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