1 | !> @file init_coupling.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of PALM. |
---|
4 | ! |
---|
5 | ! PALM is free software: you can redistribute it and/or modify it under the |
---|
6 | ! terms of the GNU General Public License as published by the Free Software |
---|
7 | ! Foundation, either version 3 of the License, or (at your option) any later |
---|
8 | ! version. |
---|
9 | ! |
---|
10 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
11 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
12 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
13 | ! |
---|
14 | ! You should have received a copy of the GNU General Public License along with |
---|
15 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
16 | ! |
---|
17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ------------------ |
---|
26 | ! $Id: init_coupling.f90 2669 2017-12-06 16:03:27Z basit $ |
---|
27 | ! file extension for vertical nesting changed to "_NV" |
---|
28 | ! |
---|
29 | ! 2365 2017-08-21 14:59:59Z kanani |
---|
30 | ! Vertical nesting implemented (SadiqHuq) |
---|
31 | ! |
---|
32 | ! 2298 2017-06-29 09:28:18Z raasch |
---|
33 | ! MPI2 coupling removed |
---|
34 | ! |
---|
35 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
36 | ! |
---|
37 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
38 | ! Forced header and separation lines into 80 columns |
---|
39 | ! |
---|
40 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
41 | ! routine local_getenv replaced by standard FORTRAN routine |
---|
42 | ! |
---|
43 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
44 | ! Code annotations made doxygen readable |
---|
45 | ! |
---|
46 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
47 | ! ONLY-attribute added to USE-statements, |
---|
48 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
49 | ! kinds are defined in new module kinds, |
---|
50 | ! revision history before 2012 removed, |
---|
51 | ! comment fields (!:) to be used for variable explanations added to |
---|
52 | ! all variable declaration statements |
---|
53 | ! |
---|
54 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
55 | ! code put under GPL (PALM 3.9) |
---|
56 | ! |
---|
57 | ! 222 2009-01-12 16:04:16Z letzel |
---|
58 | ! Initial revision |
---|
59 | ! |
---|
60 | ! Description: |
---|
61 | ! ------------ |
---|
62 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
63 | !> called. |
---|
64 | !------------------------------------------------------------------------------! |
---|
65 | SUBROUTINE init_coupling |
---|
66 | |
---|
67 | |
---|
68 | USE control_parameters, & |
---|
69 | ONLY: coupling_char, coupling_mode |
---|
70 | |
---|
71 | USE kinds |
---|
72 | |
---|
73 | USE pegrid |
---|
74 | |
---|
75 | USE vertical_nesting_mod |
---|
76 | |
---|
77 | IMPLICIT NONE |
---|
78 | |
---|
79 | ! |
---|
80 | !-- Local variables |
---|
81 | INTEGER(iwp) :: i !< |
---|
82 | INTEGER(iwp) :: inter_color !< |
---|
83 | |
---|
84 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
85 | |
---|
86 | ! |
---|
87 | !-- Get information about the coupling mode from the environment variable |
---|
88 | !-- which has been set by the mpiexec command. |
---|
89 | !-- This method is currently not used because the mpiexec command is not |
---|
90 | !-- available on some machines |
---|
91 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
92 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
93 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
94 | |
---|
95 | ! |
---|
96 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
97 | !-- distribute it to the other PEs. Distribute PEs to 2 new communicators. |
---|
98 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
99 | #if defined ( __parallel ) |
---|
100 | |
---|
101 | IF ( myid == 0 ) THEN |
---|
102 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
103 | 10 CONTINUE |
---|
104 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
105 | i = 1 |
---|
106 | ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' ) THEN |
---|
107 | i = 9 |
---|
108 | ELSE |
---|
109 | i = 0 |
---|
110 | ENDIF |
---|
111 | bc_data(0) = i |
---|
112 | |
---|
113 | ! |
---|
114 | !-- Check if '_O' has to be used as file extension in an uncoupled ocean |
---|
115 | !-- run. This is required, if this run shall be continued as a coupled run. |
---|
116 | IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 |
---|
117 | |
---|
118 | ENDIF |
---|
119 | |
---|
120 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
121 | i = bc_data(0) |
---|
122 | |
---|
123 | IF ( i == 0 ) THEN |
---|
124 | coupling_mode = 'uncoupled' |
---|
125 | ! |
---|
126 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
127 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
128 | IF ( bc_data(3) == 1 ) THEN |
---|
129 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
130 | WRITE ( 90, '(''TRUE'')' ) |
---|
131 | CLOSE ( 90 ) |
---|
132 | ENDIF |
---|
133 | ELSEIF ( i == 9 ) THEN |
---|
134 | |
---|
135 | ! |
---|
136 | !-- Set a flag to identify runs with vertical nesting |
---|
137 | vnested = .TRUE. |
---|
138 | |
---|
139 | comm_inter = MPI_COMM_WORLD |
---|
140 | |
---|
141 | ! |
---|
142 | !-- Split the total available PE's into two groups |
---|
143 | !-- numprocs for Coarse and Fine Grid are specified via mrun argument -N |
---|
144 | IF ( myid < bc_data(1) ) THEN |
---|
145 | inter_color = 0 |
---|
146 | numprocs = bc_data(1) |
---|
147 | coupling_mode = 'vnested_crse' |
---|
148 | ELSE |
---|
149 | inter_color = 1 |
---|
150 | numprocs = bc_data(2) |
---|
151 | coupling_mode = 'vnested_fine' |
---|
152 | ENDIF |
---|
153 | |
---|
154 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
155 | comm2d = comm_palm |
---|
156 | |
---|
157 | OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' ) |
---|
158 | WRITE ( 90, '(''TRUE'')' ) |
---|
159 | CLOSE ( 90 ) |
---|
160 | |
---|
161 | ELSE |
---|
162 | comm_inter = MPI_COMM_WORLD |
---|
163 | |
---|
164 | IF ( myid < bc_data(1) ) THEN |
---|
165 | inter_color = 0 |
---|
166 | numprocs = bc_data(1) |
---|
167 | coupling_mode = 'atmosphere_to_ocean' |
---|
168 | ELSE |
---|
169 | inter_color = 1 |
---|
170 | numprocs = bc_data(2) |
---|
171 | coupling_mode = 'ocean_to_atmosphere' |
---|
172 | ENDIF |
---|
173 | |
---|
174 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
175 | comm2d = comm_palm |
---|
176 | |
---|
177 | ! |
---|
178 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
179 | !-- processes. |
---|
180 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
181 | WRITE ( 90, '(''TRUE'')' ) |
---|
182 | CLOSE ( 90 ) |
---|
183 | ENDIF |
---|
184 | #endif |
---|
185 | |
---|
186 | ! |
---|
187 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
188 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
189 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
190 | THEN |
---|
191 | coupling_char = '_O' |
---|
192 | ENDIF |
---|
193 | |
---|
194 | IF ( TRIM( coupling_mode ) == 'vnested_fine' ) THEN |
---|
195 | ! |
---|
196 | !-- Set file extension for vertical nesting |
---|
197 | coupling_char = '_NV' |
---|
198 | ENDIF |
---|
199 | |
---|
200 | END SUBROUTINE init_coupling |
---|