declaration as structured block

Discuss the OpenMP 3.1 API Specifications with the OpenMP Arch. Review Board. (Read Only)

declaration as structured block

Postby anv » Wed Dec 14, 2011 11:47 am

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: 31
Joined: Wed Dec 12, 2007 9:36 am

Re: declaration as structured block

Postby anv » Wed Feb 22, 2012 3:00 am

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
anv
 
Posts: 31
Joined: Wed Dec 12, 2007 9:36 am

Re: declaration as structured block

Postby KentMilfeld » Mon Feb 27, 2012 10:40 am

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
KentMilfeld
 
Posts: 3
Joined: Fri Jan 27, 2012 12:40 pm


Return to OpenMP 3.1 API Specifications

Who is online

Users browsing this forum: No registered users and 0 guests