OpenMP® Forum

Discussion on the OpenMP specification run by the OpenMP ARB. OpenMP and the OpenMP logo are registered trademarks of the OpenMP Architecture Review Board in the United States and other countries. All rights reserved.

I have tried to use the reduction clause to the sums structure so that I don't need to do the critical part. When I try #pragma omp parallel for \ default(shared) \ private(k,j,i,x,y,z,R_sq,rho1,rho2) \ schedule(runtime) \ reduction(+:sums)

Unfortunately you can't reduce a struct or a struct member. User-defined reductions would allow this but they aren't in OpenMP (even in 3.0 draft).That said, I wouldn't expect critical to be a real bottleneck until you got to a fairly large number of processors; also, your compiler might not use a better algorithm anyway. Are you sure that critical is the problem? You might try some kind of profiling tool if you haven't already.You could try #pragma atomic, which might well be better if your hardware and compiler have good support for atomic operations. You could also save local sums into an array indexed by thread number, and reduce them at the end, either sequentially or in your own home-grown parallel fashion.Good luck.