So far I have been using omp
only for large cycles as it is very easy to write and these cycles consumes most of the time. However, sometimes I need to do some I/O which can be efficiently done only in one thread but usualy this I/O is independent on (next) loop.
I need to do something like this:
print_something(); // independet
print_something_else(); // independent
for(...){...}; // large cycle independent on previous printing
How to use omp
to execute print_something
in one thread, print_something_else
in second thread and use all the remaining threads to compute the loop? And because the loop will very probably take more time than execution of print functions, how to add the two threads which were doing the I/O into the loop after they are finished?
Would something like this work?
#pragma omp parallel
{
#pragma omp sections
{
#pragma omp section
{
print_something();
}
#pragma omp section
{
print_something_else();
}
}
#pragma omp for
for(...){...};
}