OpenMP for the loop with the master region: "the wizard area cannot be closely nested inside the sharing area or the explicit task area"

I have the following code, which I believe should display a progress bar approximating the course of the whole process (since each parallel thread of the loop should progress at about the same speed)

#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 get the desired result. But I don't like the warnings. Why does this give me a warning and is there a better way to do this?

Thanks!

+4
source share
1 answer

This gives you a warning, because the Massive area may not be closely nested in the work area, atomic or explicit task area.

#pragma omp master is the main area, as the name suggests, and #pragma omp parallel for is the task sharing area.

They are closely nested because no function call or operator separates them.

To avoid a warning, replace #pragma omp master with something like

 tid = omp_get_thread_num(); if(tid == 0) { progress_bar(x*omp_get_num_threads()); } 

according to the example here .

See the OpenMP Guide: Simple Multithreaded Programming for C ++ for more information and examples.

For more information, see the OpenMP Specification or see the Intel documentation on inappropriate nesting of OpenMP constructs .

+4
source

Source: https://habr.com/ru/post/1396910/


All Articles