diff --git a/lib/mpifx_abort.fpp b/lib/mpifx_abort.fpp index 26a2522..1736eba 100644 --- a/lib/mpifx_abort.fpp +++ b/lib/mpifx_abort.fpp @@ -1,6 +1,6 @@ !> Contains wrapper for \c MPI_ABORT. module mpifx_abort_module - use mpi + use mpi_f08, only : mpi_abort use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : handle_errorflag implicit none @@ -47,7 +47,7 @@ contains errorcode0 = -1 end if - call mpi_abort(mycomm%id, errorcode0, error0) + call mpi_abort(mycomm%comm, errorcode0, error0) call handle_errorflag(error0, "MPI_ABORT in mpifx_abort", error) end subroutine mpifx_abort diff --git a/lib/mpifx_allgather.fpp b/lib/mpifx_allgather.fpp index 94ffe02..0a8d2cf 100644 --- a/lib/mpifx_allgather.fpp +++ b/lib/mpifx_allgather.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_ALLGATHER module mpifx_allgather_module - use mpi + use mpi_f08, only : mpi_allgather, mpi_character, mpi_complex, mpi_double_complex,& + & mpi_double_precision, mpi_integer, mpi_logical, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, handle_errorflag, sp implicit none @@ -122,7 +123,7 @@ contains @:ASSERT(size(recv) == ${SIZE}$ * mycomm%size) @:ASSERT(size(recv, dim=${RANK}$) == size(send, dim=${RANK}$) * mycomm%size) - call mpi_allgather(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, mycomm%id,& + call mpi_allgather(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, mycomm%comm,& & error0) call handle_errorflag(error0, 'MPI_ALLGATHER in mpifx_allgather_${SUFFIX}$', error) @@ -162,7 +163,7 @@ contains @:ASSERT(size(recv, dim=${RANK + 1}$) == mycomm%size) call mpi_allgather(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, 'MPI_ALLGATHER in mpifx_allgather_${SUFFIX}$', error) end subroutine mpifx_allgather_${SUFFIX}$ diff --git a/lib/mpifx_allgatherv.fpp b/lib/mpifx_allgatherv.fpp index df6afd6..c691d70 100644 --- a/lib/mpifx_allgatherv.fpp +++ b/lib/mpifx_allgatherv.fpp @@ -45,7 +45,7 @@ end if call mpi_allgatherv(send, size(send), ${MPI_TYPE}$, recv, recvcounts, displs0, & - & ${MPI_TYPE}$, mycomm%id, error0) + & ${MPI_TYPE}$, mycomm%comm, error0) call handle_errorflag(error0, "MPI_ALLGATHERV in mpifx_allgatherv_${SUFFIX}$", error) @@ -96,7 +96,7 @@ end if call mpi_allgatherv(send, ${SEND_BUFFER_SIZE}$, ${MPI_TYPE}$, recv, recvcounts, displs0, & - & ${MPI_TYPE}$, mycomm%id, error0) + & ${MPI_TYPE}$, mycomm%comm, error0) call handle_errorflag(error0, "MPI_ALLGATHERV in mpifx_allgatherv_${SUFFIX}$", error) @@ -106,7 +106,8 @@ !> Contains wrapper for \c MPI_allgatherv module mpifx_allgatherv_module - use mpi + use mpi_f08, only : mpi_allgatherv, mpi_character, mpi_complex, mpi_double_complex,& + & mpi_double_precision, mpi_integer, mpi_logical, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, handle_errorflag, sp implicit none diff --git a/lib/mpifx_allreduce.fpp b/lib/mpifx_allreduce.fpp index 783a6ad..5f1276a 100644 --- a/lib/mpifx_allreduce.fpp +++ b/lib/mpifx_allreduce.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_ALLREDUCE. module mpifx_allreduce_module - use mpi + use mpi_f08, only : mpi_allreduce, mpi_complex, mpi_double_complex, mpi_double_precision,& + & mpi_in_place, mpi_integer, mpi_logical, mpi_op, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, handle_errorflag, sp implicit none @@ -50,7 +51,8 @@ module mpifx_allreduce_module interface mpifx_allreduce #:for TYPE in TYPES #:for RANK in RANKS - module procedure mpifx_allreduce_${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_allreduce_with_type${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_allreduce_with_id${TYPE_ABBREVS[TYPE]}$${RANK}$ #:endfor #:endfor end interface mpifx_allreduce @@ -94,7 +96,8 @@ module mpifx_allreduce_module interface mpifx_allreduceip #:for TYPE in TYPES #:for RANK in RANKS - module procedure mpifx_allreduceip_${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_allreduceip_with_type${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_allreduceip_with_id${TYPE_ABBREVS[TYPE]}$${RANK}$ #:endfor #:endfor end interface mpifx_allreduceip @@ -109,7 +112,7 @@ contains !! !! See MPI documentation (mpi_allreduce()) for further details. !! - subroutine mpifx_allreduce_${SUFFIX}$(mycomm, orig, reduced, reductionop, error) + subroutine mpifx_allreduce_with_type${SUFFIX}$(mycomm, orig, reduced, reductionop, error) !> MPI communicator. type(mpifx_comm), intent(in) :: mycomm @@ -121,7 +124,7 @@ contains ${TYPE}$, intent(inout) :: reduced${RANKSUFFIX(RANK)}$ !> Reduction operator - integer, intent(in) :: reductionop + type(mpi_op), intent(in) :: reductionop !> Error code on exit. integer, intent(out), optional :: error @@ -135,11 +138,36 @@ contains #:set SIZE = '1' if RANK == 0 else 'size(orig)' #:set COUNT = SIZE - call mpi_allreduce(orig, reduced, ${COUNT}$, ${MPITYPE}$, reductionop, mycomm%id, error0) + call mpi_allreduce(orig, reduced, ${COUNT}$, ${MPITYPE}$, reductionop, mycomm%comm, error0) call handle_errorflag(error0, 'MPI_ALLREDUCE in mpifx_allreduce_${SUFFIX}$', error) - end subroutine mpifx_allreduce_${SUFFIX}$ + end subroutine mpifx_allreduce_with_type${SUFFIX}$ + + + subroutine mpifx_allreduce_with_id${SUFFIX}$(mycomm, orig, reduced, reductionop, error) + + !> MPI communicator. + type(mpifx_comm), intent(in) :: mycomm + + !> Quantity to be reduced. + ${TYPE}$, intent(in) :: orig${RANKSUFFIX(RANK)}$ + + !> Contains result on exit. + ${TYPE}$, intent(inout) :: reduced${RANKSUFFIX(RANK)}$ + + !> Reduction operator + integer, intent(in) :: reductionop + + !> Error code on exit. + integer, intent(out), optional :: error + + type(mpi_op) :: newop + + newop%mpi_val = reductionop + call mpifx_allreduce(mycomm, orig, reduced, newop, error) + + end subroutine mpifx_allreduce_with_id${SUFFIX}$ #:enddef mpifx_allreduce_template @@ -151,7 +179,7 @@ contains !! !! See MPI documentation (mpi_allreduce()) for further details. !! - subroutine mpifx_allreduceip_${SUFFIX}$(mycomm, origreduced, reductionop, error) + subroutine mpifx_allreduceip_with_type${SUFFIX}$(mycomm, origreduced, reductionop, error) !> MPI communicator. type(mpifx_comm), intent(in) :: mycomm @@ -160,7 +188,7 @@ contains ${TYPE}$, intent(inout) :: origreduced${RANKSUFFIX(RANK)}$ !> Reduction operator. - integer, intent(in) :: reductionop + type(mpi_op), intent(in) :: reductionop !> Error code on exit. integer, intent(out), optional :: error @@ -170,11 +198,34 @@ contains #:set SIZE = '1' if RANK == 0 else 'size(origreduced)' #:set COUNT = SIZE - call mpi_allreduce(MPI_IN_PLACE, origreduced, ${COUNT}$, ${MPITYPE}$, reductionop, mycomm%id,& + call mpi_allreduce(MPI_IN_PLACE, origreduced, ${COUNT}$, ${MPITYPE}$, reductionop, mycomm%comm,& & error0) call handle_errorflag(error0, "MPI_REDUCE in mpifx_allreduceip_${SUFFIX}$", error) - end subroutine mpifx_allreduceip_${SUFFIX}$ + end subroutine mpifx_allreduceip_with_type${SUFFIX}$ + + subroutine mpifx_allreduceip_with_id${SUFFIX}$(mycomm, origreduced, reductionop, error) + + !> MPI communicator. + type(mpifx_comm), intent(in) :: mycomm + + !> Quantity to be reduced on input, reduced on exit. + ${TYPE}$, intent(inout) :: origreduced${RANKSUFFIX(RANK)}$ + + !> Reduction operator. + integer, intent(in) :: reductionop + + !> Error code on exit. + integer, intent(out), optional :: error + + type(mpi_op) :: newop + + newop%mpi_val = reductionop + + call mpifx_allreduceip(mycomm, origreduced, newop, error) + + end subroutine mpifx_allreduceip_with_id${SUFFIX}$ + #:enddef mpifx_allreduceip_template diff --git a/lib/mpifx_barrier.fpp b/lib/mpifx_barrier.fpp index c98908c..0963c48 100644 --- a/lib/mpifx_barrier.fpp +++ b/lib/mpifx_barrier.fpp @@ -2,7 +2,7 @@ !> Contains wrapper for \c MPI_BARRIER. module mpifx_barrier_module - use mpi + use mpi_f08, only : mpi_barrier use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : handle_errorflag implicit none @@ -40,7 +40,7 @@ contains integer :: error0 - call mpi_barrier(mycomm%id, error0) + call mpi_barrier(mycomm%comm, error0) call handle_errorflag(error0, "MPI_BARRIER in mpifx_barrier", error) end subroutine mpifx_barrier diff --git a/lib/mpifx_bcast.fpp b/lib/mpifx_bcast.fpp index cdb339a..cb9e3d6 100644 --- a/lib/mpifx_bcast.fpp +++ b/lib/mpifx_bcast.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_BCAST. module mpifx_bcast_module - use mpi + use mpi_f08, only : mpi_bcast, mpi_character, mpi_complex, mpi_double_complex,& + & mpi_double_precision, mpi_integer, mpi_logical, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, getoptarg, handle_errorflag, sp implicit none @@ -75,7 +76,7 @@ contains #:set COUNT = ('len(msg) * ' + SIZE if HASLENGTH else SIZE) call getoptarg(mycomm%leadrank, root0, root) - call mpi_bcast(msg, ${COUNT}$, ${MPITYPE}$, root0, mycomm%id, error0) + call mpi_bcast(msg, ${COUNT}$, ${MPITYPE}$, root0, mycomm%comm, error0) call handle_errorflag(error0, "MPI_BCAST in mpifx_bcast_${SUFFIX}$", error) end subroutine mpifx_bcast_${SUFFIX}$ diff --git a/lib/mpifx_comm.fpp b/lib/mpifx_comm.fpp index ac30042..b1f435c 100644 --- a/lib/mpifx_comm.fpp +++ b/lib/mpifx_comm.fpp @@ -1,6 +1,6 @@ !> Contains the extended MPI communicator. module mpifx_comm_module - use mpi + use mpi_f08, only : mpi_comm, mpi_comm_world, mpi_info_null use mpifx_helper_module, only : getoptarg, handle_errorflag implicit none private @@ -9,14 +9,19 @@ module mpifx_comm_module !> MPI communicator with some additional information. type mpifx_comm - integer :: id !< Communicator id. - integer :: size !< Nr. of processes (size). - integer :: rank !< Rank of the current process. - integer :: leadrank !< Index of the lead node. - logical :: lead !< True if current process is the lead (rank == 0). + integer :: id !< Communicator id. + type(mpi_comm) :: comm !< MPI communicator handle. + integer :: size !< Nr. of processes (size). + integer :: rank !< Rank of the current process. + integer :: leadrank !< Index of the lead node. + logical :: lead !< True if current process is the lead (rank == 0). contains + !> Initializes the MPI environment. - procedure :: init => mpifx_comm_init + procedure, private :: mpifx_comm_init_int + procedure, private :: mpifx_comm_init_comm + + generic :: init => mpifx_comm_init_int, mpifx_comm_init_comm !> Creates a new communicator by splitting the old one. procedure :: split => mpifx_comm_split @@ -38,20 +43,27 @@ contains !! \param error Error flag on return containing the first error occuring !! during the calls mpi_comm_size and mpi_comm_rank. !! - subroutine mpifx_comm_init(self, commid, error) + subroutine mpifx_comm_init_comm(self, comm, error) class(mpifx_comm), intent(out) :: self - integer, intent(in), optional :: commid + type(mpi_comm), intent(in), optional :: comm integer, intent(out), optional :: error integer :: error0 + type(mpi_comm) :: default_comm + default_comm = MPI_COMM_WORLD - call getoptarg(MPI_COMM_WORLD, self%id, commid) - call mpi_comm_size(self%id, self%size, error0) + if (present(comm)) then + self%comm = comm + else + self%comm = default_comm + end if + self%id = self%comm%mpi_val + call mpi_comm_size(self%comm, self%size, error0) call handle_errorflag(error0, "mpi_comm_size() in mpifx_comm_init()", error) if (error0 /= 0) then return end if - call mpi_comm_rank(self%id, self%rank, error0) + call mpi_comm_rank(self%comm, self%rank, error0) call handle_errorflag(error0, "mpi_comm_rank() in mpifx_comm_init()", error) if (error0 /= 0) then return @@ -59,7 +71,20 @@ contains self%leadrank = 0 self%lead = (self%rank == self%leadrank) - end subroutine mpifx_comm_init + end subroutine mpifx_comm_init_comm + + + subroutine mpifx_comm_init_int(self, commid, error) + class(mpifx_comm), intent(out) :: self + integer, intent(in) :: commid + integer, intent(out), optional :: error + + type(mpi_comm) :: newcomm + + newcomm%mpi_val = commid + call self%mpifx_comm_init_comm(newcomm, error) + + end subroutine mpifx_comm_init_int !> Creates a new communicators by splitting the old one. @@ -102,14 +127,15 @@ contains class(mpifx_comm), intent(out) :: newcomm integer, intent(out), optional :: error - integer :: error0, newcommid + integer :: error0 + type(mpi_comm) :: newmpicomm - call mpi_comm_split(self%id, splitkey, rankkey, newcommid, error0) + call mpi_comm_split(self%comm, splitkey, rankkey, newmpicomm, error0) call handle_errorflag(error0, "mpi_comm_split() in mpifx_comm_split()", error) if (error0 /= 0) then return end if - call newcomm%init(newcommid, error) + call newcomm%init(newmpicomm, error) end subroutine mpifx_comm_split @@ -150,14 +176,15 @@ contains class(mpifx_comm), intent(out) :: newcomm integer, intent(out), optional :: error - integer :: error0, newcommid + integer :: error0 + type(mpi_comm) :: newmpicomm - call mpi_comm_split_type(self%id, splittype, rankkey, MPI_INFO_NULL, newcommid, error0) + call mpi_comm_split_type(self%comm, splittype, rankkey, MPI_INFO_NULL, newmpicomm, error0) call handle_errorflag(error0, "mpi_comm_split_type() in mpifx_comm_split_type()", error) if (error0 /= 0) then return end if - call newcomm%init(newcommid, error) + call newcomm%init(newmpicomm, error) end subroutine mpifx_comm_split_type @@ -173,7 +200,8 @@ contains integer :: error - call mpi_comm_free(self%id, error) + call mpi_comm_free(self%comm, error) + self%id = self%comm%mpi_val end subroutine mpifx_comm_free diff --git a/lib/mpifx_constants.fpp b/lib/mpifx_constants.fpp index 48ff532..845ee2a 100644 --- a/lib/mpifx_constants.fpp +++ b/lib/mpifx_constants.fpp @@ -1,7 +1,7 @@ !> Exports some MPI constants. !! \cond HIDDEN module mpifx_constants_module - use mpi + use mpi_f08, only : MPI_ADDRESS_KIND private public :: MPI_MAX, MPI_MIN, MPI_SUM, MPI_PROD diff --git a/lib/mpifx_finalize.fpp b/lib/mpifx_finalize.fpp index 21976bf..105ced6 100644 --- a/lib/mpifx_finalize.fpp +++ b/lib/mpifx_finalize.fpp @@ -1,6 +1,6 @@ !> Contains wrapper for \c MPI_FINALIZE. module mpifx_finalize_module - use mpi + use mpi_f08, only : mpi_finalize use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : handle_errorflag implicit none diff --git a/lib/mpifx_gather.fpp b/lib/mpifx_gather.fpp index 5370bf0..34658eb 100644 --- a/lib/mpifx_gather.fpp +++ b/lib/mpifx_gather.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_GATHER module mpifx_gather_module - use mpi + use mpi_f08, only : mpi_double_complex, mpi_double_precision, mpi_character, mpi_complex,& + & mpi_gather, mpi_integer, mpi_logical, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, getoptarg, handle_errorflag, sp implicit none @@ -135,7 +136,7 @@ contains call getoptarg(mycomm%leadrank, root0, root) call mpi_gather(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, root0,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, "MPI_GATHER in mpifx_gather_${SUFFIX}$", error) end subroutine mpifx_gather_${SUFFIX}$ @@ -171,7 +172,7 @@ contains @:ASSERT(.not. mycomm%lead .or. size(recv, dim=${RANK + 1}$) == mycomm%size) call getoptarg(mycomm%leadrank, root0, root) - call mpi_gather(send, ${SIZE}$, ${MPITYPE}$, recv, ${SIZE}$, ${MPITYPE}$, root0, mycomm%id,& + call mpi_gather(send, ${SIZE}$, ${MPITYPE}$, recv, ${SIZE}$, ${MPITYPE}$, root0, mycomm%comm,& & error0) call handle_errorflag(error0, "MPI_GATHER in mpifx_gather_${SUFFIX}$", error) diff --git a/lib/mpifx_gatherv.fpp b/lib/mpifx_gatherv.fpp index 6fb1170..5d2c511 100644 --- a/lib/mpifx_gatherv.fpp +++ b/lib/mpifx_gatherv.fpp @@ -67,7 +67,7 @@ end if call mpi_gatherv(send, size(send), ${MPI_TYPE}$, recv, recvcounts, displs0, & - & ${MPI_TYPE}$, root0, mycomm%id, error0) + & ${MPI_TYPE}$, root0, mycomm%comm, error0) call handle_errorflag(error0, "MPI_GATHERV in mpifx_gatherv_${SUFFIX}$", error) @@ -120,7 +120,7 @@ end if call mpi_gatherv(send, ${SEND_SIZE}$, ${MPI_TYPE}$, recv, recvcounts, displs0, & - & ${MPI_TYPE}$, root0, mycomm%id, error0) + & ${MPI_TYPE}$, root0, mycomm%comm, error0) call handle_errorflag(error0, "MPI_GATHERV in mpifx_gatherv_${SUFFIX}$", error) @@ -131,7 +131,8 @@ !> Contains wrapper for \c MPI_gatherv module mpifx_gatherv_module - use mpi + use mpi_f08, only : mpi_character, MPI_COMM_WORLD, mpi_complex, mpi_double_complex,& + & mpi_double_precision, mpi_integer, mpi_logical, mpi_real use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, handle_errorflag, sp implicit none diff --git a/lib/mpifx_get_processor_name.fpp b/lib/mpifx_get_processor_name.fpp index 4b0fb8f..74f1676 100644 --- a/lib/mpifx_get_processor_name.fpp +++ b/lib/mpifx_get_processor_name.fpp @@ -1,6 +1,6 @@ !> Contains the extended MPI communicator. module mpifx_get_processor_name_module - use mpi + use mpi_f08, only : mpi_get_processor_name, MPI_MAX_PROCESSOR_NAME implicit none private diff --git a/lib/mpifx_helper.fpp b/lib/mpifx_helper.fpp index 44100b0..3a284be 100644 --- a/lib/mpifx_helper.fpp +++ b/lib/mpifx_helper.fpp @@ -4,7 +4,7 @@ !> Exports constants and helper routine(s). !! \cond HIDDEN module mpifx_helper_module - use mpi + use mpi_f08, only : mpi_abort, MPI_COMM_WORLD use, intrinsic :: iso_fortran_env, only : stderr => error_unit use mpifx_constants_module, only : MPIFX_ASSERT_FAILED, MPIFX_UNHANDLED_ERROR implicit none diff --git a/lib/mpifx_init.fpp b/lib/mpifx_init.fpp index 98422a5..8d5a110 100644 --- a/lib/mpifx_init.fpp +++ b/lib/mpifx_init.fpp @@ -1,6 +1,6 @@ !> Contains wrapper for \c MPI_INIT. module mpifx_init_module - use mpi + use mpi_f08, only : mpi_abort, MPI_COMM_WORLD, mpi_init, mpi_init_thread use mpifx_comm_module, only : mpifx_comm use mpifx_constants_module, only : MPIFX_UNHANDLED_ERROR use mpifx_helper_module, only : handle_errorflag diff --git a/lib/mpifx_recv.fpp b/lib/mpifx_recv.fpp index 6f5f681..8c82176 100644 --- a/lib/mpifx_recv.fpp +++ b/lib/mpifx_recv.fpp @@ -4,9 +4,11 @@ !> Contains wrapper for \c MPI_RECV module mpifx_recv_module - use mpi + use mpi_f08, only : MPI_ANY_SOURCE, MPI_ANY_TAG, mpi_character, mpi_complex, mpi_double_complex,& + & mpi_double_precision, mpi_integer, mpi_logical, mpi_real, mpi_status, mpi_status_f082f,& + & MPI_STATUS_SIZE use mpifx_comm_module, only : mpifx_comm - use mpifx_helper_module, only : dp, sp + use mpifx_helper_module, only : dp, sp, getoptarg, handle_errorflag implicit none private @@ -52,7 +54,8 @@ module mpifx_recv_module interface mpifx_recv #:for TYPE in TYPES #:for RANK in RANKS - module procedure mpifx_recv_${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_recv_mpi_f08${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_recv_mpi${TYPE_ABBREVS[TYPE]}$${RANK}$ #:endfor #:endfor end interface mpifx_recv @@ -68,18 +71,20 @@ contains !! \param msg Msg to be received. !! \param source Optional source process (default: MPI_ANY_SOURCE) !! \param tag Optional message tag (default: MPI_ANY_TAG). - !! \param status Optional status array. + !! \param status Optional status array as integer. !! \param error Optional error handling flag. !! - subroutine mpifx_recv_${SUFFIX}$(mycomm, msg, source, tag, status, error) + subroutine mpifx_recv_mpi_f08${SUFFIX}$(mycomm, msg, source, tag, status, error) type(mpifx_comm), intent(in) :: mycomm ${TYPE}$, intent(out) :: msg${RANKSUFFIX(RANK)}$ integer, intent(in), optional :: source, tag - integer, intent(out), optional :: status(MPI_STATUS_SIZE) + type(mpi_status), intent(out), optional :: status integer, intent(out), optional :: error integer :: source0, tag0, error0 - integer :: status0(MPI_STATUS_SIZE) + type(mpi_status) :: status0 + + print *, "routine mpif08" call getoptarg(MPI_ANY_TAG, tag0, tag) call getoptarg(MPI_ANY_SOURCE, source0, source) @@ -87,11 +92,34 @@ contains #:set SIZE = '1' if RANK == 0 else 'size(msg)' #:set COUNT = ('len(msg) * ' + SIZE if HASLENGTH else SIZE) - call mpi_recv(msg, ${COUNT}$, ${MPITYPE}$, source0, tag0, mycomm%id, status0, error0) + call mpi_recv(msg, ${COUNT}$, ${MPITYPE}$, source0, tag0, mycomm%comm, status0, error0) call handle_errorflag(error0, "MPI_RECV in mpifx_recv_${SUFFIX}$", error) - call setoptarg(status0, status) - end subroutine mpifx_recv_${SUFFIX}$ + if (present(status)) status = status0 + + end subroutine mpifx_recv_mpi_f08${SUFFIX}$ + + !> Receives a message from a given process. + !! \param mycomm MPI descriptor. + !! \param msg Msg to be received. + !! \param source Optional source process (default: MPI_ANY_SOURCE) + !! \param tag Optional message tag (default: MPI_ANY_TAG). + !! \param status Optional status array as type(mpi_status). + !! \param error Optional error handling flag. + !! + subroutine mpifx_recv_mpi${SUFFIX}$(mycomm, msg, source, tag, status, error) + type(mpifx_comm), intent(in) :: mycomm + ${TYPE}$, intent(out) :: msg${RANKSUFFIX(RANK)}$ + integer, intent(in) :: source, tag + integer, intent(out) :: status(MPI_STATUS_SIZE) + integer, intent(out), optional :: error + + type(mpi_status) :: newstatus + + call mpifx_recv(mycomm, msg, source, tag, newstatus, error) + call mpi_status_f082f(newstatus, status) + + end subroutine mpifx_recv_mpi${SUFFIX}$ #:enddef mpifx_recv_template diff --git a/lib/mpifx_reduce.fpp b/lib/mpifx_reduce.fpp index 4f538ad..b4258a8 100644 --- a/lib/mpifx_reduce.fpp +++ b/lib/mpifx_reduce.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_REDUCE. module mpifx_reduce_module - use mpi + use mpi_f08, only : mpi_complex, mpi_double_complex, mpi_double_precision, MPI_IN_PLACE,& + & mpi_integer, mpi_logical, mpi_op, mpi_real, mpi_reduce use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, getoptarg, handle_errorflag, sp implicit none @@ -50,7 +51,8 @@ module mpifx_reduce_module interface mpifx_reduce #:for TYPE in TYPES #:for RANK in RANKS - module procedure mpifx_reduce_${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_reduce_with_type${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_reduce_with_id${TYPE_ABBREVS[TYPE]}$${RANK}$ #:endfor #:endfor end interface mpifx_reduce @@ -94,7 +96,8 @@ module mpifx_reduce_module interface mpifx_reduceip #:for TYPE in TYPES #:for RANK in RANKS - module procedure mpifx_reduceip_${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_reduceip_with_type${TYPE_ABBREVS[TYPE]}$${RANK}$ + module procedure mpifx_reduceip_with_id${TYPE_ABBREVS[TYPE]}$${RANK}$ #:endfor #:endfor end interface mpifx_reduceip @@ -110,15 +113,15 @@ contains !! \param mycomm MPI communicator. !! \param orig Quantity to be reduced. !! \param reduced Contains result on exit. - !! \param reduceop Reduction operator. + !! \param reduceop Reduction operator of type(mpi_op). !! \param root Root process for the reduced (default: mycomm%leadrank) !! \param error Error code on exit. !! - subroutine mpifx_reduce_${SUFFIX}$(mycomm, orig, reduced, reduceop, root, error) + subroutine mpifx_reduce_with_type${SUFFIX}$(mycomm, orig, reduced, reduceop, root, error) type(mpifx_comm), intent(in) :: mycomm ${TYPE}$, intent(in) :: orig${RANKSUFFIX(RANK)}$ ${TYPE}$, intent(inout) :: reduced${RANKSUFFIX(RANK)}$ - integer, intent(in) :: reduceop + type(mpi_op), intent(in) :: reduceop integer, intent(in), optional :: root integer, intent(out), optional :: error @@ -129,10 +132,35 @@ contains #:set SIZE = '1' if RANK == 0 else 'size(orig)' #:set COUNT = SIZE - call mpi_reduce(orig, reduced, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%id, error0) + call mpi_reduce(orig, reduced, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%comm, error0) call handle_errorflag(error0, "MPI_REDUCE in mpifx_reduce_${SUFFIX}$", error) - end subroutine mpifx_reduce_${SUFFIX}$ + end subroutine mpifx_reduce_with_type${SUFFIX}$ + + !> Reduces on one process (type ${SUFFIX}$). + !! + !! \param mycomm MPI communicator. + !! \param orig Quantity to be reduced. + !! \param reduced Contains result on exit. + !! \param reduceop Reduction operator as integer. + !! \param root Root process for the reduced (default: mycomm%leadrank) + !! \param error Error code on exit. + !! + subroutine mpifx_reduce_with_id${SUFFIX}$(mycomm, orig, reduced, reduceop, root, error) + type(mpifx_comm), intent(in) :: mycomm + ${TYPE}$, intent(in) :: orig${RANKSUFFIX(RANK)}$ + ${TYPE}$, intent(inout) :: reduced${RANKSUFFIX(RANK)}$ + integer, intent(in) :: reduceop + integer, intent(in), optional :: root + integer, intent(out), optional :: error + + type(mpi_op) :: newop + + newop%mpi_val = reduceop + + call mpifx_reduce(mycomm, orig, reduced, newop, root, error) + + end subroutine mpifx_reduce_with_id${SUFFIX}$ #:enddef mpifx_reduce_template @@ -145,14 +173,14 @@ contains !! !! \param mycomm MPI communicator. !! \param origred Quantity to be reduced on input, result on exit - !! \param reduceop Reduction reduceop + !! \param reduceop Reduction reduceop of type(mpi_op). !! \param root Root process for the result (default: mycomm%leadrank) !! \param error Error code on exit. !! - subroutine mpifx_reduceip_${SUFFIX}$(mycomm, origred, reduceop, root, error) + subroutine mpifx_reduceip_with_type${SUFFIX}$(mycomm, origred, reduceop, root, error) type(mpifx_comm), intent(in) :: mycomm ${TYPE}$, intent(inout) :: origred${RANKSUFFIX(RANK)}$ - integer, intent(in) :: reduceop + type(mpi_op), intent(in) :: reduceop integer, intent(in), optional :: root integer, intent(out), optional :: error @@ -165,15 +193,39 @@ contains #:set COUNT = SIZE if (mycomm%rank == root0) then - call mpi_reduce(MPI_IN_PLACE, origred, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%id,& + call mpi_reduce(MPI_IN_PLACE, origred, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%comm,& & error0) else - call mpi_reduce(origred, dummy, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%id, & + call mpi_reduce(origred, dummy, ${COUNT}$, ${MPITYPE}$, reduceop, root0, mycomm%comm, & & error0) end if call handle_errorflag(error0, "MPI_REDUCE in mpifx_reduce_${SUFFIX}$", error) - end subroutine mpifx_reduceip_${SUFFIX}$ + end subroutine mpifx_reduceip_with_type${SUFFIX}$ + + !> Reduces results on one process (type ${SUFFIX}$). + !! + !! \param mycomm MPI communicator. + !! \param origred Quantity to be reduced on input, result on exit + !! \param reduceop Reduction reduceop as integer. + !! \param root Root process for the result (default: mycomm%leadrank) + !! \param error Error code on exit. + !! + subroutine mpifx_reduceip_with_id${SUFFIX}$(mycomm, origred, reduceop, root, error) + type(mpifx_comm), intent(in) :: mycomm + ${TYPE}$, intent(inout) :: origred${RANKSUFFIX(RANK)}$ + integer, intent(in) :: reduceop + integer, intent(in), optional :: root + integer, intent(out), optional :: error + + type(mpi_op) :: newop + + newop%mpi_val = reduceop + + call mpifx_reduceip(mycomm, origred, newop, root, error) + + + end subroutine mpifx_reduceip_with_id${SUFFIX}$ #:enddef mpifx_reduceip_template diff --git a/lib/mpifx_scatter.fpp b/lib/mpifx_scatter.fpp index ee9505e..43eecca 100644 --- a/lib/mpifx_scatter.fpp +++ b/lib/mpifx_scatter.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_SCATTER module mpifx_scatter_module - use mpi + use mpi_f08, only : mpi_double_complex, mpi_double_precision, mpi_character, mpi_complex,& + & mpi_integer, mpi_logical, mpi_real, mpi_scatter use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, getoptarg, handle_errorflag, sp implicit none @@ -124,7 +125,7 @@ contains call getoptarg(mycomm%leadrank, root0, root) call mpi_scatter(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, root0,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, "MPI_SCATTER in mpifx_scatter_${SUFFIX}$", error) end subroutine mpifx_scatter_${SUFFIX}$ @@ -164,7 +165,7 @@ contains call getoptarg(mycomm%leadrank, root0, root) call mpi_scatter(send, ${COUNT}$, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, root0,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, "MPI_SCATTER in mpifx_scatter_${SUFFIX}$", error) end subroutine mpifx_scatter_${SUFFIX}$ diff --git a/lib/mpifx_scatterv.fpp b/lib/mpifx_scatterv.fpp index 44586c6..1ee1d42 100644 --- a/lib/mpifx_scatterv.fpp +++ b/lib/mpifx_scatterv.fpp @@ -4,7 +4,8 @@ !> Contains wrapper for \c MPI_SCATTER module mpifx_scatterv_module - use mpi + use mpi_f08, only : mpi_double_complex, mpi_double_precision, mpi_character, mpi_complex,& + & mpi_integer, mpi_logical, mpi_real, mpi_scatterv use mpifx_comm_module, only : mpifx_comm use mpifx_helper_module, only : dp, getoptarg, handle_errorflag, sp implicit none @@ -131,7 +132,7 @@ contains end if end if call mpi_scatterv(send, sendcounts, displs0, ${MPITYPE}$, recv, ${SIZE}$, ${MPITYPE}$, root0,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, "MPI_SCATTER in mpifx_scatterv_${SUFFIX}$", error) @@ -192,7 +193,7 @@ contains end if call mpi_scatterv(send, sendcounts, displs0, ${MPITYPE}$, recv, ${COUNT}$, ${MPITYPE}$, root0,& - & mycomm%id, error0) + & mycomm%comm, error0) call handle_errorflag(error0, "MPI_SCATTER in mpifx_scatterv_${SUFFIX}$", error) end subroutine mpifx_scatterv_${SUFFIX}$ diff --git a/lib/mpifx_send.fpp b/lib/mpifx_send.fpp index 4459795..4d0ca6f 100644 --- a/lib/mpifx_send.fpp +++ b/lib/mpifx_send.fpp @@ -4,9 +4,10 @@ !> Contains wrapper for \c MPI_SEND module mpifx_send_module - use mpi + use mpi_f08, only: mpi_character, mpi_complex, mpi_double_complex, mpi_double_precision,& + & mpi_integer, mpi_logical, mpi_real, mpi_send use mpifx_comm_module, only : mpifx_comm - use mpifx_helper_module, only : default_tag, dp, sp + use mpifx_helper_module, only : default_tag, dp, sp, getoptarg, handle_errorflag implicit none private @@ -81,7 +82,7 @@ contains #:set COUNT = ('len(msg) * ' + SIZE if HASLENGTH else SIZE) call getoptarg(default_tag, tag0, tag) - call mpi_send(msg, ${COUNT}$, ${MPITYPE}$, dest, tag0, mycomm%id, error0) + call mpi_send(msg, ${COUNT}$, ${MPITYPE}$, dest, tag0, mycomm%comm, error0) call handle_errorflag(error0, "MPI_SEND in mpifx_send_${SUFFIX}$", error) end subroutine mpifx_send_${SUFFIX}$ diff --git a/lib/mpifx_win.fpp b/lib/mpifx_win.fpp index e85e711..2942d4d 100644 --- a/lib/mpifx_win.fpp +++ b/lib/mpifx_win.fpp @@ -4,7 +4,7 @@ !> Contains routined for MPI shared memory windows. module mpifx_win_module - use mpi_f08 + use mpi_f08, only : MPI_ADDRESS_KIND, mpi_comm, MPI_INFO_NULL, MPI_MODE_NOCHECK, mpi_win use mpifx_helper_module, only : handle_errorflag, sp, dp use mpifx_comm_module, only : mpifx_comm use mpifx_constants_module, only : MPIFX_SIZE_T @@ -88,7 +88,7 @@ contains local_mem_size = int(global_length, kind=MPI_ADDRESS_KIND) * disp_unit end if - self%comm%mpi_val = mycomm%id + self%comm = mycomm%comm call mpi_win_allocate_shared(local_mem_size, disp_unit, MPI_INFO_NULL, self%comm,& & local_baseptr, self%win, error0) call handle_errorflag(error0,& diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 394cd1e..999a102 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -13,7 +13,8 @@ set(targets test_reduce test_scatter test_scatterv - test_win_shared_mem) + test_win_shared_mem + test_send_recv) set(sources-helper testhelper.f90)