Multithreading in reading file


 
Thread Tools Search this Thread
Top Forums Programming Multithreading in reading file
# 8  
Old 11-23-2011
How, exactly, is a multithreaded CPU going to speed up your disk? Disks don't multithread, CPU's do. You have to read the records one-at-a-time no matter what.

Also, please answer the question I already asked twice, and now ask a third time:
Quote:
Originally Posted by Corona688
Is this really what your XML looks like, or did you pretty it up for posting?
I can't do anything useful unless you start answering my questions.
# 9  
Old 11-23-2011
Thanks for your reply, Below is the record in my XML file. I am also new to XML parser in C++.

<EMPLOYEE>
<RECORD id =XYZ >
<SSN>123</SSN>
<Section>dfdf</ Section>
<Salary>34343</Salary>
</RECORD>
<RECORD id =XZY >
< SSN >321</ SSN >
<Section>dfd</ Section>
<Salary>34343</Salary>
</RECORD>
</EMPLOYEE>

Thanks,
Arun
# 10  
Old 11-23-2011
Code:
$ cat getsecsal.c

#include <stdio.h>
#include <string.h>

int main(void)
{
        char buf[16384];
        char section[16384];

        while(fgets(buf, 16384, stdin))
        {
                char *substr;
                if(substr=strstr(buf,"<Section>"))
                {
                        substr += strlen("<Section>");
                        char *end=strstr(substr, "</ Section>");
                        if(end) (*end)='\0';
                        strcpy(section, substr);
                }
                else if(substr=strstr(buf,"<Salary>"))
                {
                        substr += strlen("<Salary>");
                        char *end=strstr(substr, "</Salary>");
                        if(end) (*end)='\0';

                        printf("%s~%s\n", section, substr);
                }
        }
}

$ gcc getsecsal.c
$ ls -lh data[12]
-rw-r--r-- 1 tyler users 1.7G Nov 23 15:57 data1
-rw-r--r-- 1 tyler users  208 Nov 23 15:57 data2
$ cat data2

<EMPLOYEE>
<RECORD id =XYZ >
<SSN>123</SSN>
<Section>dfdf</ Section>
<Salary>34343</Salary>
</RECORD>
<RECORD id =XZY >
< SSN >321</ SSN >
<Section>dfd</ Section>
<Salary>34343</Salary>
</RECORD>
</EMPLOYEE>

$ ./a.out < data2
dfdf~34343
dfd~34343

$ time ./a.out < data1 > /dev/null

real    0m46.661s
user    0m42.820s
sys     0m2.221s

$

1.7 gigabytes of data in 46.7 seconds is 37 megabytes per second -- the fastest speed my disk controller gets. I'd need a faster disk controller to do any better. More threads wouldn't do a thing.

If the tags in any of your records are actually different from what you posted, it won't work.
This User Gave Thanks to Corona688 For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Programming

Help with multithreading

I take this question of the The Linux Programming Interface: A Linux and Unix System Programming page 652 exercise 30.1 I want someone to explain the under line statement because it sounds complex to me couldn't understand anything 30-1 Modify the program (thread_incr.c) so that each loop in... (3 Replies)
Discussion started by: fwrlfo
3 Replies

2. What is on Your Mind?

Alarm interrupt and multithreading

Hi Friends any know how became a friend in this Android Programming Language (0 Replies)
Discussion started by: ljarun
0 Replies

3. Programming

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (6 Replies)
Discussion started by: moti12
6 Replies

4. IP Networking

how to do udp broadcast with multithreading

hello to all i want to use multithreading to my UDP broadcast server client program. will anyone help me by proving C code. i am working in fedora. also my requirement is POSIX compliance.please help me..... (0 Replies)
Discussion started by: moti12
0 Replies

5. Programming

MultiThreading using Pthreads

Situation: i have multiple pthread_create calls like this: pthread_create(...., ThreadFunc1,.....); pthread_create(...., ThreadFunc2,.....); . . which i am using to create multiple threads.All the "ThreadFunc<i>" functions are actually calling same function "Receive" of a class using same... (3 Replies)
Discussion started by: Sastra
3 Replies

6. Shell Programming and Scripting

Multithreading program

Hi I need to insert 1million records into MySQL database, but it is taking lot of time as there is no bulk insert support. I want to spawn 10 processes which will insert 100k records each parallely. Can somebody help me with a example program to execute this task through shell scripting. (5 Replies)
Discussion started by: sach_roger
5 Replies

7. UNIX for Advanced & Expert Users

multithreading in UNIX

Hi, Can you please give me a suitable reference to learn multithreading programming in C in UNIX? Thanks (3 Replies)
Discussion started by: naan
3 Replies

8. Programming

multithreading on OSX

Hi all, I have a query about multithreading. What I would like to do is, at the start of my main update() function, start a couple of threads in parallel, once they are all complete carry on with my main update function. void update() { thread1->update(); // fluid solver ... (3 Replies)
Discussion started by: memoid
3 Replies

9. Programming

Multithreading in Pro*C

:confused: Hi! I have created a Multhreaded Application in Pro*C (using pthreads) with about 5 Threads running simultaneously. The Application is basically to Update a Centralized Table in Oracle, which updates different rows in the Table (Each Thread updates different rows!). The... (16 Replies)
Discussion started by: shaik786
16 Replies
Login or Register to Ask a Question