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