[1900] | 1 | MODULE pmc_general |
---|
[1762] | 2 | |
---|
[2000] | 3 | !------------------------------------------------------------------------------! |
---|
[2696] | 4 | ! This file is part of the PALM model system. |
---|
[1762] | 5 | ! |
---|
[2000] | 6 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
| 7 | ! terms of the GNU General Public License as published by the Free Software |
---|
| 8 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
| 9 | ! version. |
---|
[1762] | 10 | ! |
---|
| 11 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
| 12 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
| 13 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
| 14 | ! |
---|
| 15 | ! You should have received a copy of the GNU General Public License along with |
---|
| 16 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
| 17 | ! |
---|
[2718] | 18 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 19 | !------------------------------------------------------------------------------! |
---|
[1762] | 20 | ! |
---|
| 21 | ! Current revisions: |
---|
| 22 | ! ------------------ |
---|
[1933] | 23 | ! |
---|
[2001] | 24 | ! |
---|
[1762] | 25 | ! Former revisions: |
---|
| 26 | ! ----------------- |
---|
| 27 | ! $Id: pmc_general_mod.f90 2718 2018-01-02 08:49:38Z gronemeier $ |
---|
[2716] | 28 | ! Corrected "Former revisions" section |
---|
| 29 | ! |
---|
| 30 | ! 2696 2017-12-14 17:12:51Z kanani |
---|
| 31 | ! Change in file header (GPL part) |
---|
| 32 | ! |
---|
| 33 | ! 2599 2017-11-01 13:18:45Z hellstea |
---|
[2599] | 34 | ! Some cleanup and commenting improvements only. |
---|
| 35 | ! |
---|
| 36 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1762] | 37 | ! |
---|
[2001] | 38 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 39 | ! Forced header and separation lines into 80 columns |
---|
| 40 | ! |
---|
[1933] | 41 | ! 1901 2016-05-04 15:39:38Z raasch |
---|
| 42 | ! Code clean up. The words server/client changed to parent/child. |
---|
| 43 | ! |
---|
[1901] | 44 | ! 1900 2016-05-04 15:27:53Z raasch |
---|
| 45 | ! re-formatted to match PALM style, file renamed again |
---|
| 46 | ! |
---|
[1809] | 47 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 48 | ! MPI module used by default on all machines |
---|
| 49 | ! |
---|
[1787] | 50 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
[1933] | 51 | ! change in child-parent data transfer: parent now gets data from child |
---|
| 52 | ! instead of that child puts it to the parent |
---|
[1787] | 53 | ! |
---|
[1780] | 54 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 55 | ! PMC_MPI_REAL removed, dim_order removed from type arraydef, |
---|
| 56 | ! array management changed from linked list to sequential loop |
---|
| 57 | ! |
---|
[1767] | 58 | ! 1766 2016-02-29 08:37:15Z raasch |
---|
| 59 | ! +po_data in type arraydef |
---|
| 60 | ! |
---|
[1765] | 61 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
| 62 | ! cpp-statement added (nesting can only be used in parallel mode), |
---|
| 63 | ! all kinds given in PALM style |
---|
| 64 | ! |
---|
[1763] | 65 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 66 | ! Initial revision by K. Ketelsen |
---|
[1762] | 67 | ! |
---|
| 68 | ! Description: |
---|
| 69 | ! ------------ |
---|
| 70 | ! |
---|
| 71 | ! Structure definition and utilities of Palm Model Coupler |
---|
| 72 | !------------------------------------------------------------------------------! |
---|
| 73 | |
---|
[1764] | 74 | #if defined( __parallel ) |
---|
[1900] | 75 | USE, INTRINSIC :: ISO_C_BINDING |
---|
[1762] | 76 | |
---|
[1900] | 77 | USE kinds |
---|
[1764] | 78 | |
---|
[1808] | 79 | #if defined( __mpifh ) |
---|
| 80 | INCLUDE "mpif.h" |
---|
| 81 | #else |
---|
[1764] | 82 | USE MPI |
---|
| 83 | #endif |
---|
| 84 | |
---|
[1900] | 85 | IMPLICIT NONE |
---|
[1762] | 86 | |
---|
[1900] | 87 | PRIVATE |
---|
| 88 | SAVE |
---|
[1762] | 89 | |
---|
[1900] | 90 | INTEGER, PARAMETER, PUBLIC :: da_desclen = 8 !< |
---|
| 91 | INTEGER, PARAMETER, PUBLIC :: da_namelen = 16 !< |
---|
| 92 | INTEGER, PARAMETER, PUBLIC :: pmc_da_name_err = 10 !< |
---|
| 93 | INTEGER, PARAMETER, PUBLIC :: pmc_max_array = 32 !< max # of arrays which can be coupled |
---|
| 94 | INTEGER, PARAMETER, PUBLIC :: pmc_max_models = 64 !< |
---|
| 95 | INTEGER, PARAMETER, PUBLIC :: pmc_status_ok = 0 !< |
---|
| 96 | INTEGER, PARAMETER, PUBLIC :: pmc_status_error = -1 !< |
---|
[1762] | 97 | |
---|
| 98 | |
---|
[1900] | 99 | TYPE, PUBLIC :: xy_ind !< pair of indices in horizontal plane |
---|
| 100 | INTEGER :: i |
---|
| 101 | INTEGER :: j |
---|
| 102 | END TYPE |
---|
[1762] | 103 | |
---|
[1900] | 104 | TYPE, PUBLIC :: arraydef |
---|
| 105 | INTEGER :: coupleindex !< |
---|
| 106 | INTEGER :: nrdims !< number of dimensions |
---|
| 107 | INTEGER, DIMENSION(4) :: a_dim !< size of dimensions |
---|
[1933] | 108 | TYPE(C_PTR) :: data !< pointer of data in parent space |
---|
[1900] | 109 | TYPE(C_PTR), DIMENSION(2) :: po_data !< base pointers, |
---|
| 110 | !< pmc_s_set_active_data_array |
---|
| 111 | !< sets active pointer |
---|
| 112 | INTEGER(idp) :: SendIndex !< index in send buffer |
---|
| 113 | INTEGER(idp) :: RecvIndex !< index in receive buffer |
---|
| 114 | INTEGER :: SendSize !< size in send buffer |
---|
| 115 | INTEGER :: RecvSize !< size in receive buffer |
---|
| 116 | TYPE(C_PTR) :: SendBuf !< data pointer in send buffer |
---|
| 117 | TYPE(C_PTR) :: RecvBuf !< data pointer in receive buffer |
---|
| 118 | CHARACTER(LEN=8) :: Name !< name of array |
---|
| 119 | TYPE(arraydef), POINTER :: next |
---|
| 120 | END TYPE arraydef |
---|
[1762] | 121 | |
---|
[1900] | 122 | TYPE(arraydef), PUBLIC, POINTER :: next |
---|
[1762] | 123 | |
---|
[1900] | 124 | TYPE, PUBLIC :: pedef |
---|
| 125 | INTEGER :: nr_arrays = 0 !< number of arrays which will be transfered |
---|
| 126 | INTEGER :: nrele !< number of elements, same for all arrays |
---|
| 127 | TYPE(xy_ind), POINTER, DIMENSION(:) :: locInd !< xy index local array for remote PE |
---|
| 128 | TYPE(arraydef), POINTER, DIMENSION(:) :: array_list !< list of data arrays to be transfered |
---|
| 129 | END TYPE pedef |
---|
[1762] | 130 | |
---|
[1933] | 131 | TYPE, PUBLIC :: childdef |
---|
[1900] | 132 | INTEGER(idp) :: totalbuffersize !< |
---|
| 133 | INTEGER :: model_comm !< communicator of this model |
---|
[1933] | 134 | INTEGER :: inter_comm !< inter communicator model and child |
---|
| 135 | INTEGER :: intra_comm !< intra communicator model and child |
---|
[1900] | 136 | INTEGER :: model_rank !< rank of this model |
---|
| 137 | INTEGER :: model_npes !< number of PEs this model |
---|
[1933] | 138 | INTEGER :: inter_npes !< number of PEs child model |
---|
[1900] | 139 | INTEGER :: intra_rank !< rank within intra_comm |
---|
[1933] | 140 | INTEGER :: win_parent_child !< MPI RMA for preparing data on parent AND child side |
---|
| 141 | TYPE(pedef), DIMENSION(:), POINTER :: pes !< list of all child PEs |
---|
| 142 | END TYPE childdef |
---|
[1762] | 143 | |
---|
[1900] | 144 | TYPE, PUBLIC :: da_namedef !< data array name definition |
---|
| 145 | INTEGER :: couple_index !< unique number of array |
---|
[1933] | 146 | CHARACTER(LEN=da_desclen) :: parentdesc !< parent array description |
---|
| 147 | CHARACTER(LEN=da_namelen) :: nameonparent !< name of array within parent |
---|
| 148 | CHARACTER(LEN=da_desclen) :: childdesc !< child array description |
---|
| 149 | CHARACTER(LEN=da_namelen) :: nameonchild !< name of array within child |
---|
[1900] | 150 | END TYPE da_namedef |
---|
[1762] | 151 | |
---|
[1900] | 152 | INTERFACE pmc_g_setname |
---|
| 153 | MODULE PROCEDURE pmc_g_setname |
---|
| 154 | END INTERFACE pmc_g_setname |
---|
[1762] | 155 | |
---|
[1900] | 156 | INTERFACE pmc_sort |
---|
| 157 | MODULE PROCEDURE sort_2d_i |
---|
| 158 | END INTERFACE pmc_sort |
---|
[1762] | 159 | |
---|
[1900] | 160 | PUBLIC pmc_g_setname, pmc_sort |
---|
[1762] | 161 | |
---|
| 162 | CONTAINS |
---|
| 163 | |
---|
[2599] | 164 | |
---|
| 165 | |
---|
[1933] | 166 | SUBROUTINE pmc_g_setname( mychild, couple_index, aname ) |
---|
[1762] | 167 | |
---|
[1900] | 168 | IMPLICIT NONE |
---|
[1762] | 169 | |
---|
[1900] | 170 | CHARACTER(LEN=*) :: aname !< |
---|
| 171 | INTEGER, INTENT(IN) :: couple_index !< |
---|
[1933] | 172 | TYPE(childdef), INTENT(INOUT) :: mychild !< |
---|
[1900] | 173 | |
---|
| 174 | INTEGER :: i !< |
---|
| 175 | |
---|
| 176 | TYPE(arraydef), POINTER :: ar !< |
---|
| 177 | TYPE(pedef), POINTER :: ape !< |
---|
| 178 | |
---|
[1779] | 179 | ! |
---|
[1900] | 180 | !-- Assign array to next free index in array list. |
---|
| 181 | !-- Set name of array in arraydef structure |
---|
[1933] | 182 | DO i = 1, mychild%inter_npes |
---|
| 183 | ape => mychild%pes(i) |
---|
[1900] | 184 | ape%nr_arrays = ape%nr_arrays + 1 |
---|
| 185 | ape%array_list(ape%nr_arrays)%name = aname |
---|
| 186 | ape%array_list(ape%nr_arrays)%coupleindex = couple_index |
---|
| 187 | ENDDO |
---|
[1762] | 188 | |
---|
[1900] | 189 | END SUBROUTINE pmc_g_setname |
---|
[1762] | 190 | |
---|
| 191 | |
---|
| 192 | |
---|
[1900] | 193 | SUBROUTINE sort_2d_i( array, sort_ind ) |
---|
[1762] | 194 | |
---|
[1900] | 195 | IMPLICIT NONE |
---|
| 196 | |
---|
| 197 | INTEGER, INTENT(IN) :: sort_ind |
---|
| 198 | INTEGER, DIMENSION(:,:), INTENT(INOUT) :: array |
---|
| 199 | |
---|
| 200 | INTEGER :: i !< |
---|
| 201 | INTEGER :: j !< |
---|
| 202 | INTEGER :: n !< |
---|
| 203 | |
---|
| 204 | INTEGER, DIMENSION(SIZE(array,1)) :: tmp !< |
---|
| 205 | |
---|
| 206 | n = SIZE(array,2) |
---|
| 207 | DO j = 1, n-1 |
---|
| 208 | DO i = j+1, n |
---|
| 209 | IF ( array(sort_ind,i) < array(sort_ind,j) ) THEN |
---|
| 210 | tmp = array(:,i) |
---|
| 211 | array(:,i) = array(:,j) |
---|
| 212 | array(:,j) = tmp |
---|
| 213 | ENDIF |
---|
| 214 | ENDDO |
---|
| 215 | ENDDO |
---|
| 216 | |
---|
| 217 | END SUBROUTINE sort_2d_i |
---|
| 218 | |
---|
[1764] | 219 | #endif |
---|
[1900] | 220 | END MODULE pmc_general |
---|