[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 | ! |
---|
[4360] | 18 | ! Copyright 1997-2020 Leibniz Universitaet Hannover |
---|
[2000] | 19 | !------------------------------------------------------------------------------! |
---|
[1762] | 20 | ! |
---|
| 21 | ! Current revisions: |
---|
| 22 | ! ------------------ |
---|
[4629] | 23 | ! |
---|
| 24 | ! |
---|
[1762] | 25 | ! Former revisions: |
---|
| 26 | ! ----------------- |
---|
| 27 | ! $Id: pmc_general_mod.f90 4629 2020-07-29 09:37:56Z suehring $ |
---|
[4629] | 28 | ! support for MPI Fortran77 interface (mpif.h) removed |
---|
| 29 | ! |
---|
| 30 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 31 | ! Corrected "Former revisions" section |
---|
[3945] | 32 | ! |
---|
[4182] | 33 | ! 3945 2019-05-02 11:29:27Z raasch |
---|
| 34 | ! |
---|
[3945] | 35 | ! 2019-04-24 17:31:34Z suehring |
---|
[3943] | 36 | ! Increase character length so that also chemistry variable names fully fit |
---|
[3945] | 37 | ! |
---|
| 38 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3592] | 39 | ! Determine number of coupled arrays dynamically. |
---|
| 40 | ! |
---|
[4182] | 41 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 42 | ! Initial revision by K. Ketelsen |
---|
[2716] | 43 | ! |
---|
[1762] | 44 | ! Description: |
---|
| 45 | ! ------------ |
---|
| 46 | ! |
---|
| 47 | ! Structure definition and utilities of Palm Model Coupler |
---|
| 48 | !------------------------------------------------------------------------------! |
---|
| 49 | |
---|
[1764] | 50 | #if defined( __parallel ) |
---|
[1900] | 51 | USE, INTRINSIC :: ISO_C_BINDING |
---|
[1762] | 52 | |
---|
[1900] | 53 | USE kinds |
---|
[1764] | 54 | |
---|
| 55 | USE MPI |
---|
| 56 | |
---|
[1900] | 57 | IMPLICIT NONE |
---|
[1762] | 58 | |
---|
[2841] | 59 | |
---|
[1900] | 60 | PRIVATE |
---|
| 61 | SAVE |
---|
[1762] | 62 | |
---|
[3592] | 63 | INTEGER(iwp), PUBLIC :: pmc_max_array !< max # of arrays which can be coupled - will be determined dynamically in pmc_interface |
---|
| 64 | |
---|
[2801] | 65 | INTEGER(iwp), PARAMETER, PUBLIC :: da_desclen = 8 !< |
---|
| 66 | INTEGER(iwp), PARAMETER, PUBLIC :: da_namelen = 16 !< |
---|
| 67 | INTEGER(iwp), PARAMETER, PUBLIC :: pmc_da_name_err = 10 !< |
---|
| 68 | INTEGER(iwp), PARAMETER, PUBLIC :: pmc_max_models = 64 !< |
---|
| 69 | INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_ok = 0 !< |
---|
| 70 | INTEGER(iwp), PARAMETER, PUBLIC :: pmc_status_error = -1 !< |
---|
[1762] | 71 | |
---|
| 72 | |
---|
[1900] | 73 | TYPE, PUBLIC :: xy_ind !< pair of indices in horizontal plane |
---|
[2801] | 74 | INTEGER(iwp) :: i |
---|
| 75 | INTEGER(iwp) :: j |
---|
[1900] | 76 | END TYPE |
---|
[1762] | 77 | |
---|
[1900] | 78 | TYPE, PUBLIC :: arraydef |
---|
[2801] | 79 | INTEGER(iwp) :: coupleindex !< |
---|
| 80 | INTEGER(iwp) :: nrdims !< number of dimensions |
---|
| 81 | INTEGER(iwp) :: dimkey !< key for NR dimensions and array type |
---|
| 82 | INTEGER(iwp), DIMENSION(4) :: a_dim !< size of dimensions |
---|
[1933] | 83 | TYPE(C_PTR) :: data !< pointer of data in parent space |
---|
[1900] | 84 | TYPE(C_PTR), DIMENSION(2) :: po_data !< base pointers, |
---|
| 85 | !< pmc_s_set_active_data_array |
---|
| 86 | !< sets active pointer |
---|
| 87 | INTEGER(idp) :: SendIndex !< index in send buffer |
---|
| 88 | INTEGER(idp) :: RecvIndex !< index in receive buffer |
---|
[2801] | 89 | INTEGER(iwp) :: SendSize !< size in send buffer |
---|
| 90 | INTEGER(iwp) :: RecvSize !< size in receive buffer |
---|
[1900] | 91 | TYPE(C_PTR) :: SendBuf !< data pointer in send buffer |
---|
| 92 | TYPE(C_PTR) :: RecvBuf !< data pointer in receive buffer |
---|
[3932] | 93 | CHARACTER(LEN=da_namelen) :: Name !< name of array |
---|
[1900] | 94 | TYPE(arraydef), POINTER :: next |
---|
| 95 | END TYPE arraydef |
---|
[1762] | 96 | |
---|
[1900] | 97 | TYPE(arraydef), PUBLIC, POINTER :: next |
---|
[1762] | 98 | |
---|
[1900] | 99 | TYPE, PUBLIC :: pedef |
---|
[2801] | 100 | INTEGER(iwp) :: nr_arrays = 0 !< number of arrays which will be transfered |
---|
| 101 | INTEGER(iwp) :: nrele !< number of elements, same for all arrays |
---|
[1900] | 102 | TYPE(xy_ind), POINTER, DIMENSION(:) :: locInd !< xy index local array for remote PE |
---|
| 103 | TYPE(arraydef), POINTER, DIMENSION(:) :: array_list !< list of data arrays to be transfered |
---|
| 104 | END TYPE pedef |
---|
[1762] | 105 | |
---|
[1933] | 106 | TYPE, PUBLIC :: childdef |
---|
[1900] | 107 | INTEGER(idp) :: totalbuffersize !< |
---|
[2801] | 108 | INTEGER(iwp) :: model_comm !< communicator of this model |
---|
| 109 | INTEGER(iwp) :: inter_comm !< inter communicator model and child |
---|
| 110 | INTEGER(iwp) :: intra_comm !< intra communicator model and child |
---|
| 111 | INTEGER(iwp) :: model_rank !< rank of this model |
---|
| 112 | INTEGER(iwp) :: model_npes !< number of PEs this model |
---|
| 113 | INTEGER(iwp) :: inter_npes !< number of PEs child model |
---|
| 114 | INTEGER(iwp) :: intra_rank !< rank within intra_comm |
---|
| 115 | INTEGER(iwp) :: win_parent_child !< MPI RMA for preparing data on parent AND child side |
---|
[1933] | 116 | TYPE(pedef), DIMENSION(:), POINTER :: pes !< list of all child PEs |
---|
| 117 | END TYPE childdef |
---|
[1762] | 118 | |
---|
[1900] | 119 | TYPE, PUBLIC :: da_namedef !< data array name definition |
---|
[2801] | 120 | INTEGER(iwp) :: couple_index !< unique number of array |
---|
[1933] | 121 | CHARACTER(LEN=da_desclen) :: parentdesc !< parent array description |
---|
| 122 | CHARACTER(LEN=da_namelen) :: nameonparent !< name of array within parent |
---|
| 123 | CHARACTER(LEN=da_desclen) :: childdesc !< child array description |
---|
| 124 | CHARACTER(LEN=da_namelen) :: nameonchild !< name of array within child |
---|
[1900] | 125 | END TYPE da_namedef |
---|
[1762] | 126 | |
---|
[1900] | 127 | INTERFACE pmc_g_setname |
---|
| 128 | MODULE PROCEDURE pmc_g_setname |
---|
| 129 | END INTERFACE pmc_g_setname |
---|
[1762] | 130 | |
---|
[1900] | 131 | INTERFACE pmc_sort |
---|
| 132 | MODULE PROCEDURE sort_2d_i |
---|
| 133 | END INTERFACE pmc_sort |
---|
[1762] | 134 | |
---|
[1900] | 135 | PUBLIC pmc_g_setname, pmc_sort |
---|
[1762] | 136 | |
---|
| 137 | CONTAINS |
---|
| 138 | |
---|
[2599] | 139 | |
---|
| 140 | |
---|
[1933] | 141 | SUBROUTINE pmc_g_setname( mychild, couple_index, aname ) |
---|
[1762] | 142 | |
---|
[1900] | 143 | IMPLICIT NONE |
---|
[1762] | 144 | |
---|
[2801] | 145 | CHARACTER(LEN=*) :: aname !< |
---|
| 146 | INTEGER(iwp), INTENT(IN) :: couple_index !< |
---|
| 147 | TYPE(childdef), INTENT(INOUT) :: mychild !< |
---|
[1900] | 148 | |
---|
[2801] | 149 | INTEGER(iwp) :: i !< |
---|
[1900] | 150 | |
---|
| 151 | TYPE(pedef), POINTER :: ape !< |
---|
| 152 | |
---|
[1779] | 153 | ! |
---|
[1900] | 154 | !-- Assign array to next free index in array list. |
---|
| 155 | !-- Set name of array in arraydef structure |
---|
[1933] | 156 | DO i = 1, mychild%inter_npes |
---|
| 157 | ape => mychild%pes(i) |
---|
[1900] | 158 | ape%nr_arrays = ape%nr_arrays + 1 |
---|
| 159 | ape%array_list(ape%nr_arrays)%name = aname |
---|
| 160 | ape%array_list(ape%nr_arrays)%coupleindex = couple_index |
---|
| 161 | ENDDO |
---|
[1762] | 162 | |
---|
[1900] | 163 | END SUBROUTINE pmc_g_setname |
---|
[1762] | 164 | |
---|
| 165 | |
---|
| 166 | |
---|
[1900] | 167 | SUBROUTINE sort_2d_i( array, sort_ind ) |
---|
[1762] | 168 | |
---|
[1900] | 169 | IMPLICIT NONE |
---|
| 170 | |
---|
[2801] | 171 | INTEGER(iwp), INTENT(IN) :: sort_ind |
---|
| 172 | INTEGER(iwp), DIMENSION(:,:), INTENT(INOUT) :: array |
---|
[1900] | 173 | |
---|
[2801] | 174 | INTEGER(iwp) :: i !< |
---|
| 175 | INTEGER(iwp) :: j !< |
---|
| 176 | INTEGER(iwp) :: n !< |
---|
[1900] | 177 | |
---|
[2801] | 178 | INTEGER(iwp), DIMENSION(SIZE(array,1)) :: tmp !< |
---|
[1900] | 179 | |
---|
| 180 | n = SIZE(array,2) |
---|
| 181 | DO j = 1, n-1 |
---|
| 182 | DO i = j+1, n |
---|
| 183 | IF ( array(sort_ind,i) < array(sort_ind,j) ) THEN |
---|
| 184 | tmp = array(:,i) |
---|
| 185 | array(:,i) = array(:,j) |
---|
| 186 | array(:,j) = tmp |
---|
| 187 | ENDIF |
---|
| 188 | ENDDO |
---|
| 189 | ENDDO |
---|
| 190 | |
---|
| 191 | END SUBROUTINE sort_2d_i |
---|
| 192 | |
---|
[1764] | 193 | #endif |
---|
[1900] | 194 | END MODULE pmc_general |
---|