float f( float x ) ...
float area( float xmin, float xmax, int N, float *store )
{
float h = (xmax-xmin)/N; 9
// Calculate and store f(x) for each x.
int i;
for( i=0; i<N; i++ ) store[i] = f(xmin+i*h);
// Estimate the area.
float area = 0.0f;
for( i=0; i<N; i++ ) area += h * store[i];
return area;
}
(a) Consider first the loop at line 12, which calculates f(x) over a range of values of x, and
stores the results in an array store[N].
(i) Identify any data dependencies in this loop. Explain your answer.
(ii) On a shared memory CPU architecture and OpenMP, this loop can be parallelised by using a #pragma omp parallel for directive just before the loop. Provide pseudo- code for the actions performed by each thread in the case that there are p = 3 threads.
Comments
Leave a comment