The parallel pragma helps the compiler to resolve dependencies thereby facilitating auto-parallelization of an immediately following FOR loop. The noparallel pragma prevents auto-parallelization of an immediately following FOR loop.
#pragma parallel #pragma parallel {always} #pragma noparallel |
always |
Overrides compiler heuristics that estimate the likelihood that parallelization of a loop would increase performance. Using this keyword allows a loop to be parallelized even when the compiler estimates that parallelization might not improve performance. |
The parallel pragma instructs the compiler to ignore potential dependencies that it assumes could exist and which would prevent correct parallelization in the immediately following loop. However, if dependencies are proven, they are not ignored.
Using #pragma parallel always overrides the compiler heuristics that estimate the likelihood that parallelization of a loop would increase performance. It allows a loop to be parallelized even when the compiler estimates that parallelization might not improve performance.
The #pragma noparallel prevents autoparallelization of immediately following DO loops.
These pragmas take effect only if autoparallelization is enabled by the switch /Qparallel (Windows* operating system) or -parallel (Linux* or Mac OS* X operating systems).
The #pragma parallel always should be used with care. Overriding the heuristics of the compiler should only be done if you are absolutely sure the parallelization will improve performance.
The following example illustrates how to use the #pragma parallel.
void add(int k, float *a, float *b)
{
#pragma parallel
for (int i = 0; i < 10000; i++)
a[i] = a[i+k] + b[i];
}