Reputation: 495
I want to know whether there is any limitation on number of variables that can be defined in a private() clause in OpenMP.
I have a code which has 4 for loops with lot of variables. The outermost for loop can be easily parallelized using a pragma. Also the inner most loop can also be parallelized using pragma. But I am using only one pragma at a time. (either the outermost or innermost) Of course, using pragma in innermost loop is not advisable because the overhead of thread creation is so much because of the 3 for loops above it. I just put the pragma for correctness test purposes.
#pragma omp parallel for private(var1,var2,...i,k,l)
for(j = ...)
{
int var1;
int var2;
for (i = ... )
{
...
for(k = ... )
{
...
for(l = ... )
{
...
...
}
}
}
}
OR
for(j = ...)
{
int var1;
int var2;
for (i = ... )
{
...
for(k = ... )
{
...
#pragma omp parallel for private(var3,var4)
for(l = ... )
{
int var3;
int var4;
}
}
}
}
Correctness test fails for outermost for loop. Compared to inner most loop, the private variables list for outermost loop is about 29 while inner most pragma contains about 21 variables in private variable list.
I compare the C version with OpenMp version, print the values in an array and sort and compare.
Upvotes: 0
Views: 1947
Reputation: 74395
Your problem has nothing to do with the number of variable names, allowed in the private
clause. Rather your first example is syntactically incorrect.
#pragma omp parallel for private(var1,var2,...i,k,l)
for(j = ...)
{
int var1;
int var2;
...
}
Both var1
and var2
are undeclared at the point where the parallel for
directive and its clauses are parsed. You don't have to (and actually cannot) specify their sharing class. They belong to the inner scope and therefore have predetermined sharing class private
. §2.9.1.1 from the OpenMP specification v3.1:
Certain variables and objects have predetermined data-sharing attributes as follows:
- Variables with automatic storage duration that are declared in a scope inside the construct are private.
Variables with predetermined data-sharing attributes may not be listed in data-sharing attribute clauses, except for the cases listed below.
It is advisable to use C99 features if possible and declare loop variables only in the scope where they are referenced, e.g.:
#pragma omp parallel for private(...)
for (int j = ...)
{
int var1;
int var2;
for (int i = ... )
{
...
for (int k = ... )
{
...
for (int l = ... )
{
...
...
}
}
}
}
In this case no variable from the (i
, j
, k
, l
, var1
, var2
) list should appear in the private
clause.
Upvotes: 1