Module 10: Open Multi-Processing
  Lecture 20: The “omp sections” Directive
 


Combined Parallel Work-sharing Constructs

  • OpenMP provides combined Parallel Worksharing directive that are merely shortcuts:
    • PARALLEL DO/parallel for
    • Parallel SECTIONS
  • These directives behave same as an individual PARALLEL directive being immediately followed by a separate
    work-sharing directive.
  • Most of the rules and clauses that apply to both directives are in effect
#pragma omp parallel
#pragma omp for
for (...)
#pragma omp parallel for
for (....)
#pragma omp parallel
#pragma omp sections
{...}
#pragma omp parallel sections
{.... }

Synchronization

  • Consider a simple example where two threads on two different processors are both trying to increment a variable x at the same time (assume x is initially 0):
THREAD 1
increment(x){
x = x+1;
}
THREAD 1
10 LOAD A, (x address)
20 ADD A, 1
30 STORE A, (x address)
THREAD 2
increment(x){
x = x+1;
}
THREAD 2
10 LOAD A, (x address)
20 ADD A, 1
30 STORE A, (x address)
  • What are the possible outputs?