The IBM C and C++ compiler products for AIX support OpenMP pragma directives that exploit shared memory parallelism.[2] Directives are based on the #pragma directive defined in the C and C++ standards. Compilers that support the OpenMP C and C++ API will include a command line option that activates and allows interpretation of all OpenMP compiler directives.
[2] VisualAge C++ for AIX supports OpenMP since Version 6, while C for AIX has been supporting it since Version 5.
We categorized OpenMP pragmas into the four categories shown in Table 9-2.
Category | Brief explanation and related sections |
---|---|
Parallel constructs | These pragmas enable the programmer to define the parallel regions in which work is done by threads in parallel. Most of the OpenMP directives either statically or dynamically bind to an enclosing parallel region. See Section 9.4, “Parallel region construct” on page 338 for more information. |
Work-sharing constructs | This category of pragmas enables the programmer to define how work will be distributed across the threads in a parallel region. See Section 9.5, “Work-sharing constructs” on page 340 for more information. |
Synchronization constructs | This category enables the programmer to control synchronization among threads. See Section 9.7, “Synchronization constructs” on page 348 for more information. |
Data sharing attributes | This category of pragmas enables the programmer to define the private/shared context of data within a parallel region. See Section 9.9, “Data-sharing attribute clauses” on page 355 for more information. |
Note
Throughout this chapter, the term construct refers to the pragma line and the following single code block. If a pragma line does not have any following code blocks, then we use the term directive.
The syntax of an OpenMP directive is specified as follows:
#pragma omp directive-name [clause[ [,] clause]...] new-line
Each directive starts with “#pragma omp”, to reduce the potential for conflict with other (non-OpenMP or vendor extensions to OpenMP) pragma directives with the same names. The remainder of the directive follows the conventions of the C and C++ standards for compiler directives. In particular, white space can be used before and after the #, and sometimes white space must be used to separate the words in a directive. Preprocessing tokens following the #pragma omp are subject to macro replacement.
Directives are case-sensitive. The order in which clauses appear in directives is not significant. Clauses on directives may be repeated as needed, subject to the restrictions listed in the description of each clause. If a variable-list appears in a clause, it must specify only variables. Only one directive-name can be specified per directive.
For example, the following directive is not allowed:
/* ERROR - multiple directive names not allowed */ #pragma omp parallel barrier
An OpenMP directive applies to at most one succeeding statement, which must be a structured block. For those directives, which allow a structured block following the directive name, are termed Constructs. Throughout this chapter, the term Construct is used as appropriate.