Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran OpenMP parallelization and writing in multiple files.

  1. Aug 8, 2012 #1
    Hello.

    I'm attempting to write some data in different files (each thread write in each file), but I'm getting an error saying: 'File already opened in another unit'. I'm using the function OMP_get_thread_num() from OpenMP library in order to open individual files in individual threads.

    Code (Text):


    !$OMP PARALLEL DEFAULT(PRIVATE) SHARED(PeVet,num,eta,xi,p) FIRSTPRIVATE(Temp,Told)
    !$OMP DO
    DO q=1,5
        Pe = PeVet(q)

        LocalThread = 22 +  OMP_get_thread_num()
        WRITE(FileName,'(a,i4.4,a,i4.4,a,i2.1,a)') 'Velocity-Imax',Imax,'Jmax',Jmax,'Kn',p,'.dat'
        OPEN(UNIT=LocalThread,FILE=FileName)

        DO j=1,jmax
            ud(j)= (3.d0/2.d0)*(1.d0+8*Kn*bV-eta(j)**2)/(1.d0+12*Kn*bV)
            Write(LocalThread,*) eta(j), ud(j)
        END DO
        CLOSE(LocalThread)
    END DO
    !$OMP END DO
    !$OMP END PARALLEL
     
    I don't know what I'm doing wrong...
    Please, help me guys.
    Thank you in advance
     
    Last edited: Aug 8, 2012
  2. jcsd
  3. Aug 8, 2012 #2
    It looks like the error is meaningful, isn't it?

    I mean, you may be making sure that the unit number is different in every thread, but it does not look like you are making sure that the file name become different....in other words, it looks like you open the file the first time around from the first thread that gets there...and THEN, you are attempting to open the same file from another thread with a different unit number....follow?

    are you trying to write to different files or the same? or what?
     
  4. Aug 8, 2012 #3
    Gsal, you are totally right.

    Thank you
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran OpenMP parallelization and writing in multiple files.
  1. Write File - Fortran (Replies: 1)

Loading...