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 masteris a master region as the name suggests and#pragma omp parallel foris 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 masterwith something likeas 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.