Variables in num_thread clauses have un-clear context

Discuss the OpenMP 4.0 API Specifications released July 2013 (Read Only)

Variables in num_thread clauses have un-clear context

Postby nsmeds » Wed Feb 04, 2015 6:16 am

Here is something that I noticed have changed over the API definitions. I must
admit I don't understand why they changed in OpenMP 3, and I don't see the changes having any
positive effect on the OpenMP API. In particular in the case of nested parallelism the current
wording gets confusing to me.

OpenMP 2.0 - Nov 2000
"Only a single NUM_THREADS clause can appear on the directive. The NUM_THREADS
expression is evaluated outside the context of the parallel region. Results are
unspecified if the NUM_THREADS expression contains a function reference that has
side effects."


OpenMP 2.5 - 2005
"The if clause expression and the num_threads clause expression are evaluated in
the context outside of the parallel construct, and no ordering of those evaluations
is specified. It is also unspecified whether, in what order, or how many times
any side-effects of the evaluation of the num_threads or if clause expressions occur."


OpenMP 3.0 - May 2008
OpenMP 3.1 - Jul 2011
OpenMP 4.0 - Jul 2013 (My emphasis)
"Note that using a variable in an if or num_threads clause expression of a
parallel construct causes an implicit reference to the variable in all enclosing
constructs
. The if clause expression and the num_threads clause expression are
evaluated in the context outside of the parallel construct, and no ordering of those
evaluations is specified. It is also unspecified whether, in what order, or how many times
any side-effects of the evaluation of the num_threads or if clause expressions occur"


Suggested new formulation:
"The if clause expression and the num_threads clause expression are evaluated in
the base language and in the context of the thread that encounters the parallel construct
similar to if the expression had been evaluated just before encountering the construct.
No ordering of those evaluations is specified. It is also unspecified
whether, in what order, or how many times any side-effects of the evaluation of the
num_threads or if clause expressions occur."


So I want to make it clear that the clause is evaluated just as it would if it had been
written in a source code line (besides any side-effects). I also want to make certain
that the base language can
be used for the expression.

In the example below, according to the OpenMP 4.0 rules it is unclear if num_threads()
will evaluate to 3, 5, the uninitialized value of the out-most serial context, or
something else in between.

N1=2
!$OMP PARALLEL num_threads(N1) PRIVATE(N2)
N2=3+2*omp_get_thread_num()
!$OMP PARALLEL num_threads(N2)
!.. Do work
!$OMP END PARALLEL
!$OMP END PARALLEL
nsmeds
 
Posts: 3
Joined: Fri Jan 23, 2015 2:42 am

Return to OpenMP 4.0 API Specifications

Who is online

Users browsing this forum: No registered users and 1 guest