IBM SMP directives

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.

Table E-1. Regular expressions for countable loops
C control flow statement keywordsRegular 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:

exit_condiv <= ub
 iv < ub
 iv >= ub
 iv > ub
incr_expr++iv
 iv++
 --iv
 i--
 iv += incr
 iv -= incr
 iv = iv + incr
 iv = incr + iv
 iv = iv - incr
ivIteration variable. The iteration variable is a signed integer that has either automatic or register storage class, does not have its address taken, and is not modified anywhere in the loop except in incr_expr.
incrLoop invariant signed integer expression. The value of the expression is known at compile-time and is not 0. incr cannot reference extern or static variables, pointers or pointer expressions, function calls, or variables that have their address taken.
ubLoop invariant signed integer expression. ub cannot reference extern or static variables, pointers or pointer expressions, function calls, or variables that have their address taken.

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.

The IBM SMP directives syntax

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.

Table E-2. Supported IBM pragma directives
PragmaDescription
#pragma ibm criticalInstructs the compiler that the statement or statement block immediately following this pragma is a critical section.
#pragma ibm independent_callsAsserts that specified function calls within the chosen loop have no loop-carried dependencies.
#pragma ibm independent_loopAsserts that iterations of the chosen loop are independent, and that the loop can therefore be parallelized.
#pragma ibm iterationsSpecifies the approximate number of loop iterations for the chosen loop.
#pragma ibm parallel_loopExplicitly instructs the compiler to parallelize the chosen loop.
#pragma ibm permutationAsserts that specified arrays in the chosen loop contain no repeated values.
#pragma ibm scheduleSpecifies scheduling algorithms for parallel loop execution.
#pragma ibm sequential_loopExplicitly instructs the compiler to execute the chosen loop sequentially.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset