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

Last change on this file since 2756 was 2718, checked in by maronga, 7 years ago

deleting of deprecated files; headers updated where needed

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