Hello!

I have just started to learn OpenMP by rewriting some finite element program in C. So far it works quite well except of one case where I am stuck.

Adding something to a scalar value in a loop can be done by

//--------------------------------------------------------

int i;

double sum, nn=1000;

double *f=new double[nn];

//write some values to f

#pragma omp parallel for shared(f) private(i) reduction(+:sum)

for(i=0; i<nn; i++)

sum+=f[i];

//--------------------------------------------------------

However, how can I do it in an elegant way if sum is an array itself and each entry of sum[i] might be accessed by different processors?

Is there any elegant standard way?

Many thanks for your help.

Markus