@@ -72,6 +72,11 @@ module mpi
7272 module procedure MPI_Allreduce_1D_int_proc
7373 end interface
7474
75+ interface MPI_Gatherv
76+ module procedure MPI_Gatherv_int
77+ module procedure MPI_Gatherv_real
78+ end interface MPI_Gatherv
79+
7580 interface MPI_Wtime
7681 module procedure MPI_Wtime_proc
7782 end interface
@@ -765,6 +770,88 @@ subroutine MPI_Recv_StatusIgnore_proc(buf, count, datatype, source, tag, comm, s
765770
766771 end subroutine MPI_Recv_StatusIgnore_proc
767772
773+ subroutine MPI_Gatherv_int (sendbuf , sendcount , sendtype , recvbuf , recvcounts , &
774+ displs , recvtype , root , comm , ierror )
775+ use iso_c_binding, only: c_int, c_ptr, c_loc
776+ use mpi_c_bindings, only: c_mpi_gatherv, c_mpi_in_place
777+ integer , dimension (:), intent (in ), target :: sendbuf
778+ integer , intent (in ) :: sendcount
779+ integer , intent (in ) :: sendtype
780+ integer , dimension (:), intent (out ), target :: recvbuf
781+ integer , dimension (:), intent (in ) :: recvcounts
782+ integer , dimension (:), intent (in ) :: displs
783+ integer , intent (in ) :: recvtype
784+ integer , intent (in ) :: root
785+ integer , intent (in ) :: comm
786+ integer , optional , intent (out ) :: ierror
787+ integer (kind= MPI_HANDLE_KIND) :: c_sendtype, c_recvtype, c_comm
788+ type (c_ptr) :: c_sendbuf, c_recvbuf
789+ integer (c_int) :: local_ierr
790+
791+ if (sendbuf(1 ) == MPI_IN_PLACE) then
792+ c_sendbuf = c_MPI_IN_PLACE
793+ else
794+ c_sendbuf = c_loc(sendbuf)
795+ end if
796+
797+ c_recvbuf = c_loc(recvbuf)
798+ c_sendtype = handle_mpi_datatype_f2c(sendtype)
799+ c_recvtype = handle_mpi_datatype_f2c(recvtype)
800+ c_comm = handle_mpi_comm_f2c(comm)
801+
802+ ! Call C MPI_Gatherv
803+ local_ierr = c_mpi_gatherv(c_sendbuf, sendcount, c_sendtype, &
804+ c_recvbuf, recvcounts, displs, c_recvtype, &
805+ root, c_comm)
806+
807+ if (present (ierror)) then
808+ ierror = local_ierr
809+ else if (local_ierr /= MPI_SUCCESS) then
810+ print * , " MPI_Gatherv failed with error code: " , local_ierr
811+ end if
812+ end subroutine MPI_Gatherv_int
813+
814+ subroutine MPI_Gatherv_real (sendbuf , sendcount , sendtype , recvbuf , recvcounts , &
815+ displs , recvtype , root , comm , ierror )
816+ use iso_c_binding, only: c_int, c_ptr, c_loc
817+ use mpi_c_bindings, only: c_mpi_gatherv, c_mpi_in_place
818+ real (8 ), dimension (:), intent (in ), target :: sendbuf
819+ integer , intent (in ) :: sendcount
820+ integer , intent (in ) :: sendtype
821+ real (8 ), dimension (:), intent (out ), target :: recvbuf
822+ integer , dimension (:), intent (in ) :: recvcounts
823+ integer , dimension (:), intent (in ) :: displs
824+ integer , intent (in ) :: recvtype
825+ integer , intent (in ) :: root
826+ integer , intent (in ) :: comm
827+ integer , optional , intent (out ) :: ierror
828+ integer (kind= MPI_HANDLE_KIND) :: c_sendtype, c_recvtype, c_comm
829+ type (c_ptr) :: c_sendbuf, c_recvbuf
830+ integer (c_int) :: local_ierr
831+
832+ if (sendbuf(1 ) == MPI_IN_PLACE) then
833+ c_sendbuf = c_MPI_IN_PLACE
834+ else
835+ c_sendbuf = c_loc(sendbuf)
836+ end if
837+
838+ c_recvbuf = c_loc(recvbuf)
839+ c_sendtype = handle_mpi_datatype_f2c(sendtype)
840+ c_recvtype = handle_mpi_datatype_f2c(recvtype)
841+ c_comm = handle_mpi_comm_f2c(comm)
842+
843+ ! Call C MPI_Gatherv
844+ local_ierr = c_mpi_gatherv(c_sendbuf, sendcount, c_sendtype, &
845+ c_recvbuf, recvcounts, displs, c_recvtype, &
846+ root, c_comm)
847+
848+ if (present (ierror)) then
849+ ierror = local_ierr
850+ else if (local_ierr /= MPI_SUCCESS) then
851+ print * , " MPI_Gatherv failed with error code: " , local_ierr
852+ end if
853+ end subroutine MPI_Gatherv_real
854+
768855 subroutine MPI_Waitall_proc (count , array_of_requests , array_of_statuses , ierror )
769856 use iso_c_binding, only: c_int, c_ptr
770857 use mpi_c_bindings, only: c_mpi_waitall, c_mpi_request_f2c, c_mpi_request_c2f, c_mpi_status_c2f, c_mpi_statuses_ignore
0 commit comments