They are not equivalent.
foo()
will execute the two fprintf
(parts) sequentially. bar()
may execute them in parallel.
For an exhaustive reference you may refer to the IBM compiler documentation.
Essentially, in the case of foo()
, a single worker thread handles first part
, then completes and resynchronizes with the master thread (the barrier
is, by the way, implicit at the end of a single
construct.) A new worker thread then handles the second part
, completes, and resynchronizes with the master thread.
In the case of bar()
, a separate worker thread handles each section (the first section, first part
, is an implicit section.) The worker threads complete work in parallel.
#pragma omp parallel
The omp parallel directive explicitly
instructs the compiler to parallelize
the chosen block of code. When a
parallel region is encountered, a
logical team of threads is formed.
Each thread in the team executes all
statements within a parallel region
except for work-sharing constructs.
Work within work-sharing constructs is
distributed among the threads in a
team.
Loop iterations must be independent
before the loop can be parallelized.
An implied barrier exists at the end
of a parallelized statement block.
Nested parallel regions are always
serialized.
#pragma omp single
The omp single directive identifies a
section of code that must be run by a
single available thread.
An implied barrier exists at the end
of a parallelized statement block
unless the nowait clause is specified.
#pragma omp section, #pragma omp sections
The omp sections directive distributes
work among threads bound to a defined
parallel region.
The omp section directive is optional
for the first program code segment
inside the omp sections directive.
Following segments must be preceded by
an omp section directive. All omp
section directives must appear within
the lexical construct of the program
source code segment associated with
the omp sections directive.
When program execution reaches a omp
sections directive, program segments
defined by the following omp section
directive are distributed for parallel
execution among available threads. A
barrier is implicitly defined at the
end of the larger program region
associated with the omp sections
directive unless the nowait clause is
specified.
Cheers,
V.