1 | !> @file init_coupling.f90 |
---|
2 | !------------------------------------------------------------------------------! |
---|
3 | ! This file is part of the PALM model system. |
---|
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-2020 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ------------------ |
---|
26 | ! $Id: init_coupling.f90 4444 2020-03-05 15:59:50Z moh.hefny $ |
---|
27 | ! bugfix: cpp-directives for serial mode added |
---|
28 | ! |
---|
29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
30 | ! Corrected "Former revisions" section |
---|
31 | ! |
---|
32 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
33 | ! references to mrun replaced by palmrun, and updated |
---|
34 | ! |
---|
35 | ! 222 2009-01-12 16:04:16Z letzel |
---|
36 | ! Initial revision |
---|
37 | ! |
---|
38 | ! Description: |
---|
39 | ! ------------ |
---|
40 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
41 | !> called. |
---|
42 | !------------------------------------------------------------------------------! |
---|
43 | SUBROUTINE init_coupling |
---|
44 | |
---|
45 | |
---|
46 | USE control_parameters, & |
---|
47 | ONLY: coupling_char, coupling_mode |
---|
48 | |
---|
49 | USE kinds |
---|
50 | |
---|
51 | USE pegrid |
---|
52 | |
---|
53 | USE vertical_nesting_mod |
---|
54 | |
---|
55 | IMPLICIT NONE |
---|
56 | |
---|
57 | ! |
---|
58 | !-- Local variables |
---|
59 | #if defined( __parallel ) |
---|
60 | INTEGER(iwp) :: i !< |
---|
61 | INTEGER(iwp) :: inter_color !< |
---|
62 | #endif |
---|
63 | |
---|
64 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
65 | |
---|
66 | ! |
---|
67 | !-- Get information about the coupling mode from the environment variable |
---|
68 | !-- which has been set by the mpiexec command. |
---|
69 | !-- This method is currently not used because the mpiexec command is not |
---|
70 | !-- available on some machines |
---|
71 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
72 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
73 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
74 | |
---|
75 | ! |
---|
76 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
77 | !-- distribute it to the other PEs. Distribute PEs to 2 new communicators. |
---|
78 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
79 | #if defined ( __parallel ) |
---|
80 | |
---|
81 | IF ( myid == 0 ) THEN |
---|
82 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
83 | 10 CONTINUE |
---|
84 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
85 | i = 1 |
---|
86 | ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' ) THEN |
---|
87 | i = 9 |
---|
88 | ELSE |
---|
89 | i = 0 |
---|
90 | ENDIF |
---|
91 | bc_data(0) = i |
---|
92 | |
---|
93 | ! |
---|
94 | !-- Check if '_O' has to be used as file extension in an uncoupled ocean |
---|
95 | !-- run. This is required, if this run shall be continued as a coupled run. |
---|
96 | IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 |
---|
97 | |
---|
98 | ENDIF |
---|
99 | |
---|
100 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
101 | i = bc_data(0) |
---|
102 | |
---|
103 | IF ( i == 0 ) THEN |
---|
104 | coupling_mode = 'uncoupled' |
---|
105 | ! |
---|
106 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
107 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
108 | IF ( bc_data(3) == 1 ) THEN |
---|
109 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
110 | WRITE ( 90, '(''TRUE'')' ) |
---|
111 | CLOSE ( 90 ) |
---|
112 | ENDIF |
---|
113 | ELSEIF ( i == 9 ) THEN |
---|
114 | |
---|
115 | ! |
---|
116 | !-- Set a flag to identify runs with vertical nesting |
---|
117 | vnested = .TRUE. |
---|
118 | |
---|
119 | comm_inter = MPI_COMM_WORLD |
---|
120 | |
---|
121 | ! |
---|
122 | !-- Split the total available PE's into two groups |
---|
123 | !-- numprocs for coarse and fine grid are read from stdin (see above, and |
---|
124 | !-- execution command in the palmrun script, numprocs are provided via |
---|
125 | !-- palmrun option -Y) |
---|
126 | IF ( myid < bc_data(1) ) THEN |
---|
127 | inter_color = 0 |
---|
128 | numprocs = bc_data(1) |
---|
129 | coupling_mode = 'vnested_crse' |
---|
130 | ELSE |
---|
131 | inter_color = 1 |
---|
132 | numprocs = bc_data(2) |
---|
133 | coupling_mode = 'vnested_fine' |
---|
134 | ENDIF |
---|
135 | |
---|
136 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
137 | comm2d = comm_palm |
---|
138 | |
---|
139 | OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' ) |
---|
140 | WRITE ( 90, '(''TRUE'')' ) |
---|
141 | CLOSE ( 90 ) |
---|
142 | |
---|
143 | ELSE |
---|
144 | comm_inter = MPI_COMM_WORLD |
---|
145 | |
---|
146 | IF ( myid < bc_data(1) ) THEN |
---|
147 | inter_color = 0 |
---|
148 | numprocs = bc_data(1) |
---|
149 | coupling_mode = 'atmosphere_to_ocean' |
---|
150 | ELSE |
---|
151 | inter_color = 1 |
---|
152 | numprocs = bc_data(2) |
---|
153 | coupling_mode = 'ocean_to_atmosphere' |
---|
154 | ENDIF |
---|
155 | |
---|
156 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
157 | comm2d = comm_palm |
---|
158 | |
---|
159 | ! |
---|
160 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
161 | !-- processes. |
---|
162 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
163 | WRITE ( 90, '(''TRUE'')' ) |
---|
164 | CLOSE ( 90 ) |
---|
165 | ENDIF |
---|
166 | #endif |
---|
167 | |
---|
168 | ! |
---|
169 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
170 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
171 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
172 | THEN |
---|
173 | coupling_char = '_O' |
---|
174 | ENDIF |
---|
175 | |
---|
176 | IF ( TRIM( coupling_mode ) == 'vnested_fine' ) THEN |
---|
177 | ! |
---|
178 | !-- Set file extension for vertical nesting |
---|
179 | coupling_char = '_NV' |
---|
180 | ENDIF |
---|
181 | |
---|
182 | END SUBROUTINE init_coupling |
---|