Intel® Moderncode for Parallel Architectures
Support for developing parallel programming applications on Intel® Architecture.

In OpenMP, Reduction Clause

zhangzhe65
Beginner
346 Views

Why?

#pragma omp parallel for
for (i=0; i{
sum+ = a * b;
}
and

#pragma omp parallel for reduction(+:sum)
for (i=0; i{
sum+ = a * b;
}

Please tell me why the two running results are identical?
Thank you.

0 Kudos
3 Replies
jimdempseyatthecove
Honored Contributor III
346 Views

a) You got lucky
b) You compiled with OpenMP off
c) You compiled with OpenMP on, Nested levels off, and loop is in nested level.
d) You compiled with OpenMP on, but only 1 thread is used
e) N <= 1
f) all of a or all of b or both are 0
g) N is sufficiently small such that each thread finishes before the other starts (assuming multiple threads run the loop)


Jim Dempsey
0 Kudos
zhangzhe65
Beginner
346 Views

a) You got lucky
b) You compiled with OpenMP off
c) You compiled with OpenMP on, Nested levels off, and loop is in nested level.
d) You compiled with OpenMP on, but only 1 thread is used
e) N <= 1
f) all of a or all of b or both are 0
g) N is sufficiently small such that each thread finishes before the other starts (assuming multiple threads run the loop)


Jim Dempsey

0 Kudos
zhangzhe65
Beginner
346 Views
Thank you very much indeed for your reply.
0 Kudos
Reply