declaration as structured block

Discuss the OpenMP 3.1 API Specifications with the OpenMP Arch. Review Board. (Read Only)
Locked
anv
Posts: 32
Joined: Wed Dec 12, 2007 9:36 am

declaration as structured block

Post by anv »

Please help to determine if the following code is legal:

Code: Select all

#pragma omp task
int x = foo();
And if it is legal then what is the scope of variable "x" here.

The 3.1 specification says that for C/C++ structured block is an executable statement, but there is no such term in C/C++ specification. The "int x = foo();" looks very much like executable statement.

If the above code fragment is legal, then it should be semantically equivalent to either

Code: Select all

#pragma omp task
{ int x = foo(); }
or

Code: Select all

int x;
#pragma omp task
{ x = foo(); }
depending on the scope of "x". In the first case the variable "x" declared in the scope of task construct, and thus should be private. I the second case "x" obeys base language rules and its scope lasts until closing "}", and thus it should be stared inside the task construct, and the parallel code keeps sequential semantics.

Please help to interpret.

Thanks,
Andrey

anv
Posts: 32
Joined: Wed Dec 12, 2007 9:36 am

Re: declaration as structured block

Post by anv »

Try to answer my own question, thanks to Michael Wong the C++ expert who helped me.

Semantically code fragments

Code: Select all

TYPE x = foo();
and

Code: Select all

TYPE x; x = foo();
are different, and they imply invocation of different constructors in general. Thus the correct interpretation should be

Code: Select all

#pragma omp task
{ int x = foo(); }
and thus variable "x" should be private in this case.

- Andrey

KentMilfeld

Re: declaration as structured block

Post by KentMilfeld »

Hi Andry,
Syntactically, one would expect

#pragma omp task
int x = foo();

to evaluate the 2nd line as a single statement; however the
Intel and PGI compilers breaks it up into 2 statements:
int x; x=foo;
and abort with statements that there must exist an executable statement
immediately after the pragma (PGI error is unclear):

INTEL:
par.cpp(9): error: this pragma must immediately precede a statement
#pragma omp parallel

PGI:
"tas.cpp", line 16: internal error: assertion failed: find_assoc_pragma:
pragma not found (../src/il.c, line 16531)

However, the following works:
#pragma omp task
{int x = foo();}

Here x is private, and if you don't need it, this is fine.
If you need the variable later on, then define it before the
pragma. (Of course multiple threads executing the task region
make the returned value arbitrary.)
Kent

Locked