Hi Mark,
ftinetti wrote:
Now, I do have a specific question: when the if clause evaluates to false:
is it a sequential part? if so, the problem in the original code is not related to dynamic
is it a parallel part with just one thread? if so, either the spec should be fixed/made clearer or the gcc implementation I'm using has a bug
or I'm missing something else, which is what I'm guessing right now.
I'm sorry, I'm confused: what do think is the bug in gcc/error in the spec?
I'll try to explain extracting code and text from previous posts in this thread. The following piece of code:
- Code: Select all
para_low = 0;
#pragma omp parallel for if(para_low)
for (i = 0; i < 1000; i++)
{
if (i == 0) printf("omp_in_parallel() return value: %d, and omp_get_active_level() returns: %d\n", omp_in_parallel(), omp_get_active_level());
v1[i]= 0;
}
produces the output
omp_in_parallel() return value: 0, and omp_get_active_level() returns: 0
Taking into account your explanation in a previous post:
A parallel construct will always generate a parallel region: there is no such thing as "plain sequential" execution. If the parallel region only contains one thread (either because an if clause evaluates to false, or for any other reason), then it is called an inactive parallel region. However, omp_in_parallel() only returns true if it is called from inside an active parallel region (i.e. one which is executing with more than one thread), hence the behaviour you observe in your example.
but the spec., in the explanation of omp_get_active_level() includes:
The routine always returns a nonnegative integer, and returns 0 if it is called from the sequential part of the program.
Thus, there is such thing as "sequential part of the program" which is what the return value of the function is indicating. Now I cannot distinguish the difference among "inactive parallel region" and "sequential part of the program".
Maybe I could "understand" something like: "returns 0 if it is called from an inactive parallel region" or "returns 0 if it is called from the sequential part of the program or an inactive parallel region". But I do not give it for granted...
Also, I do not understand:
omp_get_level() should always return 2 if called from inside the inner parallel, regardless of the number of threads or the value of the if clause expression.
omp_get_active_level() will only return 2 if both levels of parallel region are executed by more than one thread.
the "regardless" part specifically, since when the if clause evaluates to false the parallel region is an inactive one...
hmmmmm... maybe I just should read more... or better...
Anyway, thank you very much,
Fernando.