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