I discovered that openmp doesn't support while loops( or at least doesn't like them too much). And also doesn't like the ' != ' operator.
I have this bit of code.
int count = 1;
#pragma omp parallel for
while ( fgets(buff, BUFF_SIZE, f) != NULL )
{
len = strlen(buff);
int sequence_counter = segment_read(buff,len,count);
if (sequence_counter == 1)
{
count_of_reads++;
printf("\n Total No. of reads: %d \n",count_of_reads);
}
count++;
}
Any clues as to how to manage this ? I read somewhere ( another post on stackoverflow included) that I can use a pipeline. What is that ? and how to implement it ?
One way to implement "parallel while" in OpenMP is to use a while loop that create tasks. Here is a general sketch:
void foo() {
while( Foo* f = get_next_thing() ) {
#pragma omp task firstprivate(f)
bar(f);
}
#pragma omp taskwait
}
For the specific case of looping over fgets, note that fgets has inherently sequential semantics (it gets the "next" line), so it would need to be called before launching the task. It would also be important for each task to operate on its own copy of the data returned by fgets, so that a call to fgets does not overwrite the buffer being operated on by a previous task.