I have the following code, which I believe should display a progress bar approximating the progress of the entire process (since each parallel thread of the loop should be progressing at approximately the same rate)
#pragma omp parallel for
for(long int x=0;x<elevations.size1();x++){
#pragma omp master
{
progress_bar(x*omp_get_num_threads()); //Todo: Should I check to see if ftell fails here?
}
........
}
However, I get the following error:
warning: master region may not be closely nested inside of work-sharing or explicit task region [enabled by default]
Now, when I run the code I do get the desired result. But I don't like warnings. Why is this giving me a warning and is there a better way to accomplish this?
Thanks!
It is giving you the warning because A master region may not be closely nested inside a worksharing, atomic, or explicit task region.
#pragma omp master
is a master region as the name suggests and #pragma omp parallel for
is a task sharing region.
They are closely nested because no function call or statement separates them.
In order to avoid the warning replace the #pragma omp master
with something like
tid = omp_get_thread_num();
if(tid == 0)
{
progress_bar(x*omp_get_num_threads());
}
as per the example here.
See Guide into OpenMP: Easy multithreading programming for C++ for more information and examples.
For further information see the OpenMP Specification or see Intel's Documentation on Improper nesting of OpenMP constructs.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With