IBM SMP directives for parallelization are based on the possibility of parallelizing countable loops. A loop is considered countable when the following rules can be applied:
There is no branching into or outside of the loop.
The incremental expression (incr_expr) is not within a critical section.
Table E-1 shows the C language control flow statements and the regular expressions that define when they can be treated as countable loops.
C control flow statement keywords | Regular expression |
---|---|
for |
for ([iv]; exit_cond; incr_expr) statement for ([iv]; exit_cond; [expr] { [declaration_list] [statement_list] incr_expr; [statement_list] } |
while |
while (exit_cond) { [declaration_list] [statement_list] incr_expr; [statement_list] } |
do |
do { [declaration_list] [statement_list] incr_expr; [statement_list] } while (exit_cond) |
Where:
In general, a countable loop is automatically parallelized only if all of the following conditions are met:
The order in which loop iterations start or end does not affect the results of the program.
The loop does not contain I/O operations.
Floating point reductions inside the loop are not affected by round-off error, unless the -qnostrict option is in effect.
The -qnostrict_induction compiler option is in effect.
The -qsmp compiler option is in effect without its omp sub option. The compiler must be invoked using a thread-safe compiler mode.
When using IBM SMP directives for explicitly defining parallel portions of code, use the following syntax:
#pragma ibm pragma_name_and_args
<countable for|while|do loop>
Pragma directives must appear immediately before the section of code to which they apply. For most parallel processing pragma directives, this section of code must be a countable loop, and the compiler will report an error if one is not found.
More than one parallel processing pragma directive can be applied to a countable loop. For example:
#pragma ibm independent_loop
#pragma ibm independent_calls
#pragma ibm schedule(static,5)
<countable for|while|do loop>
Some pragma directives are mutually-exclusive. If mutually-exclusive pragmas are specified for the same loop, the last pragma specified applies to the loop. In the example below, the parallel_loop pragma directive is applied to the loop, and the sequential_loop pragma directive is ignored:
#pragma ibm sequential_loop #pragma ibm parallel_loop
Other pragmas, if specified repeatedly for a given loop, have an additive effect. For example:
#pragma ibm permutation (a,b) #pragma ibm permutation (c)
is equivalent to:
#pragma ibm permutation (a,b,c)
Table E-2 shows all IBM pragma directives supported by the latest compilers.
Pragma | Description |
---|---|
#pragma ibm critical | Instructs the compiler that the statement or statement block immediately following this pragma is a critical section. |
#pragma ibm independent_calls | Asserts that specified function calls within the chosen loop have no loop-carried dependencies. |
#pragma ibm independent_loop | Asserts that iterations of the chosen loop are independent, and that the loop can therefore be parallelized. |
#pragma ibm iterations | Specifies the approximate number of loop iterations for the chosen loop. |
#pragma ibm parallel_loop | Explicitly instructs the compiler to parallelize the chosen loop. |
#pragma ibm permutation | Asserts that specified arrays in the chosen loop contain no repeated values. |
#pragma ibm schedule | Specifies scheduling algorithms for parallel loop execution. |
#pragma ibm sequential_loop | Explicitly instructs the compiler to execute the chosen loop sequentially. |