[Omp] Barrier constructs and regions
Haab, Grant
grant.haab at intel.com
Mon Jun 27 10:03:37 PDT 2005
Here is the definition of region from the 2.5 specification, Section
1.2.2:
region:
All code encountered during a specific instance of the execution of a
given
construct or OpenMP library routine. A region includes any code in
called
routines as well as any implicit code introduced by the OpenMP
implementation.
COMMENTS:
A region may also be thought of as the dynamic or runtime extent of a
construct or OpenMP library routine.
During the execution of an OpenMP program, a construct may give
rise to many regions.
I think it is clear here that tbe language given in the first sentence:
"a given construct or OpenMP library routine"
makes it clear that a region can only be associated with a single
construct, not more than one construct.
Thus, two distinct barrier constructs (in the code below) may not
be associated with a single barrier region.
The two barrier constructs result in to two different barrier
regions at run time, and thus, the program is non-conforming based
on the restriction that all threads (or none at all) must execute each
barrier region.
The non-conforming code below may work just fine on some compilers
(in some situations), but is not guaranteed to work according to the
specfication.
The example in the appendix is illustrating a completely different
restriction than the restrictions Sanjiv mentions and is irrelevant to
the discussion.
- Grant
-----Original Message-----
From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On Behalf
Of Marina Kraeva
Sent: Tuesday, June 21, 2005 9:27 AM
To: Omp at openmp.org
Cc: Michael Suess
Subject: Re: [Omp] Barrier constructs and regions
Sanjiv,
Why do you say that the program below is non-conforming (in the quoted
message you say it is "con-forming", but later you said it's
non-conforming)?
Both restrictions that you quoted are satisfied - the barrier is called
by all threads, and there is no work-sharing regions, so the sequence of
work-sharing regions and barrier regions is the same.
Look at the non-conforming example A.35.5 in the Specs 2.5. The barrier
cannot be nested inside the critical region because only one thread AT A
TIME can enter the critical region. But in the Michael's example all
threads can call barrier at the same time.
Marina.
Shah, Sanjiv wrote:
> This is a con-forming program that probably works with most
> implementations, although it's possible some flag an error (like maybe
> ours, I don't remember).
>
> The resons are as you quoted:
>
> "The following restrictions apply to the barrier construct:
> - Each barrier region must be encountered by all threads in a team or
by
> none
> at all
> - The sequence of work-sharing regions and barrier regions encountered
> must be
> the same for every thread in a team."
>
> Sanjiv
>
>
> --
> Sanjiv, 217-403-4244
>
> -----Original Message-----
> From: Omp-bounces at openmp.org [mailto:Omp-bounces at openmp.org] On Behalf
> Of Michael Suess
> Sent: Wednesday, June 15, 2005 9:20 AM
> To: Omp at openmp.org
> Subject: [Omp] Barrier constructs and regions
>
> Hi,
>
> I have a small request for clarification. Please consider the
following
> small
> program:
>
> #include <stdio.h>
> #include <omp.h>
>
> #define THREADS 4
>
> int main()
> {
>
> omp_set_num_threads(THREADS);
>
> # pragma omp parallel
> {
> if (omp_get_thread_num() == 0) {
> #pragma omp barrier
> } else {
> #pragma omp barrier
> }
> }
>
> return 0;
> }
>
> The question is: Is this a standard compliant program (the problem are
> the
> barriers here). The Spec has to say:
>
> "All of the threads of the team executing the binding parallel region
> must
> execute the barrier region before any are allowed to continue
execution
> beyond the barrier."
>
> And:
>
> "The following restrictions apply to the barrier construct:
> - Each barrier region must be encountered by all threads in a team or
by
> none
> at all
> - The sequence of work-sharing regions and barrier regions encountered
> must be
> the same for every thread in a team."
>
> We have two barrier constructs. But do they create the same barrier
> region? If
> yes, the program is compliant and should run just fine (it wont do
very
> much,
> but thats not the point :-) ). If not, the program is not compliant
and
> should hang (actually it's behaviour is undefined then and I would
> expect it
> to hang). All compilers I have access to run the program just fine.
>
> In the section about language terminology, it says in the comments
about
>
> region:
> "During the execution of an OpenMP program, a construct may give
> rise to many regions."
>
> But can many constructs also give rise to the same region?
>
> Thanks for your answers,
> Michael Suess
>
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
>
> _______________________________________________
> Omp mailing list
> Omp at openmp.org
> http://openmp.org/mailman/listinfo/omp_openmp.org
>
>
_______________________________________________
Omp mailing list
Omp at openmp.org
http://openmp.org/mailman/listinfo/omp_openmp.org
More information about the Omp
mailing list