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