Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
28382 Discussions

a question about parallel computing

siyuliben
Beginner
747 Views

Hi,

I am working on a source code that needs parallel computing. I just want to ask if anyone knows about how to run parallelization. 

I need to run a very complex subroutine parallely, I found OpenMP might work for my case, and I create a source code to test it. The compilation went successfully but when I run the source code the private variables are not printed correctly (sometimes it is correct, but it still shows errors when the subroutine reads input files).

I attached a simple example. It is in fixed form (does OpenMP works for fixed form?).

Can anyone help me, thank you very much.

0 Kudos
1 Solution
jimdempseyatthecove
Honored Contributor III
703 Views

1:

>> DATA DATA lstopconv , inonconv/.TRUE. , 0/
/.TRUE. , 0/

Note, DATA cannot be used to initialize Automatic (stack local) variables. Thusly, lstopconv and inonconv are implicitly SAVE. While lstopconv is not written in the subroutine and thus being SAVE is not an issue, inonconv is written and thus will present an issue amongst the threads.

2:

      icount = NARGS()
      IF ( icount.GT.1 ) THEN
         i2 = 1
         CALL GETARG(i2,cdatapath,status)
      ELSE
         cfilename = hydName//'LEVEL_01.DIR'
         OPEN (10,FILE=cfilename,STATUS='old',ERR=900)
         READ (10,99001,ERR=1100) cdatapath
 
99001    FORMAT (a)
         CLOSE (10)
      ENDIF

Multiple threads could potentially execute the ELSE clause at the same time. This could create a file handle (IO Unit) in use error.

Consider using NEWUNIT or a unit number offset by the OpenMP thread number (requires number of threads available unit numbers).

3:

100 CALL INIT(cosalf,ntab,itcum,tlevel,alevel,plevel,hroot,vroot, &
...


Is each thread to perform the INIT or is this to be performed only once?

4:

DATA iunit/50 , 70 , 71 , 75 , 76 , 77 , 78/

Same issue as with 2) each thread will require different unit number values. consider using NEWUNIT

OPEN(NEWUNIT=iunit(1), ...

IOW assign the unit number in iunit(index) on the OPEN statement via NEWUNIT as opposed to with DATA

 

For the other unit numbers that are fixed example:

integer :: unit44, unit45, ...
...
OPEN (NEWUNIT=unit44,FILE=cfilename,STATUS='unknown',ERR=1000)

then change READ/WRITE from using 44 to unit44

Though I would suggest using variable names associated with the file

e.g unit44 becomes unit_T_Level1

 

This should be enough to get you started.

Jim Dempsey

 

View solution in original post

0 Kudos
7 Replies
jimdempseyatthecove
Honored Contributor III
723 Views

You have not shown the contents of Mysubroutine.

You have not shown the output values and indicate which variable values you assume are incorrect (not what you expect).

Also try:

!$omp parallel shared ( test) private ( count, Name )

 

or

      !$omp parallel 
     & !$omp shared ( test) 
     & !$omp private ( count, Name )

as the original code would have been seen as:

!$omp parallel !$omp shared ( test) !$omp private ( count, Name )

Jim Dempsey

0 Kudos
siyuliben
Beginner
715 Views

Thank you very much for replying to me. I attached my source code here. 

I changed it to the free form so it is the same as the examples I found out.

The subroutine is a very complex model. But the errors come from the beginning of the source code when it is reading files.

The problem is coming from the subroutine 'MATIN’ , 'TMIN', and 'SETBC'. And the 

The error messages I got (corresponding to the subroutine above) were:

1. 'Error when reading from an input file Selector.in Time Informations !'

2. 'Error when reading from an input file Selector.in Time Informations !'

3. 'Error when reading from an input file Atmosph.in !'

The strange thing is they sometimes went through, but most of the time they don't.

0 Kudos
jimdempseyatthecove
Honored Contributor III
704 Views

1:

>> DATA DATA lstopconv , inonconv/.TRUE. , 0/
/.TRUE. , 0/

Note, DATA cannot be used to initialize Automatic (stack local) variables. Thusly, lstopconv and inonconv are implicitly SAVE. While lstopconv is not written in the subroutine and thus being SAVE is not an issue, inonconv is written and thus will present an issue amongst the threads.

2:

      icount = NARGS()
      IF ( icount.GT.1 ) THEN
         i2 = 1
         CALL GETARG(i2,cdatapath,status)
      ELSE
         cfilename = hydName//'LEVEL_01.DIR'
         OPEN (10,FILE=cfilename,STATUS='old',ERR=900)
         READ (10,99001,ERR=1100) cdatapath
 
99001    FORMAT (a)
         CLOSE (10)
      ENDIF

Multiple threads could potentially execute the ELSE clause at the same time. This could create a file handle (IO Unit) in use error.

Consider using NEWUNIT or a unit number offset by the OpenMP thread number (requires number of threads available unit numbers).

3:

100 CALL INIT(cosalf,ntab,itcum,tlevel,alevel,plevel,hroot,vroot, &
...


Is each thread to perform the INIT or is this to be performed only once?

4:

DATA iunit/50 , 70 , 71 , 75 , 76 , 77 , 78/

Same issue as with 2) each thread will require different unit number values. consider using NEWUNIT

OPEN(NEWUNIT=iunit(1), ...

IOW assign the unit number in iunit(index) on the OPEN statement via NEWUNIT as opposed to with DATA

 

For the other unit numbers that are fixed example:

integer :: unit44, unit45, ...
...
OPEN (NEWUNIT=unit44,FILE=cfilename,STATUS='unknown',ERR=1000)

then change READ/WRITE from using 44 to unit44

Though I would suggest using variable names associated with the file

e.g unit44 becomes unit_T_Level1

 

This should be enough to get you started.

Jim Dempsey

 

0 Kudos
siyuliben
Beginner
699 Views

Thank you very much. I really appreciate your help. I will try them to see if the source code is working. 

I have some more questions.

For number 1:

          If DATA cannot be used, can I just write 'lstopconv  = 0'?

          I just have a new question: If I set a variable like this, is this variable shared or private in each thread?

For number 3:

          100 CALL INIT(cosalf,ntab,itcum,tlevel,alevel,plevel,hroot,vroot, &
           Is each thread to perform the INIT or is this to be performed only once?

           This is performed in each tread.

0 Kudos
jimdempseyatthecove
Honored Contributor III
682 Views

>> If DATA cannot be used, can I just write 'lstopconv  = 0'?

Yes, as long as this is an execution statement as opposed to on: 'integer :: lstopconv  = 0' which would make it implicitly SAVE.

>>If I set a variable like this, is this variable shared or private in each thread?

it would be stack local (private to the caller)

Jim Demspey

0 Kudos
siyuliben
Beginner
678 Views

Thank you Jim, I will try your suggestions. If the source code works, I will accept it as the solution.

0 Kudos
siyuliben
Beginner
610 Views
0 Kudos
Reply