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

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -