Skip main navigation

Nesting and binding

Nesting and binding text
nest
© PRACE and University of Ljubljana

Directive Scoping

OpenMP specifies a number of scoping rules on how directives may associate (bind) and nest within each other. That is why incorrect programs may result, if the OpenMP binding and nesting rules are ignored. These terms are used to explain the impact of OpenMP directives.

Static (Lexical) Extent:

  • The code textually enclosed between the beginning and the end of a structured block following a directive.
  • The static extent of a directive does not span multiple routines or code files.

Dynamic Extent:

  • The dynamic extent of a directive further includes the routines called from within the construct.
  • It includes both its static (lexical) extent and the extents of its orphaned directives.

Orphaned Directive:

  • An OpenMP directive that appears independently from another enclosing directive is said to be an orphaned directive. They are directives inside the dynamic extent but not within the static extent.
  • Will span routines and possibly code files.

Let’s explain with this example program. We have 2 subroutine calls and both are parallelized.

Program Test:

...
#pragma omp parallel
{
...
#pragma omp for
{
for (int i = 0; i < N; i++) {
...
sub1();
...
}
}
...
sub2();
...
}

These are the two subroutines sub1 and sub2.

void sub1() {
...
#pragma omp critical
{
...
}
...
return;
}
void sub2() {
...
#pragma omp sections
{
...
}
...
return;
}

In this example:

  • The static extent of our parallel region is exactly this, the calls inside the parallel region. The FOR directive occurs within an enclosing parallel region.
  • The dynamic extent of our parallel region is the static extent plus including the 2 subroutines that are called inside the parallel region. The CRITICAL and SECTIONS directives occur within the dynamic extent of the FOR and PARALLEL directives.
  • In the dynamic extent but not in the static extent we have orphaned CRITICAL and SECTIONS directives.
© PRACE and University of Ljubljana
This article is from the free online

Introduction to Parallel Programming

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now