Skip to content

Commit

Permalink
Merge pull request #3316 from GEOS-ESM/bugfix/atrayano/#3314_protect_…
Browse files Browse the repository at this point in the history
…comm_dup

Added protection for null mpi communicator
  • Loading branch information
tclune authored Jan 14, 2025
2 parents 5e3f8f9 + 0361120 commit 3e18fc4
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions base/FileIOShared.F90
Original file line number Diff line number Diff line change
Expand Up @@ -544,12 +544,12 @@ subroutine ArrDescrInit(ArrDes,comm,im_world,jm_world,lm_world,nx,ny,num_readers
ArrDes%jm_world=jm_world
ArrDes%lm_world=lm_world

call MPI_Comm_Dup(readers_comm, ArrDes%readers_comm, status)
call MPI_Comm_Dup(ioscattercomm, ArrDes%IOscattercomm, status)
call MPI_Comm_Dup(writers_comm, ArrDes%writers_comm, status)
call MPI_Comm_Dup(iogathercomm, ArrDes%IOgathercomm, status)
call MPI_Comm_Dup(xcomm, ArrDes%Xcomm, status)
call MPI_Comm_Dup(ycomm, ArrDes%Ycomm, status)
call MAPL_Comm_dup(readers_comm, ArrDes%readers_comm, status)
call MAPL_Comm_dup(ioscattercomm, ArrDes%IOscattercomm, status)
call MAPL_Comm_dup(writers_comm, ArrDes%writers_comm, status)
call MAPL_Comm_dup(iogathercomm, ArrDes%IOgathercomm, status)
call MAPL_Comm_dup(xcomm, ArrDes%Xcomm, status)
call MAPL_Comm_dup(ycomm, ArrDes%Ycomm, status)
call mpi_comm_rank(arrdes%ycomm,arrdes%myrow,status)
_VERIFY(status)

Expand Down Expand Up @@ -595,16 +595,16 @@ subroutine ArrDescrSet(ArrDes, offset, &

if(present(offset )) ArrDes%offset = offset
if(present(readers_comm )) then
call MPI_Comm_Dup(readers_comm, ArrDes%readers_comm, status)
call MAPL_Comm_dup(readers_comm, ArrDes%readers_comm, status)
end if
if(present(ioscattercomm)) then
call MPI_Comm_Dup(IOscattercomm, ArrDes%IOscattercomm, status)
call MAPL_Comm_dup(IOscattercomm, ArrDes%IOscattercomm, status)
end if
if(present(writers_comm )) then
call MPI_Comm_Dup(writers_comm, ArrDes%writers_comm, status)
call MAPL_Comm_dup(writers_comm, ArrDes%writers_comm, status)
end if
if(present(iogathercomm)) then
call MPI_Comm_Dup(IOgathercomm, ArrDes%IOgathercomm, status)
call MAPL_Comm_dup(IOgathercomm, ArrDes%IOgathercomm, status)
end if
if(present(i1 )) ArrDes%i1 => i1
if(present(in )) ArrDes%in => in
Expand Down Expand Up @@ -645,7 +645,7 @@ subroutine ArrDescrCreateWriterComm(arrdes, full_comm, num_writers, rc)
call MPI_COMM_SPLIT(full_comm, color, myid, arrdes%writers_comm, status)
_VERIFY(status)
if (num_writers==ny) then
call MPI_Comm_Dup(arrdes%Xcomm, ArrDes%IOgathercomm, status)
call MAPL_Comm_dup(arrdes%Xcomm, ArrDes%IOgathercomm, status)
else
j = arrdes%NY0 - mod(arrdes%NY0-1,ny_by_writers)
call MPI_COMM_SPLIT(full_comm, j, myid, arrdes%IOgathercomm, status)
Expand Down Expand Up @@ -693,7 +693,7 @@ subroutine ArrDescrCreateReaderComm(arrdes, full_comm, num_readers, rc)
call MPI_COMM_SPLIT(full_comm, color, MYID, arrdes%readers_comm, status)
_VERIFY(status)
if (num_readers==ny) then
call MPI_Comm_Dup(arrdes%Xcomm, ArrDes%IOscattercomm, status)
call MAPL_Comm_dup(arrdes%Xcomm, ArrDes%IOscattercomm, status)
else
j = arrdes%NY0 - mod(arrdes%NY0-1,ny_by_readers)
call MPI_COMM_SPLIT(full_comm, j, MYID, arrdes%IOscattercomm, status)
Expand Down Expand Up @@ -917,4 +917,19 @@ subroutine MAPL_CommFree(comm, rc)
end if
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_CommFree

subroutine MAPL_Comm_Dup(comm, newcomm, rc)
integer, intent(in) :: comm
integer, intent(out) :: newcomm
integer, optional, intent(out) :: rc

integer :: status

newcomm = MPI_COMM_NULL
if(comm /= MPI_COMM_NULL) then
call MPI_Comm_Dup(comm, newcomm,status)
_VERIFY(status)
end if
_RETURN(ESMF_SUCCESS)
end subroutine MAPL_Comm_Dup
end module FileIOSharedMod

0 comments on commit 3e18fc4

Please sign in to comment.