Skip to content

Commit

Permalink
Merge pull request #27 from aradi/commfree
Browse files Browse the repository at this point in the history
Implement wrapper for mpi_comm_free()
  • Loading branch information
bhourahine authored Mar 14, 2021
2 parents 3c38f24 + af0d283 commit 5b43416
Showing 1 changed file with 28 additions and 9 deletions.
37 changes: 28 additions & 9 deletions lib/mpifx_comm.fpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!> Contains the extended MPI communicator.
module mpifx_comm_module
use mpi
use mpi, only : MPI_COMM_WORLD, mpi_comm_size, mpi_comm_rank, mpi_comm_split, mpi_comm_free
use mpifx_helper_module
implicit none
private
Expand All @@ -21,6 +21,9 @@ module mpifx_comm_module
!> Creates a new communicator by splitting the old one.
procedure :: split => mpifx_comm_split

!> Frees the communicator. The communicator should not be used after this.
procedure :: free => mpifx_comm_free

end type mpifx_comm

contains
Expand Down Expand Up @@ -52,7 +55,7 @@ contains
end if
self%leadrank = 0
self%lead = (self%rank == self%leadrank)

end subroutine mpifx_comm_init


Expand All @@ -73,10 +76,10 @@ contains
!! program test_split
!! use libmpifx_module
!! implicit none
!!
!!
!! type(mpifx_comm) :: allproc, groupproc
!! integer :: groupsize, mygroup
!!
!!
!! call mpifx_init()
!! call allproc%init()
!! groupsize = allproc%size / 2
Expand All @@ -85,9 +88,9 @@ contains
!! write(*, "(3(A,1X,I0,1X))") "ID:", allproc%rank, "SUBGROUP", &
!! & mygroup, "SUBGROUP ID", groupproc%rank
!! call mpifx_finalize()
!!
!!
!! end program test_split
!!
!!
!! \see MPI documentation (\c MPI_COMM_SPLIT)
!!
subroutine mpifx_comm_split(self, splitkey, rankkey, newcomm, error)
Expand All @@ -97,7 +100,7 @@ contains
integer, intent(out), optional :: error

integer :: error0, newcommid

call mpi_comm_split(self%id, splitkey, rankkey, newcommid, error0)
call handle_errorflag(error0, "mpi_comm_split() in mpifx_comm_split()", error)
if (error0 /= 0) then
Expand All @@ -106,6 +109,22 @@ contains
call newcomm%init(newcommid, error)

end subroutine mpifx_comm_split




!> Frees the MPI communicator.
!>
!> After this call, the passed communicator should not be used any more.
!>
!> \param self Communicator instance.
!>
subroutine mpifx_comm_free(self)
class(mpifx_comm), intent(inout) :: self

integer :: error

call mpi_comm_free(self%id, error)

end subroutine mpifx_comm_free


end module mpifx_comm_module

0 comments on commit 5b43416

Please sign in to comment.