Dear Diego,

As I understand it (which is not necessarily correct), your code is slightly
incorrect, since variable are by default shared between parallel sections.
Therefore, the "int i" is shared between threads, and hence the erratic
results if both loops execute at the same time.  To fix it, you could try
changing the first #pragma to read

#pragma omp parallel sections private(i)

Or, alternatively, define i in the for loops as, for example

for (int i = 0; i < num_steps*10; i++) {
...


So why does this works with icc or gcc 4.4?  My guess would be it's because
OpenMP doesn't guarantee that variables are in sync between threads unless it
hits a flush directive (either explicit or implicit), and so it would seem
with icc or gcc 4.4 the variable i is out of sync (probably because it's held
in a register, which is probably a good idea).

Yours,
Ed

Ps: For those interested, a great tutorial on OpenMP is available at
http://www.llnl.gov/computing/tutorials/openMP/.

Reply via email to