OpenMP shared memory parallel code annotations
Usually automatic paralleization with a run-time system based on a thread library.
A simplified translation of the following example parallel-for loop is given below.
Grid1 *g = new Grid1(0, n+1);
Grid1IteratorSub it(1, n, g);
DistArray x(g), y(g);
...
float e = 0;
ForEach(int i, it,
x(i) += ( y(i+1) + y(i-1) )*.5;
e += sqr( y(i) ); )
...
|
global
main code:
float *x = new float[n+1];
float *y = new float[n+1];
...
e = 0;
#pragma omp for reduction(+:e)
for (int i=1; i<n; ++i) {
x[i] += ( y[i+1] + y[i-1] )*.5;
e += y[i] * y[i];
}
...
delete[] x, y;
|
Note that the reduction variable e is global.