Split text files Accross threads

Posted by Kevin on Stack Overflow See other posts from Stack Overflow or by Kevin
Published on 2012-12-08T17:02:31Z Indexed on 2012/12/08 17:03 UTC
Read the original article Hit count: 197

Filed under:
|
|
|

The problem: I have a few text files (10) with numbers in them on every line. I need to have them split across some threads I create using the pthread library. these threads that are created (worker threads) are to find the largest prime number that gets sent to them (and over all the largest prime from all of the text files).

My current thoughts on solutions: I am thinking myself to have two arrays and all of the text files in one array and the other array will contain a binary file that I can read say 1000 lines and send the pointer to the index of that binary file in a struct that contains the id, file pointer, and file position and let it crank through that.

a little bit of what I am talking about

pthread_create(&threads[index],NULL,calc_sqrt,(void *)threadFields[index]);//Pass struct to each worker

Struct:

typedef struct threadFields{
  int *id, *position;
  FILE *Fin;
}tField;

If anyone has any insight or a better solution it would be greatly appreciated

Thanks

© Stack Overflow or respective owner

Related posts about c

    Related posts about file