Sequential code

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) ); )
...


main code:

float *x = new float[n+1];
float *y = new float[n+1];
...
float e = 0;
for (int i=1; i<n; ++i) {
   x[i] += ( y[i+1] + y[i-1] )*.5;
   e += y[i] * y[i];
}
...
delete[] x, y;