I would like to parallelize this code:

- Code: Select all
`DO j=0,n`

CALL rk4(6, fun, y0(:,j), t0, dt, tf, tout,

& printout,

& 1,checker,

& ender(j), tatmo(j), yatmo(:,j))

END DO

rk4 is a Runge_Kutta 4th order to integrate the ODEs "fun" ("fun" is declared as external. "Printout" and "checker" are external subroutines, too). The y0 is a matrix, where each column is a set of initial conditions. The equations have to be integrate with stepsize "dt" until "tf". The results are stored in some matrices ("ender", "tatmo", "yatmo"). A modules contains global variable with some constants (I added threadprivate in the module).

I supposed to re-write the code in this way

- Code: Select all
`c$OMP PARALLEL DO DEFAULT(SHARED), PRIVATE(j)`

DO j=0,n

CALL rk4(6, fun, y0(:,j), t0, dt, tf, tout,

& printout,

& 1,checker,

& ender(j), tatmo(j), yatmo(:,j))

END DO

c$ END PARALLEL DO

However, the two code lead to different results. Why?

Thank you.