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

此生再无相见时 提交于 2019-12-10 04:42:10

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/9317788/openmp-for-loop-with-master-region-master-region-may-not-be-closely-nested-ins

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!