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