Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenMP for loop with master region: "master region may not be closely nested inside of work-sharing or explicit task region"

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!

like image 602
Richard Avatar asked Feb 16 '12 19:02

Richard


1 Answers

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.

like image 188
Appleman1234 Avatar answered Nov 11 '22 07:11

Appleman1234