Skip to content

Commit

Permalink
Add missing argument for error code to MPI calls
Browse files Browse the repository at this point in the history
Almost all MPI functions in Fortran need an additional argument for
returning an error code. If there is no memory allocated that receives
that error code, unrelated memory on the stack(?) could be overwritten.
(What part of the memory is overwritten might depend on the calling
convention.)

Add that argument when calling MPI subroutines in `ParallelUtils.F90`.
  • Loading branch information
mmuetzel committed Aug 28, 2024
1 parent 57869d8 commit fb8d4e3
Showing 1 changed file with 22 additions and 22 deletions.
44 changes: 22 additions & 22 deletions fem/src/ParallelUtils.F90
Original file line number Diff line number Diff line change
Expand Up @@ -1386,21 +1386,21 @@ END SUBROUTINE ParallelActiveBarrier


FUNCTION ParallelSlicesComm() RESULT( CustomComm )
INTEGER :: CustomComm
#ifdef PARALLEL_FOR_REAL
INTEGER :: CustomComm
#ifdef PARALLEL_FOR_REAL
LOGICAL :: Visited = .FALSE.
INTEGER :: nSlices, nTimes, iSlice, iTime
INTEGER :: nSlices, nTimes, iSlice, iTime, ierr
INTEGER :: CustomComm0
LOGICAL :: GotIt
SAVE Visited, CustomComm0

IF(.NOT. Visited ) THEN
nSlices = ListGetInteger( CurrentModel % Simulation,'Number Of Slices',GotIt)
nTimes = ListGetInteger( CurrentModel % Simulation,'Number Of Times',GotIt)
IF(nSlices > 1 .AND. nTimes > 1) THEN
iSlice = MODULO( ParEnv % MyPe, nSlices )
iSlice = MODULO( ParEnv % MyPe, nSlices )
iTime = ParEnv % MyPe / nSlices
CALL MPI_Comm_split(ELMER_COMM_WORLD, iTime, ParEnv % PEs, CustomComm0);
CALL MPI_Comm_split(ELMER_COMM_WORLD, iTime, ParEnv % PEs, CustomComm0, ierr);
ELSE
CustomComm0 = ELMER_COMM_WORLD
END IF
Expand All @@ -1415,57 +1415,57 @@ FUNCTION ParallelSlicesComm() RESULT( CustomComm )

END FUNCTION ParallelSlicesComm


FUNCTION ParallelTimesComm() RESULT( CustomComm )
INTEGER :: CustomComm
#ifdef PARALLEL_FOR_REAL
INTEGER :: CustomComm
#ifdef PARALLEL_FOR_REAL
LOGICAL :: Visited = .FALSE.
INTEGER :: nSlices, nTimes, iSlice, iTime
INTEGER :: nSlices, nTimes, iSlice, iTime, ierr
INTEGER :: CustomComm0
LOGICAL :: GotIt
SAVE Visited, CustomComm0

IF(.NOT. Visited ) THEN
nSlices = ListGetInteger( CurrentModel % Simulation,'Number Of Slices',GotIt)
nTimes = ListGetInteger( CurrentModel % Simulation,'Number Of Times',GotIt)
IF(nSlices > 1 .AND. nTimes > 1) THEN
iSlice = MODULO( ParEnv % MyPe, nSlices )
iTime = ParEnv % MyPe / nSlices
CALL MPI_Comm_split(ELMER_COMM_WORLD, iSlice, ParEnv % PEs, CustomComm0);
iSlice = MODULO( ParEnv % MyPe, nSlices )
iTime = ParEnv % MyPe / nSlices
CALL MPI_Comm_split(ELMER_COMM_WORLD, iSlice, ParEnv % PEs, CustomComm0, ierr);
ELSE
CustomComm0 = ELMER_COMM_WORLD
END IF
PRINT *,'Creating TimesComm:',ParEnv % MyPe, iSlice, iTime
Visited = .TRUE.
END IF

CustomComm = CustomComm0
#else
CustomComm = -1
#endif
#endif
END FUNCTION ParallelTimesComm


FUNCTION ParallelPieceRank(CustomComm) RESULT (CommRank)
INTEGER :: CustomComm, CommRank
INTEGER :: CustomComm, CommRank, ierr
#ifdef PARALLEL_FOR_REAL
PRINT *,'GetRank:',ParEnv % MyPe, CustomComm
CALL MPI_Comm_rank(CustomComm, CommRank)
CALL MPI_Comm_rank(CustomComm, CommRank, ierr)
PRINT *,'GotRank:',ParEnv % MyPe, CommRank
#else
CommRank = -1
#endif
#endif
END FUNCTION ParallelPieceRank

FUNCTION ParallelPieceSize(CustomComm) RESULT (CommSize)
INTEGER :: CustomComm, CommSize
INTEGER :: CustomComm, CommSize, ierr
#ifdef PARALLEL_FOR_REAL
PRINT *,'GetSize:',ParEnv % MyPe, CustomComm
CALL MPI_Comm_size(CustomComm, CommSize)
CALL MPI_Comm_size(CustomComm, CommSize, ierr)
PRINT *,'GotSize:',ParEnv % MyPe, CommSize
#else
CommRank = -1
#endif
#endif
END FUNCTION ParallelPieceSize


Expand Down

0 comments on commit fb8d4e3

Please sign in to comment.