[1933] | 1 | MODULE pmc_parent |
---|
[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 | ! |
---|
[2718] | 18 | ! Copyright 1997-2018 Leibniz Universitaet Hannover |
---|
[2000] | 19 | !------------------------------------------------------------------------------! |
---|
[1762] | 20 | ! |
---|
| 21 | ! Current revisions: |
---|
| 22 | ! ------------------ |
---|
[1834] | 23 | ! |
---|
[2001] | 24 | ! |
---|
[1762] | 25 | ! Former revisions: |
---|
| 26 | ! ----------------- |
---|
| 27 | ! $Id: pmc_parent_mod.f90 2841 2018-02-27 15:02:57Z scharf $ |
---|
[2841] | 28 | ! Bugfix: wrong placement of include 'mpif.h' corrected |
---|
| 29 | ! |
---|
| 30 | ! 2809 2018-02-15 09:55:58Z schwenkel |
---|
[2809] | 31 | ! Bugfix for gfortran: Replace the function C_SIZEOF with STORAGE_SIZE |
---|
| 32 | ! |
---|
| 33 | ! 2801 2018-02-14 16:01:55Z thiele |
---|
[2801] | 34 | ! Introduce particle transfer in nested models. |
---|
| 35 | ! |
---|
| 36 | ! 2718 2018-01-02 08:49:38Z maronga |
---|
[2716] | 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 |
---|
[2599] | 43 | ! Some cleanup and commenting improvements only. |
---|
| 44 | ! |
---|
| 45 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1762] | 46 | ! |
---|
[2001] | 47 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 48 | ! Forced header and separation lines into 80 columns |
---|
| 49 | ! |
---|
[1939] | 50 | ! 1938 2016-06-13 15:26:05Z hellstea |
---|
| 51 | ! Minor clean up. |
---|
| 52 | ! |
---|
[1933] | 53 | ! 1901 2016-05-04 15:39:38Z raasch |
---|
| 54 | ! Module renamed. Code clean up. The words server/client changed to parent/child. |
---|
| 55 | ! |
---|
[1901] | 56 | ! 1900 2016-05-04 15:27:53Z raasch |
---|
| 57 | ! re-formatted to match PALM style |
---|
| 58 | ! |
---|
[1851] | 59 | ! 1850 2016-04-08 13:29:27Z maronga |
---|
| 60 | ! Module renamed |
---|
| 61 | ! |
---|
| 62 | ! |
---|
[1834] | 63 | ! 1833 2016-04-07 14:23:03Z raasch |
---|
| 64 | ! gfortran requires pointer attributes for some array declarations, |
---|
| 65 | ! long line wrapped |
---|
| 66 | ! |
---|
[1809] | 67 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 68 | ! MPI module used by default on all machines |
---|
| 69 | ! |
---|
[1798] | 70 | ! 1797 2016-03-21 16:50:28Z raasch |
---|
| 71 | ! introduction of different datatransfer modes |
---|
| 72 | ! |
---|
[1792] | 73 | ! 1791 2016-03-11 10:41:25Z raasch |
---|
| 74 | ! Debug write-statements commented out |
---|
| 75 | ! |
---|
[1787] | 76 | ! 1786 2016-03-08 05:49:27Z raasch |
---|
[1933] | 77 | ! change in child-parent data transfer: parent now gets data from child |
---|
| 78 | ! instead that child put's it to the parent |
---|
[1787] | 79 | ! |
---|
[1780] | 80 | ! 1779 2016-03-03 08:01:28Z raasch |
---|
| 81 | ! kind=dp replaced by wp, |
---|
| 82 | ! error messages removed or changed to PALM style, dim_order removed |
---|
| 83 | ! array management changed from linked list to sequential loop |
---|
| 84 | ! |
---|
[1767] | 85 | ! 1766 2016-02-29 08:37:15Z raasch |
---|
| 86 | ! modifications to allow for using PALM's pointer version |
---|
| 87 | ! +new routine pmc_s_set_active_data_array |
---|
| 88 | ! |
---|
[1765] | 89 | ! 1764 2016-02-28 12:45:19Z raasch |
---|
| 90 | ! cpp-statement added (nesting can only be used in parallel mode) |
---|
| 91 | ! |
---|
[1763] | 92 | ! 1762 2016-02-25 12:31:13Z hellstea |
---|
| 93 | ! Initial revision by K. Ketelsen |
---|
[1762] | 94 | ! |
---|
| 95 | ! Description: |
---|
| 96 | ! ------------ |
---|
| 97 | ! |
---|
[1933] | 98 | ! Parent part of Palm Model Coupler |
---|
[2801] | 99 | !------------------------------------------------------------------------------! |
---|
[1762] | 100 | |
---|
[1764] | 101 | #if defined( __parallel ) |
---|
[1900] | 102 | USE, INTRINSIC :: ISO_C_BINDING |
---|
[1762] | 103 | |
---|
[2841] | 104 | #if !defined( __mpifh ) |
---|
[1764] | 105 | USE MPI |
---|
| 106 | #endif |
---|
[1900] | 107 | USE kinds |
---|
[2801] | 108 | USE pmc_general, & |
---|
| 109 | ONLY: arraydef, childdef, da_namedef, da_namelen, pedef, & |
---|
[1900] | 110 | pmc_g_setname, pmc_max_array, pmc_max_models, pmc_sort |
---|
[1762] | 111 | |
---|
[2801] | 112 | USE pmc_handle_communicator, & |
---|
| 113 | ONLY: m_model_comm,m_model_rank,m_model_npes, m_to_child_comm, & |
---|
[1933] | 114 | m_world_rank, pmc_parent_for_child |
---|
[1900] | 115 | |
---|
[2801] | 116 | USE pmc_mpi_wrapper, & |
---|
[1900] | 117 | ONLY: pmc_alloc_mem, pmc_bcast, pmc_time |
---|
| 118 | |
---|
| 119 | IMPLICIT NONE |
---|
| 120 | |
---|
[2841] | 121 | #if defined( __mpifh ) |
---|
| 122 | INCLUDE "mpif.h" |
---|
| 123 | #endif |
---|
| 124 | |
---|
[1762] | 125 | PRIVATE |
---|
| 126 | SAVE |
---|
| 127 | |
---|
[1933] | 128 | TYPE childindexdef |
---|
[1900] | 129 | INTEGER :: nrpoints !< |
---|
| 130 | INTEGER, DIMENSION(:,:), ALLOCATABLE :: index_list_2d !< |
---|
[1933] | 131 | END TYPE childindexdef |
---|
[1762] | 132 | |
---|
[2801] | 133 | TYPE(childdef), DIMENSION(pmc_max_models),PUBLIC :: children !< |
---|
| 134 | TYPE(childindexdef), DIMENSION(pmc_max_models) :: indchildren !< |
---|
[1762] | 135 | |
---|
[1900] | 136 | INTEGER :: next_array_in_list = 0 !< |
---|
[1779] | 137 | |
---|
[1762] | 138 | |
---|
[1933] | 139 | PUBLIC pmc_parent_for_child |
---|
[1762] | 140 | |
---|
| 141 | |
---|
[1933] | 142 | INTERFACE pmc_parentinit |
---|
| 143 | MODULE PROCEDURE pmc_parentinit |
---|
| 144 | END INTERFACE pmc_parentinit |
---|
[1779] | 145 | |
---|
[1900] | 146 | INTERFACE pmc_s_set_2d_index_list |
---|
| 147 | MODULE PROCEDURE pmc_s_set_2d_index_list |
---|
| 148 | END INTERFACE pmc_s_set_2d_index_list |
---|
[1762] | 149 | |
---|
[1900] | 150 | INTERFACE pmc_s_clear_next_array_list |
---|
| 151 | MODULE PROCEDURE pmc_s_clear_next_array_list |
---|
| 152 | END INTERFACE pmc_s_clear_next_array_list |
---|
[1762] | 153 | |
---|
[1900] | 154 | INTERFACE pmc_s_getnextarray |
---|
| 155 | MODULE PROCEDURE pmc_s_getnextarray |
---|
| 156 | END INTERFACE pmc_s_getnextarray |
---|
[1762] | 157 | |
---|
[1900] | 158 | INTERFACE pmc_s_set_dataarray |
---|
| 159 | MODULE PROCEDURE pmc_s_set_dataarray_2d |
---|
| 160 | MODULE PROCEDURE pmc_s_set_dataarray_3d |
---|
[2801] | 161 | MODULE PROCEDURE pmc_s_set_dataarray_ip2d |
---|
[1900] | 162 | END INTERFACE pmc_s_set_dataarray |
---|
[1762] | 163 | |
---|
[1900] | 164 | INTERFACE pmc_s_setind_and_allocmem |
---|
| 165 | MODULE PROCEDURE pmc_s_setind_and_allocmem |
---|
| 166 | END INTERFACE pmc_s_setind_and_allocmem |
---|
[1762] | 167 | |
---|
[1900] | 168 | INTERFACE pmc_s_fillbuffer |
---|
| 169 | MODULE PROCEDURE pmc_s_fillbuffer |
---|
| 170 | END INTERFACE pmc_s_fillbuffer |
---|
[1766] | 171 | |
---|
[1900] | 172 | INTERFACE pmc_s_getdata_from_buffer |
---|
| 173 | MODULE PROCEDURE pmc_s_getdata_from_buffer |
---|
| 174 | END INTERFACE pmc_s_getdata_from_buffer |
---|
[1762] | 175 | |
---|
[1900] | 176 | INTERFACE pmc_s_set_active_data_array |
---|
| 177 | MODULE PROCEDURE pmc_s_set_active_data_array |
---|
| 178 | END INTERFACE pmc_s_set_active_data_array |
---|
[1762] | 179 | |
---|
[2801] | 180 | INTERFACE pmc_s_get_child_npes |
---|
| 181 | MODULE PROCEDURE pmc_s_get_child_npes |
---|
| 182 | END INTERFACE pmc_s_get_child_npes |
---|
[1762] | 183 | |
---|
[2801] | 184 | PUBLIC pmc_parentinit, pmc_s_clear_next_array_list, pmc_s_fillbuffer, & |
---|
| 185 | pmc_s_getdata_from_buffer, pmc_s_getnextarray, & |
---|
| 186 | pmc_s_setind_and_allocmem, pmc_s_set_active_data_array, & |
---|
| 187 | pmc_s_set_dataarray, pmc_s_set_2d_index_list, & |
---|
| 188 | pmc_s_get_child_npes |
---|
| 189 | |
---|
[1900] | 190 | CONTAINS |
---|
[1762] | 191 | |
---|
| 192 | |
---|
[1933] | 193 | SUBROUTINE pmc_parentinit |
---|
[1762] | 194 | |
---|
[1900] | 195 | IMPLICIT NONE |
---|
[1762] | 196 | |
---|
[2801] | 197 | INTEGER(iwp) :: childid !< |
---|
| 198 | INTEGER(iwp) :: i !< |
---|
| 199 | INTEGER(iwp) :: j !< |
---|
| 200 | INTEGER(iwp) :: istat !< |
---|
[1762] | 201 | |
---|
| 202 | |
---|
[1933] | 203 | DO i = 1, SIZE( pmc_parent_for_child )-1 |
---|
[1762] | 204 | |
---|
[1933] | 205 | childid = pmc_parent_for_child( i ) |
---|
[1900] | 206 | |
---|
[1933] | 207 | children(childid)%model_comm = m_model_comm |
---|
| 208 | children(childid)%inter_comm = m_to_child_comm(childid) |
---|
| 209 | |
---|
[1779] | 210 | ! |
---|
[1900] | 211 | !-- Get rank and size |
---|
[2801] | 212 | CALL MPI_COMM_RANK( children(childid)%model_comm, & |
---|
[1933] | 213 | children(childid)%model_rank, istat ) |
---|
[2801] | 214 | CALL MPI_COMM_SIZE( children(childid)%model_comm, & |
---|
[1933] | 215 | children(childid)%model_npes, istat ) |
---|
[2801] | 216 | CALL MPI_COMM_REMOTE_SIZE( children(childid)%inter_comm, & |
---|
[1933] | 217 | children(childid)%inter_npes, istat ) |
---|
| 218 | |
---|
[1900] | 219 | ! |
---|
[2599] | 220 | !-- Intra communicator is used for MPI_GET |
---|
[2801] | 221 | CALL MPI_INTERCOMM_MERGE( children(childid)%inter_comm, .FALSE., & |
---|
[1933] | 222 | children(childid)%intra_comm, istat ) |
---|
[2801] | 223 | CALL MPI_COMM_RANK( children(childid)%intra_comm, & |
---|
[1933] | 224 | children(childid)%intra_rank, istat ) |
---|
[1762] | 225 | |
---|
[1933] | 226 | ALLOCATE( children(childid)%pes(children(childid)%inter_npes)) |
---|
| 227 | |
---|
[1900] | 228 | ! |
---|
[1933] | 229 | !-- Allocate array of TYPE arraydef for all child PEs to store information |
---|
[1900] | 230 | !-- of the transfer array |
---|
[1933] | 231 | DO j = 1, children(childid)%inter_npes |
---|
| 232 | ALLOCATE( children(childid)%pes(j)%array_list(pmc_max_array) ) |
---|
[1900] | 233 | ENDDO |
---|
[1762] | 234 | |
---|
[1933] | 235 | CALL get_da_names_from_child (childid) |
---|
[1762] | 236 | |
---|
[1900] | 237 | ENDDO |
---|
[1762] | 238 | |
---|
[1933] | 239 | END SUBROUTINE pmc_parentinit |
---|
[1762] | 240 | |
---|
| 241 | |
---|
| 242 | |
---|
[1933] | 243 | SUBROUTINE pmc_s_set_2d_index_list( childid, index_list ) |
---|
[1762] | 244 | |
---|
[1900] | 245 | IMPLICIT NONE |
---|
[1762] | 246 | |
---|
[2801] | 247 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
| 248 | INTEGER(iwp), DIMENSION(:,:), INTENT(INOUT) :: index_list !< |
---|
[1762] | 249 | |
---|
[2801] | 250 | INTEGER(iwp) :: ian !< |
---|
| 251 | INTEGER(iwp) :: ic !< |
---|
| 252 | INTEGER(iwp) :: ie !< |
---|
| 253 | INTEGER(iwp) :: ip !< |
---|
| 254 | INTEGER(iwp) :: is !< |
---|
| 255 | INTEGER(iwp) :: istat !< |
---|
| 256 | INTEGER(iwp) :: n,i !< |
---|
[1762] | 257 | |
---|
| 258 | |
---|
[1900] | 259 | IF ( m_model_rank == 0 ) THEN |
---|
| 260 | ! |
---|
[2599] | 261 | !-- Sort to ascending parent process order |
---|
[1900] | 262 | CALL pmc_sort( index_list, 6 ) |
---|
| 263 | is = 1 |
---|
| 264 | DO ip = 0, m_model_npes-1 |
---|
| 265 | ! |
---|
[2599] | 266 | !-- Split into parent processes |
---|
[1900] | 267 | ie = is - 1 |
---|
| 268 | ! |
---|
[2599] | 269 | !-- There may be no entry for this process |
---|
[1900] | 270 | IF ( is <= SIZE( index_list,2 ) .AND. ie >= 0 ) THEN |
---|
| 271 | DO WHILE ( index_list(6,ie+1 ) == ip ) |
---|
| 272 | ie = ie + 1 |
---|
| 273 | IF ( ie == SIZE( index_list,2 ) ) EXIT |
---|
| 274 | ENDDO |
---|
| 275 | ian = ie - is + 1 |
---|
| 276 | ELSE |
---|
| 277 | is = -1 |
---|
| 278 | ie = -2 |
---|
| 279 | ian = 0 |
---|
| 280 | ENDIF |
---|
| 281 | ! |
---|
[2599] | 282 | !-- Send data to other parent processes |
---|
[1900] | 283 | IF ( ip == 0 ) THEN |
---|
[1933] | 284 | indchildren(childid)%nrpoints = ian |
---|
[1900] | 285 | IF ( ian > 0) THEN |
---|
[1933] | 286 | ALLOCATE( indchildren(childid)%index_list_2d(6,ian) ) |
---|
[2801] | 287 | indchildren(childid)%index_list_2d(:,1:ian) = & |
---|
[1900] | 288 | index_list(:,is:ie) |
---|
| 289 | ENDIF |
---|
| 290 | ELSE |
---|
[2801] | 291 | CALL MPI_SEND( ian, 1, MPI_INTEGER, ip, 1000, m_model_comm, & |
---|
[1900] | 292 | istat ) |
---|
| 293 | IF ( ian > 0) THEN |
---|
[2801] | 294 | CALL MPI_SEND( index_list(1,is), 6*ian, MPI_INTEGER, ip, & |
---|
[1900] | 295 | 1001, m_model_comm, istat ) |
---|
| 296 | ENDIF |
---|
| 297 | ENDIF |
---|
| 298 | is = ie + 1 |
---|
| 299 | ENDDO |
---|
| 300 | ELSE |
---|
[2801] | 301 | CALL MPI_RECV( indchildren(childid)%nrpoints, 1, MPI_INTEGER, 0, 1000, & |
---|
[1900] | 302 | m_model_comm, MPI_STATUS_IGNORE, istat ) |
---|
[1933] | 303 | ian = indchildren(childid)%nrpoints |
---|
[1900] | 304 | IF ( ian > 0 ) THEN |
---|
[1933] | 305 | ALLOCATE( indchildren(childid)%index_list_2d(6,ian) ) |
---|
[2801] | 306 | CALL MPI_RECV( indchildren(childid)%index_list_2d, 6*ian, & |
---|
| 307 | MPI_INTEGER, 0, 1001, m_model_comm, & |
---|
[1900] | 308 | MPI_STATUS_IGNORE, istat) |
---|
| 309 | ENDIF |
---|
| 310 | ENDIF |
---|
[2801] | 311 | CALL set_pe_index_list( childid, children(childid), & |
---|
| 312 | indchildren(childid)%index_list_2d, & |
---|
[1933] | 313 | indchildren(childid)%nrpoints ) |
---|
[1762] | 314 | |
---|
[1900] | 315 | END SUBROUTINE pmc_s_set_2d_index_list |
---|
[1779] | 316 | |
---|
| 317 | |
---|
| 318 | |
---|
[1900] | 319 | SUBROUTINE pmc_s_clear_next_array_list |
---|
[1833] | 320 | |
---|
[1900] | 321 | IMPLICIT NONE |
---|
[1762] | 322 | |
---|
[1900] | 323 | next_array_in_list = 0 |
---|
[1762] | 324 | |
---|
[1900] | 325 | END SUBROUTINE pmc_s_clear_next_array_list |
---|
[1762] | 326 | |
---|
| 327 | |
---|
| 328 | |
---|
[1933] | 329 | LOGICAL FUNCTION pmc_s_getnextarray( childid, myname ) |
---|
| 330 | |
---|
[1900] | 331 | ! |
---|
[2801] | 332 | !-- Althoug there are no linked lists any more in PMC, this call still looks like working with a list |
---|
| 333 | |
---|
[1900] | 334 | CHARACTER(LEN=*), INTENT(OUT) :: myname !< |
---|
[1933] | 335 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1779] | 336 | |
---|
[1900] | 337 | TYPE(arraydef), POINTER :: ar |
---|
| 338 | TYPE(pedef), POINTER :: ape |
---|
[1779] | 339 | |
---|
[1900] | 340 | next_array_in_list = next_array_in_list + 1 |
---|
| 341 | ! |
---|
[2599] | 342 | !-- Array names are the same on all children processes, so take first |
---|
| 343 | !-- process to get the name |
---|
[1933] | 344 | ape => children(childid)%pes(1) |
---|
[1833] | 345 | |
---|
[1900] | 346 | IF ( next_array_in_list > ape%nr_arrays ) THEN |
---|
| 347 | ! |
---|
| 348 | !-- All arrays are done |
---|
| 349 | pmc_s_getnextarray = .FALSE. |
---|
| 350 | RETURN |
---|
| 351 | ENDIF |
---|
[1779] | 352 | |
---|
[1900] | 353 | ar => ape%array_list(next_array_in_list) |
---|
| 354 | myname = ar%name |
---|
| 355 | ! |
---|
[2801] | 356 | !-- Return true if there is still an array in the list |
---|
| 357 | |
---|
[1900] | 358 | pmc_s_getnextarray = .TRUE. |
---|
[1762] | 359 | |
---|
[1900] | 360 | END FUNCTION pmc_s_getnextarray |
---|
[1762] | 361 | |
---|
| 362 | |
---|
| 363 | |
---|
[1933] | 364 | SUBROUTINE pmc_s_set_dataarray_2d( childid, array, array_2 ) |
---|
[1900] | 365 | |
---|
| 366 | IMPLICIT NONE |
---|
| 367 | |
---|
[2801] | 368 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1900] | 369 | |
---|
| 370 | REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER :: array !< |
---|
| 371 | REAL(wp), INTENT(IN), DIMENSION(:,:), POINTER, OPTIONAL :: array_2 !< |
---|
| 372 | |
---|
[2801] | 373 | INTEGER(iwp) :: nrdims !< |
---|
| 374 | INTEGER(iwp), DIMENSION(4) :: dims !< |
---|
[1900] | 375 | TYPE(C_PTR) :: array_adr !< |
---|
| 376 | TYPE(C_PTR) :: second_adr !< |
---|
| 377 | |
---|
| 378 | |
---|
| 379 | dims = 1 |
---|
| 380 | nrdims = 2 |
---|
| 381 | dims(1) = SIZE( array,1 ) |
---|
| 382 | dims(2) = SIZE( array,2 ) |
---|
| 383 | array_adr = C_LOC( array ) |
---|
| 384 | |
---|
| 385 | IF ( PRESENT( array_2 ) ) THEN |
---|
| 386 | second_adr = C_LOC(array_2) |
---|
[2801] | 387 | CALL pmc_s_setarray( childid, nrdims, dims, array_adr, & |
---|
[1900] | 388 | second_adr = second_adr) |
---|
| 389 | ELSE |
---|
[1933] | 390 | CALL pmc_s_setarray( childid, nrdims, dims, array_adr ) |
---|
[1900] | 391 | ENDIF |
---|
| 392 | |
---|
| 393 | END SUBROUTINE pmc_s_set_dataarray_2d |
---|
| 394 | |
---|
[2801] | 395 | SUBROUTINE pmc_s_set_dataarray_ip2d( childid, array ) |
---|
[1900] | 396 | |
---|
[2801] | 397 | IMPLICIT NONE |
---|
[1900] | 398 | |
---|
[2801] | 399 | INTEGER(iwp),INTENT(IN) :: childid !< |
---|
| 400 | |
---|
| 401 | INTEGER(idp), INTENT(IN), DIMENSION(:,:), POINTER :: array !< |
---|
| 402 | |
---|
| 403 | INTEGER(iwp) :: nrdims !< |
---|
| 404 | INTEGER(iwp), DIMENSION(4) :: dims !< |
---|
| 405 | TYPE(C_PTR) :: array_adr !< |
---|
| 406 | |
---|
| 407 | |
---|
| 408 | dims = 1 |
---|
| 409 | nrdims = 2 |
---|
| 410 | dims(1) = SIZE( array,1 ) |
---|
| 411 | dims(2) = SIZE( array,2 ) |
---|
| 412 | array_adr = C_LOC( array ) |
---|
| 413 | |
---|
| 414 | CALL pmc_s_setarray( childid, nrdims, dims, array_adr , dimkey=22) |
---|
| 415 | |
---|
| 416 | END SUBROUTINE pmc_s_set_dataarray_ip2d |
---|
| 417 | |
---|
| 418 | |
---|
[1933] | 419 | SUBROUTINE pmc_s_set_dataarray_3d( childid, array, nz_cl, nz, array_2 ) |
---|
[1900] | 420 | |
---|
| 421 | IMPLICIT NONE |
---|
| 422 | |
---|
[2801] | 423 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
| 424 | INTEGER(iwp), INTENT(IN) :: nz !< |
---|
| 425 | INTEGER(iwp), INTENT(IN) :: nz_cl !< |
---|
[1900] | 426 | |
---|
| 427 | REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER :: array !< |
---|
| 428 | REAL(wp), INTENT(IN), DIMENSION(:,:,:), POINTER, OPTIONAL :: array_2 !< |
---|
| 429 | |
---|
[2801] | 430 | INTEGER(iwp) :: nrdims !< |
---|
| 431 | INTEGER(iwp), DIMENSION(4) :: dims !< |
---|
[1900] | 432 | TYPE(C_PTR) :: array_adr !< |
---|
| 433 | TYPE(C_PTR) :: second_adr !< |
---|
| 434 | |
---|
| 435 | nrdims = 3 |
---|
| 436 | dims(1) = SIZE( array,1 ) |
---|
| 437 | dims(2) = SIZE( array,2 ) |
---|
| 438 | dims(3) = SIZE( array,3 ) |
---|
| 439 | dims(4) = nz_cl+dims(1)-nz ! works for first dimension 1:nz and 0:nz+1 |
---|
| 440 | |
---|
| 441 | array_adr = C_LOC(array) |
---|
[1766] | 442 | ! |
---|
[1900] | 443 | !-- In PALM's pointer version, two indices have to be stored internally. |
---|
| 444 | !-- The active address of the data array is set in swap_timelevel. |
---|
| 445 | IF ( PRESENT( array_2 ) ) THEN |
---|
| 446 | second_adr = C_LOC( array_2 ) |
---|
[2801] | 447 | CALL pmc_s_setarray( childid, nrdims, dims, array_adr, & |
---|
[1900] | 448 | second_adr = second_adr) |
---|
| 449 | ELSE |
---|
[1933] | 450 | CALL pmc_s_setarray( childid, nrdims, dims, array_adr ) |
---|
[1900] | 451 | ENDIF |
---|
[1762] | 452 | |
---|
[1900] | 453 | END SUBROUTINE pmc_s_set_dataarray_3d |
---|
[1762] | 454 | |
---|
[1779] | 455 | |
---|
| 456 | |
---|
[1933] | 457 | SUBROUTINE pmc_s_setind_and_allocmem( childid ) |
---|
[1779] | 458 | |
---|
[2801] | 459 | USE control_parameters, & |
---|
[1900] | 460 | ONLY: message_string |
---|
| 461 | |
---|
| 462 | IMPLICIT NONE |
---|
| 463 | |
---|
[1786] | 464 | ! |
---|
[1933] | 465 | !-- Naming convention for appendices: _pc -> parent to child transfer |
---|
| 466 | !-- _cp -> child to parent transfer |
---|
| 467 | !-- send -> parent to child transfer |
---|
| 468 | !-- recv -> child to parent transfer |
---|
[2801] | 469 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1762] | 470 | |
---|
[2801] | 471 | INTEGER(iwp) :: arlen !< |
---|
| 472 | INTEGER(iwp) :: i !< |
---|
| 473 | INTEGER(iwp) :: ierr !< |
---|
| 474 | INTEGER(iwp) :: istat !< |
---|
| 475 | INTEGER(iwp) :: j !< |
---|
| 476 | INTEGER(iwp) :: myindex !< |
---|
| 477 | INTEGER(iwp) :: rcount !< count MPI requests |
---|
| 478 | INTEGER(iwp) :: tag !< |
---|
[1762] | 479 | |
---|
[1900] | 480 | INTEGER(idp) :: bufsize !< size of MPI data window |
---|
| 481 | INTEGER(KIND=MPI_ADDRESS_KIND) :: winsize !< |
---|
| 482 | |
---|
[2801] | 483 | INTEGER(iwp), DIMENSION(1024) :: req !< |
---|
[1900] | 484 | |
---|
| 485 | TYPE(C_PTR) :: base_ptr !< |
---|
| 486 | TYPE(pedef), POINTER :: ape !< |
---|
| 487 | TYPE(arraydef), POINTER :: ar !< |
---|
| 488 | |
---|
[1933] | 489 | REAL(wp),DIMENSION(:), POINTER, SAVE :: base_array_pc !< base array for parent to child transfer |
---|
| 490 | REAL(wp),DIMENSION(:), POINTER, SAVE :: base_array_cp !< base array for child to parent transfer |
---|
[1900] | 491 | |
---|
[1786] | 492 | ! |
---|
[1933] | 493 | !-- Parent to child direction |
---|
[1900] | 494 | myindex = 1 |
---|
| 495 | rcount = 0 |
---|
| 496 | bufsize = 8 |
---|
[1786] | 497 | ! |
---|
[1900] | 498 | !-- First stride: compute size and set index |
---|
[1933] | 499 | DO i = 1, children(childid)%inter_npes |
---|
[1762] | 500 | |
---|
[1933] | 501 | ape => children(childid)%pes(i) |
---|
[1900] | 502 | tag = 200 |
---|
[1762] | 503 | |
---|
[1900] | 504 | DO j = 1, ape%nr_arrays |
---|
[1762] | 505 | |
---|
[1900] | 506 | ar => ape%array_list(j) |
---|
| 507 | IF ( ar%nrdims == 2 ) THEN |
---|
| 508 | arlen = ape%nrele |
---|
| 509 | ELSEIF ( ar%nrdims == 3 ) THEN |
---|
| 510 | arlen = ape%nrele * ar%a_dim(4) |
---|
| 511 | ELSE |
---|
| 512 | arlen = -1 |
---|
| 513 | ENDIF |
---|
| 514 | ar%sendindex = myindex |
---|
[1762] | 515 | |
---|
[1900] | 516 | tag = tag + 1 |
---|
| 517 | rcount = rcount + 1 |
---|
[2801] | 518 | CALL MPI_ISEND( myindex, 1, MPI_INTEGER, i-1, tag, & |
---|
[1933] | 519 | children(childid)%inter_comm, req(rcount), ierr ) |
---|
[1900] | 520 | ! |
---|
[2801] | 521 | !-- Maximum of 1024 pending requests |
---|
| 522 | |
---|
[1900] | 523 | IF ( rcount == 1024 ) THEN |
---|
| 524 | CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr ) |
---|
| 525 | rcount = 0 |
---|
| 526 | ENDIF |
---|
[1762] | 527 | |
---|
[1900] | 528 | myindex = myindex + arlen |
---|
| 529 | bufsize = bufsize + arlen |
---|
| 530 | ar%sendsize = arlen |
---|
| 531 | ENDDO |
---|
| 532 | |
---|
| 533 | IF ( rcount > 0 ) THEN |
---|
| 534 | CALL MPI_WAITALL( rcount, req, MPI_STATUSES_IGNORE, ierr ) |
---|
| 535 | ENDIF |
---|
| 536 | |
---|
| 537 | ENDDO |
---|
[1786] | 538 | ! |
---|
[1933] | 539 | !-- Create RMA (One Sided Communication) window for data buffer parent to |
---|
| 540 | !-- child transfer. |
---|
[1900] | 541 | !-- The buffer of MPI_GET (counterpart of transfer) can be PE-local, i.e. |
---|
| 542 | !-- it can but must not be part of the MPI RMA window. Only one RMA window is |
---|
| 543 | !-- required to prepare the data for |
---|
[1933] | 544 | !-- parent -> child transfer on the parent side |
---|
[1900] | 545 | !-- and for |
---|
[1933] | 546 | !-- child -> parent transfer on the child side |
---|
| 547 | CALL pmc_alloc_mem( base_array_pc, bufsize ) |
---|
| 548 | children(childid)%totalbuffersize = bufsize * wp |
---|
[1762] | 549 | |
---|
[1900] | 550 | winsize = bufsize * wp |
---|
[2801] | 551 | CALL MPI_WIN_CREATE( base_array_pc, winsize, wp, MPI_INFO_NULL, & |
---|
| 552 | children(childid)%intra_comm, & |
---|
[1933] | 553 | children(childid)%win_parent_child, ierr ) |
---|
[1786] | 554 | ! |
---|
[1900] | 555 | !-- Open window to set data |
---|
[1933] | 556 | CALL MPI_WIN_FENCE( 0, children(childid)%win_parent_child, ierr ) |
---|
[1900] | 557 | ! |
---|
| 558 | !-- Second stride: set buffer pointer |
---|
[1933] | 559 | DO i = 1, children(childid)%inter_npes |
---|
[1786] | 560 | |
---|
[1933] | 561 | ape => children(childid)%pes(i) |
---|
[1786] | 562 | |
---|
[1900] | 563 | DO j = 1, ape%nr_arrays |
---|
[1786] | 564 | |
---|
[1900] | 565 | ar => ape%array_list(j) |
---|
[1933] | 566 | ar%sendbuf = C_LOC( base_array_pc(ar%sendindex) ) |
---|
[1786] | 567 | |
---|
[1933] | 568 | IF ( ar%sendindex + ar%sendsize > bufsize ) THEN |
---|
[2801] | 569 | WRITE( message_string, '(a,i4,4i7,1x,a)' ) & |
---|
| 570 | 'parent buffer too small ',i, & |
---|
| 571 | ar%sendindex,ar%sendsize,ar%sendindex+ar%sendsize, & |
---|
[1933] | 572 | bufsize,trim(ar%name) |
---|
| 573 | CALL message( 'pmc_s_setind_and_allocmem', 'PA0429', 3, 2, 0, 6, 0 ) |
---|
[1900] | 574 | ENDIF |
---|
| 575 | ENDDO |
---|
| 576 | ENDDO |
---|
| 577 | ! |
---|
[1933] | 578 | !-- Child to parent direction |
---|
[1900] | 579 | bufsize = 8 |
---|
| 580 | ! |
---|
| 581 | !-- First stride: compute size and set index |
---|
[1933] | 582 | DO i = 1, children(childid)%inter_npes |
---|
| 583 | ape => children(childid)%pes(i) |
---|
[1900] | 584 | tag = 300 |
---|
| 585 | DO j = 1, ape%nr_arrays |
---|
| 586 | ar => ape%array_list(j) |
---|
| 587 | ! |
---|
[1933] | 588 | !-- Receive index from child |
---|
[1900] | 589 | tag = tag + 1 |
---|
[2801] | 590 | CALL MPI_RECV( myindex, 1, MPI_INTEGER, i-1, tag, & |
---|
[1933] | 591 | children(childid)%inter_comm, MPI_STATUS_IGNORE, ierr ) |
---|
[1900] | 592 | IF ( ar%nrdims == 3 ) THEN |
---|
| 593 | bufsize = MAX( bufsize, ape%nrele * ar%a_dim(4) ) |
---|
| 594 | ELSE |
---|
| 595 | bufsize = MAX( bufsize, ape%nrele ) |
---|
| 596 | ENDIF |
---|
| 597 | ar%recvindex = myindex |
---|
| 598 | ENDDO |
---|
| 599 | ENDDO |
---|
| 600 | ! |
---|
| 601 | !-- Create RMA (one sided communication) data buffer. |
---|
| 602 | !-- The buffer for MPI_GET can be PE local, i.e. it can but must not be part of |
---|
| 603 | !-- the MPI RMA window |
---|
[1933] | 604 | CALL pmc_alloc_mem( base_array_cp, bufsize, base_ptr ) |
---|
| 605 | children(childid)%totalbuffersize = bufsize * wp |
---|
[1762] | 606 | |
---|
[1933] | 607 | CALL MPI_BARRIER( children(childid)%intra_comm, ierr ) |
---|
[1900] | 608 | ! |
---|
| 609 | !-- Second stride: set buffer pointer |
---|
[1933] | 610 | DO i = 1, children(childid)%inter_npes |
---|
| 611 | ape => children(childid)%pes(i) |
---|
[1900] | 612 | DO j = 1, ape%nr_arrays |
---|
| 613 | ar => ape%array_list(j) |
---|
| 614 | ar%recvbuf = base_ptr |
---|
| 615 | ENDDO |
---|
| 616 | ENDDO |
---|
[1762] | 617 | |
---|
[1900] | 618 | END SUBROUTINE pmc_s_setind_and_allocmem |
---|
[1762] | 619 | |
---|
| 620 | |
---|
[1797] | 621 | |
---|
[2801] | 622 | SUBROUTINE pmc_s_fillbuffer( childid, waittime, particle_transfer ) |
---|
[1762] | 623 | |
---|
[1900] | 624 | IMPLICIT NONE |
---|
[1762] | 625 | |
---|
[2801] | 626 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1762] | 627 | |
---|
[1900] | 628 | REAL(wp), INTENT(OUT), OPTIONAL :: waittime !< |
---|
[2801] | 629 | LOGICAL, INTENT(IN), OPTIONAL :: particle_transfer !< |
---|
[1779] | 630 | |
---|
[1762] | 631 | |
---|
[2801] | 632 | INTEGER(iwp) :: ierr !< |
---|
| 633 | INTEGER(iwp) :: ij !< |
---|
| 634 | INTEGER(iwp) :: ip !< |
---|
| 635 | INTEGER(iwp) :: istat !< |
---|
| 636 | INTEGER(iwp) :: j !< |
---|
| 637 | INTEGER(iwp) :: myindex !< |
---|
| 638 | |
---|
| 639 | LOGICAL :: lo_ptrans |
---|
[1779] | 640 | |
---|
[2801] | 641 | INTEGER(iwp), DIMENSION(1) :: buf_shape |
---|
| 642 | |
---|
[1900] | 643 | REAL(wp) :: t1 !< |
---|
| 644 | REAL(wp) :: t2 !< |
---|
| 645 | REAL(wp), POINTER, DIMENSION(:) :: buf !< |
---|
| 646 | REAL(wp), POINTER, DIMENSION(:,:) :: data_2d !< |
---|
| 647 | REAL(wp), POINTER, DIMENSION(:,:,:) :: data_3d !< |
---|
[2801] | 648 | INTEGER(idp), POINTER, DIMENSION(:) :: ibuf !< |
---|
| 649 | INTEGER(idp), POINTER, DIMENSION(:,:) :: idata_2d !< |
---|
[1762] | 650 | |
---|
[1900] | 651 | TYPE(pedef), POINTER :: ape !< |
---|
| 652 | TYPE(arraydef), POINTER :: ar !< |
---|
[1762] | 653 | |
---|
[1900] | 654 | ! |
---|
[1933] | 655 | !-- Synchronization of the model is done in pmci_synchronize. |
---|
| 656 | !-- Therefor the RMA window can be filled without |
---|
[1900] | 657 | !-- sychronization at this point and a barrier is not necessary. |
---|
| 658 | !-- Please note that waittime has to be set in pmc_s_fillbuffer AND |
---|
| 659 | !-- pmc_c_getbuffer |
---|
| 660 | IF ( PRESENT( waittime) ) THEN |
---|
| 661 | t1 = pmc_time() |
---|
[1933] | 662 | CALL MPI_BARRIER( children(childid)%intra_comm, ierr ) |
---|
[1900] | 663 | t2 = pmc_time() |
---|
| 664 | waittime = t2- t1 |
---|
| 665 | ENDIF |
---|
[1786] | 666 | |
---|
[2801] | 667 | lo_ptrans = .FALSE. |
---|
| 668 | IF ( PRESENT( particle_transfer)) lo_ptrans = particle_transfer |
---|
| 669 | |
---|
[1933] | 670 | DO ip = 1, children(childid)%inter_npes |
---|
| 671 | ape => children(childid)%pes(ip) |
---|
[1900] | 672 | DO j = 1, ape%nr_arrays |
---|
| 673 | ar => ape%array_list(j) |
---|
| 674 | myindex = 1 |
---|
[2801] | 675 | |
---|
| 676 | IF ( ar%dimkey == 2 .AND. .NOT.lo_ptrans ) THEN ! PALM 2D REAL*8 Array |
---|
| 677 | |
---|
[1900] | 678 | buf_shape(1) = ape%nrele |
---|
| 679 | CALL C_F_POINTER( ar%sendbuf, buf, buf_shape ) |
---|
| 680 | CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) ) |
---|
| 681 | DO ij = 1, ape%nrele |
---|
| 682 | buf(myindex) = data_2d(ape%locind(ij)%j,ape%locind(ij)%i) |
---|
| 683 | myindex = myindex + 1 |
---|
| 684 | ENDDO |
---|
[2801] | 685 | |
---|
| 686 | ELSEIF ( ar%dimkey == 3 .AND. .NOT.lo_ptrans ) THEN ! PALM 3D REAL*8 Array |
---|
| 687 | |
---|
[1900] | 688 | buf_shape(1) = ape%nrele*ar%a_dim(4) |
---|
| 689 | CALL C_F_POINTER( ar%sendbuf, buf, buf_shape ) |
---|
| 690 | CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3) ) |
---|
| 691 | DO ij = 1, ape%nrele |
---|
[1933] | 692 | buf(myindex:myindex+ar%a_dim(4)-1) = & |
---|
[1900] | 693 | data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) |
---|
| 694 | myindex = myindex + ar%a_dim(4) |
---|
| 695 | ENDDO |
---|
[2801] | 696 | ELSEIF ( ar%dimkey == 22 .AND. lo_ptrans ) THEN ! 2D INTEGER*8 Array for particle Transfer |
---|
| 697 | |
---|
| 698 | buf_shape(1) = ape%nrele |
---|
| 699 | CALL C_F_POINTER( ar%sendbuf, ibuf, buf_shape ) |
---|
| 700 | CALL C_F_POINTER( ar%data, idata_2d, ar%a_dim(1:2) ) |
---|
| 701 | DO ij = 1, ape%nrele |
---|
| 702 | ibuf(myindex) = idata_2d(ape%locind(ij)%j,ape%locind(ij)%i) |
---|
| 703 | myindex = myindex + 1 |
---|
| 704 | ENDDO |
---|
[1900] | 705 | ENDIF |
---|
| 706 | ENDDO |
---|
| 707 | ENDDO |
---|
[1786] | 708 | ! |
---|
[1900] | 709 | !-- Buffer is filled |
---|
[1933] | 710 | CALL MPI_BARRIER( children(childid)%intra_comm, ierr ) |
---|
[1786] | 711 | |
---|
[1900] | 712 | END SUBROUTINE pmc_s_fillbuffer |
---|
[1786] | 713 | |
---|
[1762] | 714 | |
---|
| 715 | |
---|
[2801] | 716 | SUBROUTINE pmc_s_getdata_from_buffer( childid, waittime , particle_transfer, child_process_nr ) |
---|
[1762] | 717 | |
---|
[1900] | 718 | IMPLICIT NONE |
---|
[1762] | 719 | |
---|
[2801] | 720 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1933] | 721 | REAL(wp), INTENT(OUT), OPTIONAL :: waittime !< |
---|
[2801] | 722 | LOGICAL, INTENT(IN), OPTIONAL :: particle_transfer !< |
---|
| 723 | INTEGER(iwp), INTENT(IN), OPTIONAL :: child_process_nr !< |
---|
[1762] | 724 | |
---|
[2801] | 725 | INTEGER(iwp) :: ierr !< |
---|
| 726 | INTEGER(iwp) :: ij !< |
---|
| 727 | INTEGER(iwp) :: ip !< |
---|
| 728 | INTEGER(iwp) :: ip_start !< |
---|
| 729 | INTEGER(iwp) :: ip_end !< |
---|
| 730 | INTEGER(iwp) :: istat !< |
---|
| 731 | INTEGER(iwp) :: j !< |
---|
| 732 | INTEGER(iwp) :: myindex !< |
---|
| 733 | INTEGER(iwp) :: nr !< |
---|
| 734 | INTEGER(iwp) :: target_pe !< |
---|
[1933] | 735 | INTEGER(kind=MPI_ADDRESS_KIND) :: target_disp !< |
---|
[2801] | 736 | |
---|
| 737 | LOGICAL :: lo_ptrans |
---|
[1762] | 738 | |
---|
[2801] | 739 | INTEGER(iwp), DIMENSION(1) :: buf_shape !< |
---|
[1762] | 740 | |
---|
[2801] | 741 | REAL(wp) :: t1 !< |
---|
| 742 | REAL(wp) :: t2 !< |
---|
| 743 | REAL(wp), POINTER, DIMENSION(:) :: buf !< |
---|
| 744 | REAL(wp), POINTER, DIMENSION(:,:) :: data_2d !< |
---|
| 745 | REAL(wp), POINTER, DIMENSION(:,:,:) :: data_3d !< |
---|
| 746 | INTEGER(idp), POINTER, DIMENSION(:) :: ibuf !< |
---|
| 747 | INTEGER(idp), POINTER, DIMENSION(:,:) :: idata_2d !< |
---|
[1762] | 748 | |
---|
[2801] | 749 | TYPE(pedef), POINTER :: ape !< |
---|
| 750 | TYPE(arraydef), POINTER :: ar !< |
---|
[1762] | 751 | |
---|
| 752 | |
---|
[1900] | 753 | t1 = pmc_time() |
---|
[2801] | 754 | |
---|
| 755 | IF(PRESENT(child_process_nr)) then |
---|
| 756 | ip_start = child_process_nr |
---|
| 757 | ip_end = child_process_nr |
---|
| 758 | ELSE |
---|
| 759 | ip_start = 1 |
---|
| 760 | ip_end = children(childid)%inter_npes |
---|
| 761 | END IF |
---|
| 762 | |
---|
| 763 | lo_ptrans = .FALSE. |
---|
| 764 | IF ( PRESENT( particle_transfer)) lo_ptrans = particle_transfer |
---|
| 765 | |
---|
| 766 | IF(ip_start == 1) THEN |
---|
[1900] | 767 | ! |
---|
[2801] | 768 | !-- Wait for child to fill buffer |
---|
| 769 | CALL MPI_BARRIER( children(childid)%intra_comm, ierr ) |
---|
| 770 | t2 = pmc_time() - t1 |
---|
| 771 | IF ( PRESENT( waittime ) ) waittime = t2 |
---|
[1762] | 772 | |
---|
[2801] | 773 | CALL MPI_BARRIER( children(childid)%intra_comm, ierr ) |
---|
| 774 | ENDIF |
---|
| 775 | |
---|
| 776 | DO ip = ip_start,ip_end |
---|
[1933] | 777 | ape => children(childid)%pes(ip) |
---|
[1900] | 778 | DO j = 1, ape%nr_arrays |
---|
| 779 | ar => ape%array_list(j) |
---|
[2599] | 780 | |
---|
[1900] | 781 | IF ( ar%recvindex < 0 ) CYCLE |
---|
[1766] | 782 | |
---|
[2801] | 783 | IF ( ar%dimkey == 2 .AND. .NOT.lo_ptrans ) THEN |
---|
[1900] | 784 | nr = ape%nrele |
---|
[2801] | 785 | ELSEIF ( ar%dimkey == 3 .AND. .NOT.lo_ptrans ) THEN |
---|
[1900] | 786 | nr = ape%nrele * ar%a_dim(4) |
---|
[2801] | 787 | ELSE IF ( ar%dimkey == 22 .AND. lo_ptrans) THEN |
---|
| 788 | nr = ape%nrele |
---|
| 789 | ELSE |
---|
| 790 | CYCLE !particle array are not transfered here |
---|
[1900] | 791 | ENDIF |
---|
| 792 | buf_shape(1) = nr |
---|
[2801] | 793 | IF(lo_ptrans) THEN |
---|
| 794 | CALL C_F_POINTER( ar%recvbuf, ibuf, buf_shape ) |
---|
| 795 | ELSE |
---|
| 796 | CALL C_F_POINTER( ar%recvbuf, buf, buf_shape ) |
---|
| 797 | ENDIF |
---|
| 798 | |
---|
[1900] | 799 | ! |
---|
| 800 | !-- MPI passive target RMA |
---|
| 801 | IF ( nr > 0 ) THEN |
---|
| 802 | target_disp = ar%recvindex - 1 |
---|
| 803 | ! |
---|
[2599] | 804 | !-- Child processes are located behind parent process |
---|
[1900] | 805 | target_pe = ip - 1 + m_model_npes |
---|
[2801] | 806 | CALL MPI_WIN_LOCK( MPI_LOCK_SHARED, target_pe, 0, & |
---|
[1933] | 807 | children(childid)%win_parent_child, ierr ) |
---|
[2801] | 808 | IF(lo_ptrans) THEN |
---|
| 809 | CALL MPI_GET( ibuf, nr*8, MPI_BYTE, target_pe, target_disp, nr*8, & !There is no MPI_INTEGER8 datatype |
---|
| 810 | MPI_BYTE, children(childid)%win_parent_child, ierr ) |
---|
| 811 | ELSE |
---|
| 812 | CALL MPI_GET( buf, nr, MPI_REAL, target_pe, target_disp, nr, & |
---|
| 813 | MPI_REAL, children(childid)%win_parent_child, ierr ) |
---|
| 814 | ENDIF |
---|
| 815 | CALL MPI_WIN_UNLOCK( target_pe, & |
---|
[1933] | 816 | children(childid)%win_parent_child, ierr ) |
---|
[1900] | 817 | ENDIF |
---|
| 818 | myindex = 1 |
---|
[2801] | 819 | IF ( ar%dimkey == 2 .AND. .NOT.lo_ptrans ) THEN |
---|
| 820 | |
---|
[1900] | 821 | CALL C_F_POINTER( ar%data, data_2d, ar%a_dim(1:2) ) |
---|
| 822 | DO ij = 1, ape%nrele |
---|
| 823 | data_2d(ape%locind(ij)%j,ape%locind(ij)%i) = buf(myindex) |
---|
| 824 | myindex = myindex + 1 |
---|
| 825 | ENDDO |
---|
[2801] | 826 | |
---|
| 827 | ELSEIF ( ar%dimkey == 3 .AND. .NOT.lo_ptrans ) THEN |
---|
| 828 | |
---|
[1900] | 829 | CALL C_F_POINTER( ar%data, data_3d, ar%a_dim(1:3)) |
---|
| 830 | DO ij = 1, ape%nrele |
---|
[2801] | 831 | data_3d(1:ar%a_dim(4),ape%locind(ij)%j,ape%locind(ij)%i) = & |
---|
[1900] | 832 | buf(myindex:myindex+ar%a_dim(4)-1) |
---|
| 833 | myindex = myindex + ar%a_dim(4) |
---|
| 834 | ENDDO |
---|
[2801] | 835 | |
---|
| 836 | ELSE IF ( ar%dimkey == 22 .AND. lo_ptrans) THEN |
---|
| 837 | |
---|
| 838 | CALL C_F_POINTER( ar%data, idata_2d, ar%a_dim(1:2) ) |
---|
| 839 | DO ij = 1, ape%nrele |
---|
| 840 | idata_2d(ape%locind(ij)%j,ape%locind(ij)%i) = ibuf(myindex) |
---|
| 841 | myindex = myindex + 1 |
---|
| 842 | ENDDO |
---|
| 843 | |
---|
[1900] | 844 | ENDIF |
---|
| 845 | ENDDO |
---|
| 846 | ENDDO |
---|
[1762] | 847 | |
---|
[1900] | 848 | END SUBROUTINE pmc_s_getdata_from_buffer |
---|
[1762] | 849 | |
---|
| 850 | |
---|
| 851 | |
---|
[1933] | 852 | SUBROUTINE get_da_names_from_child( childid ) |
---|
| 853 | |
---|
[1900] | 854 | ! |
---|
[1933] | 855 | !-- Get data array description and name from child |
---|
[1900] | 856 | IMPLICIT NONE |
---|
[1762] | 857 | |
---|
[2801] | 858 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
[1762] | 859 | |
---|
[1900] | 860 | TYPE(da_namedef) :: myname !< |
---|
[1762] | 861 | |
---|
[1900] | 862 | DO |
---|
[1933] | 863 | CALL pmc_bcast( myname%couple_index, 0, comm=m_to_child_comm(childid) ) |
---|
[1900] | 864 | IF ( myname%couple_index == -1 ) EXIT |
---|
[1933] | 865 | CALL pmc_bcast( myname%parentdesc, 0, comm=m_to_child_comm(childid) ) |
---|
| 866 | CALL pmc_bcast( myname%nameonparent, 0, comm=m_to_child_comm(childid) ) |
---|
| 867 | CALL pmc_bcast( myname%childdesc, 0, comm=m_to_child_comm(childid) ) |
---|
| 868 | CALL pmc_bcast( myname%nameonchild, 0, comm=m_to_child_comm(childid) ) |
---|
[1762] | 869 | |
---|
[2801] | 870 | CALL pmc_g_setname( children(childid), myname%couple_index, & |
---|
[1933] | 871 | myname%nameonparent ) |
---|
[1900] | 872 | ENDDO |
---|
[1762] | 873 | |
---|
[1933] | 874 | END SUBROUTINE get_da_names_from_child |
---|
[1762] | 875 | |
---|
| 876 | |
---|
| 877 | |
---|
[2801] | 878 | SUBROUTINE pmc_s_setarray(childid, nrdims, dims, array_adr, second_adr, dimkey ) |
---|
[1933] | 879 | |
---|
[1900] | 880 | ! |
---|
[2599] | 881 | !-- Set array for child inter process 0 |
---|
[1900] | 882 | IMPLICIT NONE |
---|
[1762] | 883 | |
---|
[2801] | 884 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
| 885 | INTEGER(iwp), INTENT(IN) :: nrdims !< |
---|
| 886 | INTEGER(iwp), INTENT(IN), DIMENSION(:) :: dims !< |
---|
[1762] | 887 | |
---|
[2801] | 888 | TYPE(C_PTR), INTENT(IN) :: array_adr !< |
---|
| 889 | TYPE(C_PTR), INTENT(IN), OPTIONAL :: second_adr !< |
---|
| 890 | INTEGER(iwp), INTENT(IN), OPTIONAL :: dimkey !< |
---|
[1762] | 891 | |
---|
[2801] | 892 | INTEGER(iwp) :: i !< local counter |
---|
[1762] | 893 | |
---|
[1900] | 894 | TYPE(pedef), POINTER :: ape !< |
---|
| 895 | TYPE(arraydef), POINTER :: ar !< |
---|
[1762] | 896 | |
---|
| 897 | |
---|
[1933] | 898 | DO i = 1, children(childid)%inter_npes |
---|
| 899 | ape => children(childid)%pes(i) |
---|
[1900] | 900 | ar => ape%array_list(next_array_in_list) |
---|
| 901 | ar%nrdims = nrdims |
---|
[2801] | 902 | ar%dimkey = nrdims |
---|
| 903 | IF(PRESENT(dimkey)) ar%dimkey = dimkey |
---|
[1900] | 904 | ar%a_dim = dims |
---|
| 905 | ar%data = array_adr |
---|
| 906 | IF ( PRESENT( second_adr ) ) THEN |
---|
| 907 | ar%po_data(1) = array_adr |
---|
| 908 | ar%po_data(2) = second_adr |
---|
| 909 | ELSE |
---|
| 910 | ar%po_data(1) = C_NULL_PTR |
---|
| 911 | ar%po_data(2) = C_NULL_PTR |
---|
| 912 | ENDIF |
---|
| 913 | ENDDO |
---|
| 914 | |
---|
| 915 | END SUBROUTINE pmc_s_setarray |
---|
| 916 | |
---|
| 917 | |
---|
| 918 | |
---|
[1933] | 919 | SUBROUTINE pmc_s_set_active_data_array( childid, iactive ) |
---|
[1900] | 920 | |
---|
| 921 | IMPLICIT NONE |
---|
| 922 | |
---|
[2801] | 923 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
| 924 | INTEGER(iwp), INTENT(IN) :: iactive !< |
---|
[1900] | 925 | |
---|
[2801] | 926 | INTEGER(iwp) :: i !< |
---|
| 927 | INTEGER(iwp) :: ip !< |
---|
| 928 | INTEGER(iwp) :: j !< |
---|
[1900] | 929 | |
---|
| 930 | TYPE(pedef), POINTER :: ape !< |
---|
| 931 | TYPE(arraydef), POINTER :: ar !< |
---|
| 932 | |
---|
[1933] | 933 | DO ip = 1, children(childid)%inter_npes |
---|
| 934 | ape => children(childid)%pes(ip) |
---|
[1900] | 935 | DO j = 1, ape%nr_arrays |
---|
| 936 | ar => ape%array_list(j) |
---|
[2801] | 937 | if(mod(ar%dimkey,10) == 2) CYCLE !Not for 2D array |
---|
[1900] | 938 | IF ( iactive == 1 .OR. iactive == 2 ) THEN |
---|
| 939 | ar%data = ar%po_data(iactive) |
---|
| 940 | ENDIF |
---|
| 941 | ENDDO |
---|
| 942 | ENDDO |
---|
| 943 | |
---|
| 944 | END SUBROUTINE pmc_s_set_active_data_array |
---|
| 945 | |
---|
[2801] | 946 | INTEGER FUNCTION pmc_s_get_child_npes (child_id) |
---|
| 947 | IMPLICIT NONE |
---|
[1900] | 948 | |
---|
[2801] | 949 | INTEGER(iwp),INTENT(IN) :: child_id |
---|
[1900] | 950 | |
---|
[2801] | 951 | pmc_s_get_child_npes = children(child_id)%inter_npes |
---|
| 952 | |
---|
| 953 | RETURN |
---|
| 954 | END FUNCTION pmc_s_get_child_npes |
---|
| 955 | |
---|
| 956 | |
---|
[1933] | 957 | SUBROUTINE set_pe_index_list( childid, mychild, index_list, nrp ) |
---|
[1900] | 958 | |
---|
| 959 | IMPLICIT NONE |
---|
| 960 | |
---|
[2801] | 961 | INTEGER(iwp), INTENT(IN) :: childid !< |
---|
| 962 | INTEGER(iwp), INTENT(IN), DIMENSION(:,:) :: index_list !< |
---|
| 963 | INTEGER(iwp), INTENT(IN) :: nrp !< |
---|
[1900] | 964 | |
---|
[1933] | 965 | TYPE(childdef), INTENT(INOUT) :: mychild !< |
---|
[1900] | 966 | |
---|
[2801] | 967 | INTEGER(iwp) :: i !< |
---|
| 968 | INTEGER(iwp) :: ierr !< |
---|
| 969 | INTEGER(iwp) :: ind !< |
---|
| 970 | INTEGER(iwp) :: indwin !< |
---|
| 971 | INTEGER(iwp) :: indwin2 !< |
---|
| 972 | INTEGER(iwp) :: i2 !< |
---|
| 973 | INTEGER(iwp) :: j !< |
---|
| 974 | INTEGER(iwp) :: rempe !< |
---|
[1900] | 975 | INTEGER(KIND=MPI_ADDRESS_KIND) :: winsize !< |
---|
| 976 | |
---|
[2801] | 977 | INTEGER(iwp), DIMENSION(mychild%inter_npes) :: remind !< |
---|
[1900] | 978 | |
---|
[2801] | 979 | INTEGER(iwp), DIMENSION(:), POINTER :: remindw !< |
---|
| 980 | INTEGER(iwp), DIMENSION(:), POINTER :: rldef !< |
---|
[1900] | 981 | |
---|
| 982 | TYPE(pedef), POINTER :: ape !< |
---|
| 983 | |
---|
| 984 | ! |
---|
[2599] | 985 | !-- First, count entries for every remote child process |
---|
[1933] | 986 | DO i = 1, mychild%inter_npes |
---|
| 987 | ape => mychild%pes(i) |
---|
[1900] | 988 | ape%nrele = 0 |
---|
| 989 | ENDDO |
---|
| 990 | ! |
---|
| 991 | !-- Loop over number of coarse grid cells |
---|
| 992 | DO j = 1, nrp |
---|
[2599] | 993 | rempe = index_list(5,j) + 1 ! process number on remote process |
---|
[1933] | 994 | ape => mychild%pes(rempe) |
---|
[2599] | 995 | ape%nrele = ape%nrele + 1 ! Increment number of elements for this child process |
---|
[1900] | 996 | ENDDO |
---|
| 997 | |
---|
[1933] | 998 | DO i = 1, mychild%inter_npes |
---|
| 999 | ape => mychild%pes(i) |
---|
[1900] | 1000 | ALLOCATE( ape%locind(ape%nrele) ) |
---|
| 1001 | ENDDO |
---|
| 1002 | |
---|
| 1003 | remind = 0 |
---|
| 1004 | ! |
---|
| 1005 | !-- Second, create lists |
---|
| 1006 | !-- Loop over number of coarse grid cells |
---|
| 1007 | DO j = 1, nrp |
---|
| 1008 | rempe = index_list(5,j) + 1 |
---|
[1933] | 1009 | ape => mychild%pes(rempe) |
---|
[1900] | 1010 | remind(rempe) = remind(rempe)+1 |
---|
| 1011 | ind = remind(rempe) |
---|
| 1012 | ape%locind(ind)%i = index_list(1,j) |
---|
| 1013 | ape%locind(ind)%j = index_list(2,j) |
---|
| 1014 | ENDDO |
---|
| 1015 | ! |
---|
[2599] | 1016 | !-- Prepare number of elements for children processes |
---|
[1933] | 1017 | CALL pmc_alloc_mem( rldef, mychild%inter_npes*2 ) |
---|
[1900] | 1018 | ! |
---|
[2599] | 1019 | !-- Number of child processes * size of INTEGER (i just arbitrary INTEGER) |
---|
[2809] | 1020 | winsize = mychild%inter_npes*STORAGE_SIZE(i)/8*2 |
---|
[1900] | 1021 | |
---|
[2801] | 1022 | CALL MPI_WIN_CREATE( rldef, winsize, iwp, MPI_INFO_NULL, & |
---|
[1933] | 1023 | mychild%intra_comm, indwin, ierr ) |
---|
[1900] | 1024 | ! |
---|
| 1025 | !-- Open window to set data |
---|
| 1026 | CALL MPI_WIN_FENCE( 0, indwin, ierr ) |
---|
| 1027 | |
---|
[2599] | 1028 | rldef(1) = 0 ! index on remote process 0 |
---|
| 1029 | rldef(2) = remind(1) ! number of elements on remote process 0 |
---|
[1900] | 1030 | ! |
---|
| 1031 | !-- Reserve buffer for index array |
---|
[1933] | 1032 | DO i = 2, mychild%inter_npes |
---|
[1900] | 1033 | i2 = (i-1) * 2 + 1 |
---|
[2599] | 1034 | rldef(i2) = rldef(i2-2) + rldef(i2-1) * 2 ! index on remote process |
---|
| 1035 | rldef(i2+1) = remind(i) ! number of elements on remote process |
---|
[1900] | 1036 | ENDDO |
---|
| 1037 | ! |
---|
[1933] | 1038 | !-- Close window to allow child to access data |
---|
[1900] | 1039 | CALL MPI_WIN_FENCE( 0, indwin, ierr ) |
---|
| 1040 | ! |
---|
[1933] | 1041 | !-- Child has retrieved data |
---|
[1900] | 1042 | CALL MPI_WIN_FENCE( 0, indwin, ierr ) |
---|
| 1043 | |
---|
[1933] | 1044 | i2 = 2 * mychild%inter_npes - 1 |
---|
[1900] | 1045 | winsize = ( rldef(i2) + rldef(i2+1) ) * 2 |
---|
| 1046 | ! |
---|
| 1047 | !-- Make sure, MPI_ALLOC_MEM works |
---|
| 1048 | winsize = MAX( winsize, 1 ) |
---|
| 1049 | |
---|
| 1050 | CALL pmc_alloc_mem( remindw, INT( winsize ) ) |
---|
| 1051 | |
---|
| 1052 | CALL MPI_BARRIER( m_model_comm, ierr ) |
---|
[2809] | 1053 | CALL MPI_WIN_CREATE( remindw, winsize*STORAGE_SIZE(i)/8, iwp, MPI_INFO_NULL, & |
---|
[1933] | 1054 | mychild%intra_comm, indwin2, ierr ) |
---|
[1900] | 1055 | ! |
---|
| 1056 | !-- Open window to set data |
---|
| 1057 | CALL MPI_WIN_FENCE( 0, indwin2, ierr ) |
---|
| 1058 | ! |
---|
| 1059 | !-- Create the 2D index list |
---|
| 1060 | DO j = 1, nrp |
---|
[2599] | 1061 | rempe = index_list(5,j) + 1 ! process number on remote process |
---|
[1933] | 1062 | ape => mychild%pes(rempe) |
---|
[1900] | 1063 | i2 = rempe * 2 - 1 |
---|
| 1064 | ind = rldef(i2) + 1 |
---|
| 1065 | remindw(ind) = index_list(3,j) |
---|
| 1066 | remindw(ind+1) = index_list(4,j) |
---|
| 1067 | rldef(i2) = rldef(i2)+2 |
---|
| 1068 | ENDDO |
---|
| 1069 | ! |
---|
[1933] | 1070 | !-- All data are set |
---|
[1900] | 1071 | CALL MPI_WIN_FENCE( 0, indwin2, ierr ) |
---|
| 1072 | ! |
---|
| 1073 | !-- Don't know why, but this barrier is necessary before windows can be freed |
---|
| 1074 | !-- TODO: find out why this is required |
---|
[1933] | 1075 | CALL MPI_BARRIER( mychild%intra_comm, ierr ) |
---|
[1900] | 1076 | |
---|
| 1077 | CALL MPI_WIN_FREE( indwin, ierr ) |
---|
| 1078 | CALL MPI_WIN_FREE( indwin2, ierr ) |
---|
| 1079 | |
---|
[1933] | 1080 | ! |
---|
[1900] | 1081 | !-- TODO: check if the following idea needs to be done |
---|
| 1082 | !-- Sollte funktionieren, Problem mit MPI implementation |
---|
| 1083 | !-- https://www.lrz.de/services/software/parallel/mpi/onesided |
---|
| 1084 | !-- CALL MPI_Free_mem (remindw, ierr) |
---|
| 1085 | |
---|
| 1086 | END SUBROUTINE set_pe_index_list |
---|
| 1087 | |
---|
[1764] | 1088 | #endif |
---|
[1933] | 1089 | END MODULE pmc_parent |
---|