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

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education