Index jumping around in Fortran 90

General OpenMP discussion

Index jumping around in Fortran 90

Postby Astrokitten » Tue Nov 08, 2011 10:20 am

Hello,
I am using OpenMP with Fortran90 for Monte Carlo simulation.
Using N sets of 9 parameters [Nx9], I generate N trajectories and
store them to the corresponding column in a matrix. Each trajectory
has M data points so the resultant matrix storing them columnwise
is in [MxN] dimension.

My intention was to store the trajectory generated by 'J'th row of Param
in 'J'th column of Result. However, it seems that parallel process is
randomly assigning the result into arbitrary column. That is,

Result from Param(1,:) --> Assigned to Result(3,:)
Result from Param(2,:) --> Assigned to Result(1,:)
Result from Param(3,:) --> Assigned to Result(4,:)
Result from Param(4,:) --> Assigned to Result(2,:)

instead of

Result from Param(1,:) --> Assigned to Result(1,:)
Result from Param(2,:) --> Assigned to Result(2,:)
Result from Param(3,:) --> Assigned to Result(3,:)
Result from Param(4,:) --> Assigned to Result(4,:).

A brief (abstracted) code looks like this:
Code: Select all
  Use OMP_Lib
  !$OMP Parallel Private(J)
  N_Thread=OMP_Get_Num_Threads()
  !$OMP Do Schedule(Dynamic,N_Case/N_Thread)
  Do J=1,N
    Result(:,J)=Get_Result(Param(J,:))
  End Do
  !$OMP End Do NoWait
  !$OMP End Parallel


Am I doing something wrong? If so, please let me know how to fix it.

Thank you.
Astrokitten
 
Posts: 1
Joined: Tue Nov 08, 2011 10:00 am

Re: Index jumping around in Fortran 90

Postby ftinetti » Wed Nov 09, 2011 3:52 am

Hi,

I assume you meant
instead of

Result from Param(1,:) --> Assigned to Result(:,1)
Result from Param(2,:) --> Assigned to Result(:,2)
Result from Param(3,:) --> Assigned to Result(:,3)
Result from Param(4,:) --> Assigned to Result(:,4)


And the only wrong detail in the code is that N_Thread should be private, but I can't relate this detail with the scrambled result... maybe if you post a little example reproducing the wrong behavior to play with I could see something else (not guaranteed, of course) .

HTH.
ftinetti
 
Posts: 581
Joined: Wed Feb 10, 2010 2:44 pm


Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 7 guests