openmp - What is Parallel for usage in different for loops? -
i have code fragments here think correct not given answer. need clarify this.
dotp=0; (i=0;i<n;i++){ dotp+= a[i]+b[i]; }
given answer parallelizing code :
dotp=0; #pragma omp parallel reduction(+:dotp) (i=0;i<n;i++){ dotp+= a[i]+b[i]; }
i think needs dotp added firstprivate visible inside loop
dotp=0; #pragma omp parallel reduction(+:dotp) firstprivate(dotp) (i=0;i<n;i++){ dotp+= a[i]+b[i]; }
if not correct why not have use firstprivate ?
the reduction
clause marks dotp
shared , performs final summation.
the initial value of each shared dotp
within loop 0. final step in summation add previous version (original) value of dotp
, in case 0. value.
you not (and should not) need first private, enforce initial zeroing of dotp
.
Comments
Post a Comment