Control Parallel Processing with Pragmas

Parallel processing operations are controlled by pragma directives in your program source. The pragmas have effect only when parallelization is enabled with the -qsmp compiler option.


OpenMP Directives

Applies to C Applies to C++

Syntax

#pragma omp pragma_name_and_args
statement_block

Pragma directives generally appear immediately before the section of code to which they apply. The omp parallel directive is used to define the region of program code to be parallelized. Other OpenMP directives define visibility of data variables in the defined parallel region and how work within that region is shared and synchronized.

For example, the following example defines a parallel region in which iterations of a for loop can run in parallel:

#pragma omp parallel
{
  #pragma omp for 
    for (i=0; i<n; i++)
      ...
}

This example defines a parallel region in which two or more non-iterative sections of program code can run in parallel:

#pragma omp sections
{
  #pragma omp section 
     structured_block_1
           ...
  #pragma omp section 
     structured_block_2
           ...
      ....
}
 

Related Concepts

Program Parallelization

Related References

smp
Pragmas to Control Parallel Processing
OpenMP Run-time Options for Parallel Processing
Built-in Functions Used for Parallel Processing IBM Copyright 2003