[1762] | 1 | MODULE pmc_general |
---|
| 2 | |
---|
| 3 | !--------------------------------------------------------------------------------! |
---|
| 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 | ! |
---|
| 17 | ! Copyright 1997-2015 Leibniz Universitaet Hannover |
---|
| 18 | !--------------------------------------------------------------------------------! |
---|
| 19 | ! |
---|
| 20 | ! Current revisions: |
---|
| 21 | ! ------------------ |
---|
| 22 | ! |
---|
[1787] | 23 | ! |
---|
[1762] | 24 | ! Former revisions: |
---|
| 25 | ! ----------------- |
---|
| 26 | ! $Id: pmc_general.f90 1787 2016-03-08 06:57:00Z raasch $ |
---|
| 27 | ! |
---|
[1787] | 28 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
| 29 | ! change in client-server data transfer: server now gets data from client |
---|
| 30 | ! instead that client put's it to the server |
---|
| 31 | ! |
---|
[1780] | 32 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 33 | ! PMC_MPI_REAL removed, dim_order removed from type arraydef, |
---|
| 34 | ! array management changed from linked list to sequential loop |
---|
| 35 | ! |
---|
[1767] | 36 | ! 1766 2016-02-29 08:37:15Z raasch |
---|
| 37 | ! +po_data in type arraydef |
---|
| 38 | ! |
---|
[1765] | 39 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
| 40 | ! cpp-statement added (nesting can only be used in parallel mode), |
---|
| 41 | ! all kinds given in PALM style |
---|
| 42 | ! |
---|
[1763] | 43 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 44 | ! Initial revision by K. Ketelsen |
---|
[1762] | 45 | ! |
---|
| 46 | ! Description: |
---|
| 47 | ! ------------ |
---|
| 48 | ! |
---|
| 49 | ! Structure definition and utilities of Palm Model Coupler |
---|
| 50 | !------------------------------------------------------------------------------! |
---|
| 51 | |
---|
[1764] | 52 | #if defined( __parallel ) |
---|
[1762] | 53 | use, intrinsic :: iso_c_binding |
---|
| 54 | |
---|
[1764] | 55 | USE kinds |
---|
| 56 | |
---|
| 57 | #if defined( __lc ) |
---|
| 58 | USE MPI |
---|
| 59 | #else |
---|
| 60 | INCLUDE "mpif.h" |
---|
| 61 | #endif |
---|
| 62 | |
---|
[1762] | 63 | IMPLICIT none |
---|
| 64 | PRIVATE |
---|
| 65 | SAVE |
---|
| 66 | |
---|
| 67 | ! return status |
---|
| 68 | INTEGER,parameter,PUBLIC :: PMC_STATUS_OK = 0 |
---|
| 69 | INTEGER,parameter,PUBLIC :: PMC_STATUS_ERROR = -1 |
---|
| 70 | INTEGER,parameter,PUBLIC :: PMC_DA_NAME_ERR = 10 |
---|
| 71 | |
---|
[1779] | 72 | INTEGER,parameter,PUBLIC :: PMC_MAX_ARRAY = 32 !Max Number of Array which can be coupled |
---|
[1762] | 73 | INTEGER,parameter,PUBLIC :: PMC_MAX_MODELL = 64 |
---|
| 74 | INTEGER,parameter,PUBLIC :: DA_Desclen = 8 |
---|
| 75 | INTEGER,parameter,PUBLIC :: DA_Namelen = 16 |
---|
| 76 | |
---|
| 77 | TYPE, PUBLIC :: xy_ind ! Pair of indices in horizontal plane |
---|
| 78 | INTEGER :: i |
---|
| 79 | INTEGER :: j |
---|
| 80 | END TYPE |
---|
| 81 | |
---|
| 82 | TYPE, PUBLIC :: ArrayDef |
---|
| 83 | INTEGER :: coupleIndex |
---|
| 84 | INTEGER :: NrDims ! Number of Dimensions |
---|
| 85 | INTEGER,DIMENSION(4) :: A_dim ! Size of dimensions |
---|
[1766] | 86 | TYPE(c_ptr) :: data ! Pointer of data in server space |
---|
| 87 | TYPE(c_ptr), DIMENSION(2) :: po_data ! Base Pointers, PMC_S_Set_Active_data_array sets active pointer |
---|
[1786] | 88 | INTEGER(idp) :: SendIndex ! index in Send Buffer |
---|
| 89 | INTEGER(idp) :: RecvIndex ! index in Receive Buffer |
---|
| 90 | INTEGER :: SendSize ! size in Send Buffer |
---|
| 91 | INTEGER :: RecvSize ! size in Receiver Buffer |
---|
[1762] | 92 | TYPE (c_ptr) :: SendBuf ! Pointer of Data in Send buffer |
---|
[1786] | 93 | TYPE (c_ptr) :: RecvBuf ! Pointer of Data in ReceiveS buffer |
---|
[1762] | 94 | CHARACTER(len=8) :: Name ! Name of Array |
---|
| 95 | |
---|
| 96 | Type(ArrayDef),POINTER :: next |
---|
| 97 | END TYPE ArrayDef |
---|
| 98 | |
---|
| 99 | TYPE (ArrayDef), PUBLIC, POINTER :: next; |
---|
| 100 | |
---|
| 101 | TYPE, PUBLIC :: PeDef |
---|
[1779] | 102 | INTEGER :: Nr_arrays=0 ! Number of arrays which will be transfered in this run |
---|
| 103 | INTEGER :: NrEle ! Number of Elemets, same for all arrays |
---|
| 104 | TYPE (xy_ind), POINTER,DIMENSION(:) :: locInd ! xy index local array for remote PE |
---|
| 105 | TYPE( ArrayDef), POINTER, DIMENSION(:) :: array_list ! List of Data Arrays to be transfered |
---|
[1762] | 106 | END TYPE PeDef |
---|
| 107 | |
---|
| 108 | TYPE, PUBLIC :: ClientDef |
---|
[1764] | 109 | INTEGER(idp) :: TotalBufferSize |
---|
[1762] | 110 | INTEGER :: model_comm ! Communicator of this model |
---|
| 111 | INTEGER :: inter_comm ! Inter communicator model and client |
---|
| 112 | INTEGER :: intra_comm ! Intra communicator model and client |
---|
| 113 | INTEGER :: model_rank ! Rank of this model |
---|
| 114 | INTEGER :: model_npes ! Number of PEs this model |
---|
| 115 | INTEGER :: inter_npes ! Number of PEs client model |
---|
| 116 | INTEGER :: intra_rank ! rank within intra_comm |
---|
[1786] | 117 | INTEGER :: win_server_client ! MPI RMA for preparing data on server AND client side |
---|
[1762] | 118 | TYPE (PeDef), DIMENSION(:), POINTER :: PEs ! List of all Client PEs |
---|
| 119 | END TYPE ClientDef |
---|
| 120 | |
---|
| 121 | TYPE, PUBLIC :: DA_NameDef ! Data Array Name Definition |
---|
| 122 | INTEGER :: couple_index ! Unique Number of Array |
---|
| 123 | CHARACTER(len=DA_Desclen) :: ServerDesc ! Server array description |
---|
| 124 | CHARACTER(len=DA_Namelen) :: NameOnServer ! Name of array within Server |
---|
| 125 | CHARACTER(len=DA_Desclen) :: ClientDesc ! Client array description |
---|
| 126 | CHARACTER(len=DA_Namelen) :: NameOnClient ! Name of array within Client |
---|
| 127 | END TYPE DA_NameDef |
---|
| 128 | |
---|
| 129 | INTERFACE PMC_G_SetName |
---|
| 130 | MODULE procedure PMC_G_SetName |
---|
| 131 | end INTERFACE PMC_G_SetName |
---|
| 132 | |
---|
| 133 | INTERFACE PMC_sort |
---|
| 134 | MODULE procedure sort_2d_i |
---|
| 135 | end INTERFACE PMC_sort |
---|
| 136 | |
---|
[1779] | 137 | PUBLIC PMC_G_SetName, PMC_sort |
---|
[1762] | 138 | |
---|
| 139 | |
---|
| 140 | CONTAINS |
---|
| 141 | SUBROUTINE PMC_G_SetName (myClient, couple_index, aName) |
---|
| 142 | IMPLICIT none |
---|
| 143 | |
---|
| 144 | TYPE(ClientDef),INTENT(INOUT) :: myClient |
---|
| 145 | INTEGER,INTENT(IN) :: couple_index |
---|
| 146 | CHARACTER(LEN=*) :: aName |
---|
| 147 | |
---|
| 148 | INTEGER :: i |
---|
| 149 | TYPE(ArrayDef),POINTER :: ar |
---|
| 150 | TYPE(PeDef),POINTER :: aPE |
---|
| 151 | |
---|
[1779] | 152 | ! |
---|
| 153 | !-- Assign array to next free index in array_list. |
---|
| 154 | !-- Set name of array in ArrayDef structure |
---|
[1762] | 155 | do i=1,myClient%inter_npes |
---|
| 156 | aPE => myClient%PEs(i) |
---|
[1779] | 157 | aPE%Nr_arrays = aPE%Nr_arrays+1 |
---|
| 158 | aPE%array_list(aPE%Nr_arrays)%name = aName |
---|
| 159 | aPE%array_list(aPE%Nr_arrays)%coupleIndex = couple_index |
---|
[1762] | 160 | end do |
---|
| 161 | |
---|
| 162 | return |
---|
| 163 | end SUBROUTINE PMC_G_SetName |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | SUBROUTINE sort_2d_i (array,sort_ind) |
---|
| 167 | IMPLICIT none |
---|
| 168 | INTEGER,DIMENSION(:,:),INTENT(INOUT) :: array |
---|
| 169 | INTEGER,INTENT(IN) :: sort_ind |
---|
| 170 | |
---|
| 171 | !-- local Variables |
---|
| 172 | INTEGER :: i,j,n |
---|
| 173 | INTEGER,DIMENSION(size(array,1)) :: tmp |
---|
| 174 | |
---|
| 175 | n = size(array,2) |
---|
| 176 | do j=1,n-1 |
---|
| 177 | do i=j+1,n |
---|
| 178 | if(array(sort_ind,i) < array(sort_ind,j) ) then |
---|
| 179 | tmp = array(:,i) |
---|
| 180 | array(:,i) = array(:,j) |
---|
| 181 | array(:,j) = tmp |
---|
| 182 | end if |
---|
| 183 | end do |
---|
| 184 | end do |
---|
| 185 | |
---|
| 186 | return |
---|
| 187 | END SUBROUTINE sort_2d_i |
---|
| 188 | |
---|
[1764] | 189 | #endif |
---|
[1762] | 190 | end MODULE pmc_general |
---|