[1945] | 1 | #if defined key_mpp_mpi |
---|
| 2 | #if defined key_sp |
---|
| 3 | #define mpivar mpi_real |
---|
| 4 | #else |
---|
| 5 | #define mpivar mpi_double_precision |
---|
| 6 | #endif |
---|
| 7 | #endif |
---|
| 8 | MODULE mppallgatherv |
---|
| 9 | !!====================================================================== |
---|
| 10 | !! *** MODULE mppallgatherv *** |
---|
| 11 | !! NEMO: MPP allgatherv routines |
---|
| 12 | !!====================================================================== |
---|
| 13 | |
---|
| 14 | !!---------------------------------------------------------------------- |
---|
| 15 | !! mpp_gatherv : Gather a real array on all processors |
---|
| 16 | !!---------------------------------------------------------------------- |
---|
| 17 | !! * Modules used |
---|
| 18 | USE par_kind, ONLY : & ! Precision variables |
---|
| 19 | & wp |
---|
| 20 | USE par_oce, ONLY : & ! Ocean parameters |
---|
| 21 | & jpnij |
---|
| 22 | #if defined key_mpp_mpi |
---|
| 23 | USE lib_mpp, ONLY : & ! MPP library |
---|
| 24 | & mpi_comm_opa |
---|
| 25 | #endif |
---|
| 26 | |
---|
| 27 | IMPLICIT NONE |
---|
| 28 | |
---|
| 29 | !! * Routine accessibility |
---|
| 30 | PRIVATE |
---|
| 31 | |
---|
| 32 | PUBLIC & |
---|
| 33 | & mpp_allgatherv |
---|
| 34 | |
---|
| 35 | INTERFACE mpp_allgatherv |
---|
| 36 | MODULE PROCEDURE mpp_allgatherv_real, mpp_allgatherv_int |
---|
| 37 | END INTERFACE |
---|
| 38 | CONTAINS |
---|
| 39 | |
---|
| 40 | SUBROUTINE mpp_allgatherv_real( pvalsin, knoin, pvalsout, ksizeout, & |
---|
| 41 | & knoout, kstartout ) |
---|
| 42 | !!---------------------------------------------------------------------- |
---|
| 43 | !! *** ROUTINE mpp_allgatherv_real *** |
---|
| 44 | !! |
---|
| 45 | !! ** Purpose : Gather a real array on all processors |
---|
| 46 | !! |
---|
| 47 | !! ** Method : MPI all gatherv |
---|
| 48 | !! |
---|
| 49 | !! ** Action : This does only work for MPI. |
---|
| 50 | !! It does not work for SHMEM. |
---|
| 51 | !! |
---|
| 52 | !! References : http://www.mpi-forum.org |
---|
| 53 | !! |
---|
| 54 | !! History : |
---|
| 55 | !! ! 08-08 (K. Mogensen) Original code |
---|
| 56 | !!---------------------------------------------------------------------- |
---|
| 57 | |
---|
| 58 | !! * Arguments |
---|
| 59 | INTEGER, INTENT(IN) :: & |
---|
| 60 | & knoin, & |
---|
| 61 | & ksizeout |
---|
| 62 | REAL(wp), DIMENSION(knoin), INTENT(IN) :: & |
---|
| 63 | & pvalsin |
---|
| 64 | REAL(wp), DIMENSION(ksizeout), INTENT(OUT) :: & |
---|
| 65 | & pvalsout |
---|
| 66 | INTEGER, DIMENSION(jpnij), INTENT(OUT) :: & |
---|
| 67 | & kstartout, & |
---|
| 68 | & knoout |
---|
| 69 | |
---|
| 70 | !! * Local declarations |
---|
| 71 | INTEGER :: & |
---|
| 72 | & ierr |
---|
| 73 | #if defined key_mpp_mpi |
---|
| 74 | #include <mpif.h> |
---|
| 75 | INTEGER, DIMENSION(jpnij) :: & |
---|
| 76 | & idispl |
---|
| 77 | INTEGER :: & |
---|
| 78 | & ji |
---|
| 79 | !----------------------------------------------------------------------- |
---|
| 80 | ! Call the MPI library to get number of data per processor |
---|
| 81 | !----------------------------------------------------------------------- |
---|
| 82 | CALL mpi_allgather( knoin, 1, mpi_integer, & |
---|
| 83 | & knoout, 1, mpi_integer, & |
---|
| 84 | & mpi_comm_opa, ierr ) |
---|
| 85 | !----------------------------------------------------------------------- |
---|
| 86 | ! Compute starts of each processors contribution |
---|
| 87 | !----------------------------------------------------------------------- |
---|
| 88 | kstartout(1) = 0 |
---|
| 89 | DO ji = 2, jpnij |
---|
| 90 | kstartout(ji) = kstartout(ji-1) + knoout(ji-1) |
---|
| 91 | ENDDO |
---|
| 92 | !----------------------------------------------------------------------- |
---|
| 93 | ! Call the MPI library to do the gathering of the data |
---|
| 94 | !----------------------------------------------------------------------- |
---|
| 95 | CALL mpi_allgatherv( pvalsin, knoin, mpivar, & |
---|
| 96 | & pvalsout, knoout, kstartout, mpivar, & |
---|
| 97 | & mpi_comm_opa, ierr ) |
---|
| 98 | #elif defined key_mpp_shmem |
---|
| 99 | error "Only MPI support for MPP in NEMOVAR" |
---|
| 100 | #else |
---|
| 101 | !----------------------------------------------------------------------- |
---|
| 102 | ! For no-MPP just return input values |
---|
| 103 | !----------------------------------------------------------------------- |
---|
| 104 | pvalsout(1:knoin) = pvalsin(1:knoin) |
---|
| 105 | kstartout(1) = 0 |
---|
| 106 | knoout(1) = knoin |
---|
| 107 | |
---|
| 108 | #endif |
---|
| 109 | |
---|
| 110 | END SUBROUTINE mpp_allgatherv_real |
---|
| 111 | |
---|
| 112 | SUBROUTINE mpp_allgatherv_int( kvalsin, knoin, kvalsout, ksizeout, & |
---|
| 113 | & knoout, kstartout ) |
---|
| 114 | !!---------------------------------------------------------------------- |
---|
| 115 | !! *** ROUTINE mpp_allgatherv *** |
---|
| 116 | !! |
---|
| 117 | !! ** Purpose : Gather an integer array on all processors |
---|
| 118 | !! |
---|
| 119 | !! ** Method : MPI all gatherv |
---|
| 120 | !! |
---|
| 121 | !! ** Action : This does only work for MPI. |
---|
| 122 | !! It does not work for SHMEM. |
---|
| 123 | !! |
---|
| 124 | !! References : http://www.mpi-forum.org |
---|
| 125 | !! |
---|
| 126 | !! History : |
---|
| 127 | !! ! 06-07 (K. Mogensen) Original code |
---|
| 128 | !!---------------------------------------------------------------------- |
---|
| 129 | |
---|
| 130 | !! * Arguments |
---|
| 131 | INTEGER, INTENT(IN) :: & |
---|
| 132 | & knoin, & |
---|
| 133 | & ksizeout |
---|
| 134 | INTEGER, DIMENSION(knoin), INTENT(IN) :: & |
---|
| 135 | & kvalsin |
---|
| 136 | INTEGER, DIMENSION(ksizeout), INTENT(OUT) :: & |
---|
| 137 | & kvalsout |
---|
| 138 | INTEGER, DIMENSION(jpnij), INTENT(OUT) :: & |
---|
| 139 | & kstartout, & |
---|
| 140 | & knoout |
---|
| 141 | |
---|
| 142 | !! * Local declarations |
---|
| 143 | INTEGER :: & |
---|
| 144 | & ierr |
---|
| 145 | #if defined key_mpp_mpi |
---|
| 146 | #include <mpif.h> |
---|
| 147 | INTEGER, DIMENSION(jpnij) :: & |
---|
| 148 | & idispl |
---|
| 149 | INTEGER :: & |
---|
| 150 | & ji |
---|
| 151 | !----------------------------------------------------------------------- |
---|
| 152 | ! Call the MPI library to get number of data per processor |
---|
| 153 | !----------------------------------------------------------------------- |
---|
| 154 | CALL mpi_allgather( knoin, 1, mpi_integer, & |
---|
| 155 | & knoout, 1, mpi_integer, & |
---|
| 156 | & mpi_comm_opa, ierr ) |
---|
| 157 | !----------------------------------------------------------------------- |
---|
| 158 | ! Compute starts of each processors contribution |
---|
| 159 | !----------------------------------------------------------------------- |
---|
| 160 | kstartout(1) = 0 |
---|
| 161 | DO ji = 2, jpnij |
---|
| 162 | kstartout(ji) = kstartout(ji-1) + knoout(ji-1) |
---|
| 163 | ENDDO |
---|
| 164 | !----------------------------------------------------------------------- |
---|
| 165 | ! Call the MPI library to do the gathering of the data |
---|
| 166 | !----------------------------------------------------------------------- |
---|
| 167 | CALL mpi_allgatherv( kvalsin, knoin, mpi_integer, & |
---|
| 168 | & kvalsout, knoout, kstartout, mpi_integer, & |
---|
| 169 | & mpi_comm_opa, ierr ) |
---|
| 170 | #elif defined key_mpp_shmem |
---|
| 171 | error "Only MPI support for MPP in NEMOVAR" |
---|
| 172 | #else |
---|
| 173 | !----------------------------------------------------------------------- |
---|
| 174 | ! For no-MPP just return input values |
---|
| 175 | !----------------------------------------------------------------------- |
---|
| 176 | kvalsout(1:knoin) = kvalsin(1:knoin) |
---|
| 177 | kstartout(1) = 0 |
---|
| 178 | knoout(1) = knoin |
---|
| 179 | |
---|
| 180 | #endif |
---|
| 181 | |
---|
| 182 | END SUBROUTINE mpp_allgatherv_int |
---|
| 183 | |
---|
| 184 | END MODULE mppallgatherv |
---|