another newbie question

General OpenMP discussion

another newbie question

Postby rudra » Tue Jun 03, 2008 5:41 am

dear friends,
I am trying to make my code parallel. the main program looks like:

87 !$OMP PARALLEL SHARED(X,Y,Z) PRIVATE(ISTP)
88 !$OMP DO
89 mcstp: do istp=1,rmcs
90
91 iatm=int(ntot*rvec(istp))+1
92 old_x=x(iatm);old_y=y(iatm);old_z=z(iatm)
93
94 x(iatm)=x(iatm)+dr*(rvec(iatm)-0.5)
95 y(iatm)=y(iatm)+dr*(rvec(iatm)-0.5)
96 z(iatm)=z(iatm)+dr*(rvec(iatm)-0.5)
97 call PBC(x,y,z,boxl)
98 call
crdf(filrdf,x,y,z,boxl,ntot,nap,rrl,gr_new,rmin,exst)
99 if (.not.exst) then
100 write(*,*) "Problem in openning file",filrdf,"in
step",istp
101 stop
102 endif
103
104 mcst=rmcs/10
105 if (mod(istp,mcst)==0) write(*,'(a2,$)') ". "
106 !---------------------------------------------------------------
107
108 call
metropolis(rdf_ex,gr,gr_new,ntot,chng,rho,boxl,sigma,istp)
109 if (chng==1)then
110 x(iatm)=old_x
111 y(iatm)=old_y
112 z(iatm)=old_z
113 end if
114
115 end do mcstp
116 !$OMP END DO
117 !$OMP END PARALLEL

the subroutine crdf (crdf is a part of a module mrdf.f90...which
doesnot have any parallel attribute) writes data in a file(unit 16)

56 open(16,file=filrdf,status='replace')!,iostat=ok)
57 inquire(16,exist=exst)
58 do bin=1,nbin
59 rl=float(bin-1)*del_r
60 ru=rl+del_r
61 rrl(bin) =ru-0.5
62 hist_i=const*(ru**3-rl**3)
63 gr(bin)=float(hist(bin))/(float(nap)*hist_i)
64 write(16,*)rrl(bin),gr(bin)
65 end do
66 close(16)

while i am trying to run this program , a runtime error comes saying:
At line 56 of file mrdf.f90 (unit = 16, file = 'newrdf.dat')
Fortran runtime error: Cannot change STATUS parameter in OPEN statement :(
which is understood, because the code is trying to write on the same
file simultaneously. How can i manage this? This is the first time i
am trying to write a parallel code.....so do reply even if its too
idiotic
rudra
 
Posts: 21
Joined: Tue Jun 03, 2008 5:28 am
Location: kolkata,india

Re: another newbie question

Postby ejd » Tue Jun 03, 2008 7:07 am

Your problem is that you have multiple threads of execution all trying to do the open and write to the same file. The general methods to get around this problem, are to open the file outside the parallel region and then serialize the writes by enclosing it in a critical, single, etc. region or to use only one thread (like the master thread) to do all the writes to the file. Another way is to open a different file for each thread and have each thread write to it's own file. Hope that helps.
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: another newbie question

Postby rudra » Wed Jun 04, 2008 12:05 am

dear friends,
as i told you the problem has been solved by writing

56 inquire(16,opened=opn)
57 if(.not.opn)then
58 open(16,file=filrdf,status='replace')
59 end if
on the mrdf.f90

, but another problem has been created:
when i am putting rmcs>500(line 89) of main program, an error is
coming:

At line 58 of file mrdf.f90
Fortran runtime error: Cannot change STATUS parameter in OPEN
statement
but with smaller rmcs, its working fine

any idea? i am running in in 8 processor currently, and compiling it with option gfortran -fopenmp
rudra
 
Posts: 21
Joined: Tue Jun 03, 2008 5:28 am
Location: kolkata,india

Re: another newbie question

Postby ejd » Wed Jun 04, 2008 5:00 am

The problem is the same as before. You can still have multiple threads trying to do the open at the same time. Say the file isn't yet open. Two (or more) threads can do the inquire at the same time and both see the file as not yet open and try to open it. The operating system is then the "gatekeeper" and will open the file for one thread and then see when it tries to open it for another thread that there is a problem (trying to replace an open file).
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 5 guests