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

Last change on this file since 3677 was 3655, checked in by knoop, 6 years ago

Bugfix: made "unit" and "found" intend INOUT in module interface subroutines + automatic copyright update

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