#pragma ibm independent_loop
Purpose
The independent_loop pragma explicitly states that the iterations of the chosen loop are independent, and that the iterations can be executed in parallel.
Syntax
>>-#--pragma--ibm independent_loop--+--------+----------------->< '-if exp-'
where exp represents a scalar expression.
Usage
If the iterations of a
loop are independent, you can put the pragma before the loop block.
Then the compiler executes these iterations in parallel. When the exp argument
is specified, the loop iterations are considered independent only
if exp evaluates to TRUE at run time.
Notes:
- If the iterations of the chosen loop are dependent, the compiler executes the loop iterations sequentially no matter whether you specify the independent_loop pragma.
- To have an effect on a loop, you must put the independent_loop pragma immediately before this loop. Otherwise, the pragma is ignored.
- If several independent_loop pragmas are specified before a loop, only the last one takes effect.
- This pragma only takes effect if you specify the -qsmp or -qhot compiler option.
This pragma can be combined with the omp parallel for pragma to select a specific parallel process scheduling algorithm. For more information, see #pragma omp parallel for.
Examples
In the following example,
the loop iterations are executed in parallel if the value of the argument k is
larger than 2.
int a[1000], b[1000], c[1000];
int main(int k){
if(k>0){
#pragma ibm independent_loop if (k>2)
for(int i=0; i<900; i++){
a[i]=b[i]*c[i];
}
}
}



