source: palm/trunk/SOURCE/pmc_general_mod.f90 @ 3210

Last change on this file since 3210 was 2841, checked in by knoop, 7 years ago

Bugfix: wrong placement of include 'mpif.h' corrected

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