CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   Run a user fortran routine in parallel (https://www.cfd-online.com/Forums/cfx/165765-run-user-fortran-routine-parallel.html)

Smilodon January 25, 2016 10:47

Run a user fortran routine in parallel
 
Hello everybody,

we have written a rather large user fortran model, which runs perfectly when running CFX on a single processor.

In order to be able to use our user fortran model in parallel, we would like to know, how to get the processor number in user fortran.

Namely, we would like to have only one processor writing the results and others skipping this step.

In short, we would like to do

myproc = the number of parallel thread
nproc = number of all threads
IF (myproc.EQ.1) THEN
CALL DoSomething
END IF

The question is how to get myproc and nproc?

Thank you for your answers!

Opaque January 25, 2016 11:41

Worth reading the documentation. For example,

Quote:

18.5.2.9. GET_PARALLEL_INFO

The GET_PARALLEL_INFO routine provides access to information about the parallel run mode and partitioning details from within any user CEL function or from within junction box routines. It can be called in the following ways to look up the variables RUNMOD, PARMOD, OWNPAR and NPARD:

CALL GET_PARALLEL_INFO ('RUNMOD',RUN_MODE,CNAME,CRESLT)
CALL GET_PARALLEL_INFO ('PARMOD',PAR_MODE,CNAME,CRESLT)
CALL GET_PARALLEL_INFO ('OWNPAR',OWN_PAR,CNAME,CRESLT)
CALL GET_PARALLEL_INFO ('NPARD',NUM_PAR,CNAME,CRESLT)
RUNMOD describes the run mode as either serial or parallel. It is an integer variable where 0 corresponds to serial and 1 to parallel.

PARMOD describes the parallel mode and can be master or slave. It is an integer variable where 1 corresponds to the master process and 2 to a slave process.

OWNPAR is an integer variable that gives the partition number on the current process.

NPARD is an integer variable that gives the total number of partitions.

The variables RUN_MODE, PAR_MODE, OWN_PAR and NUM_PAR are used to store the values locally and should be declared as integer variables in your subroutine. They can be named differently to the names used here, but to avoid conflicts they should not be named RUNMOD, PARMOD, OWNPAR or NPARD. CNAME is a dummy character variable and should be declared as such.

doublestrong March 28, 2017 05:35

Thanks for the hints. I got the same problem and fixed it. The solver crashed if my subroutine wrote a result file in the parallel mode.

Now a result file is written only if the master processor calls my user routine. Here is the code block concerning output:
CALL GET_PARALLEL_INFO ('PARMOD',PAR_MODE,CNAME,CRESLT)
if (PAR_MODE .EQ. 1) THEN
open(12,FILE='PressureRecordFile',POSITION = 'APPEND')
write(12,*) CTSTEP
close(12)
ENDIF

Hope it helps people who also work with user routine.


All times are GMT -4. The time now is 05:30.