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-2016 Leibniz Universitaet Hannover |
---|
18 | !------------------------------------------------------------------------------! |
---|
19 | ! |
---|
20 | ! Current revisions: |
---|
21 | ! ----------------- |
---|
22 | ! |
---|
23 | ! |
---|
24 | ! Former revisions: |
---|
25 | ! ------------------ |
---|
26 | ! $Id: init_coupling.f90 2001 2016-08-20 18:41:22Z knoop $ |
---|
27 | ! |
---|
28 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
29 | ! Forced header and separation lines into 80 columns |
---|
30 | ! |
---|
31 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
32 | ! routine local_getenv replaced by standard FORTRAN routine |
---|
33 | ! |
---|
34 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
35 | ! Code annotations made doxygen readable |
---|
36 | ! |
---|
37 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
38 | ! ONLY-attribute added to USE-statements, |
---|
39 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
40 | ! kinds are defined in new module kinds, |
---|
41 | ! revision history before 2012 removed, |
---|
42 | ! comment fields (!:) to be used for variable explanations added to |
---|
43 | ! all variable declaration statements |
---|
44 | ! |
---|
45 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
46 | ! code put under GPL (PALM 3.9) |
---|
47 | ! |
---|
48 | ! 222 2009-01-12 16:04:16Z letzel |
---|
49 | ! Initial revision |
---|
50 | ! |
---|
51 | ! Description: |
---|
52 | ! ------------ |
---|
53 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
54 | !> called. |
---|
55 | !------------------------------------------------------------------------------! |
---|
56 | SUBROUTINE init_coupling |
---|
57 | |
---|
58 | |
---|
59 | USE control_parameters, & |
---|
60 | ONLY: coupling_char, coupling_mode |
---|
61 | |
---|
62 | USE kinds |
---|
63 | |
---|
64 | USE pegrid |
---|
65 | |
---|
66 | IMPLICIT NONE |
---|
67 | |
---|
68 | ! |
---|
69 | !-- Local variables |
---|
70 | INTEGER(iwp) :: i !< |
---|
71 | INTEGER(iwp) :: inter_color !< |
---|
72 | |
---|
73 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
74 | |
---|
75 | ! |
---|
76 | !-- Get information about the coupling mode from the environment variable |
---|
77 | !-- which has been set by the mpiexec command. |
---|
78 | !-- This method is currently not used because the mpiexec command is not |
---|
79 | !-- available on some machines |
---|
80 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
81 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
82 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
83 | |
---|
84 | ! |
---|
85 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
86 | !-- distribute it to the other PEs. If __mpi2 was defined, suggest a |
---|
87 | !-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only. |
---|
88 | !-- In this case, distribute PEs to 2 new communicators. |
---|
89 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
90 | #if defined ( __parallel ) |
---|
91 | |
---|
92 | !myid_absolut = myid |
---|
93 | IF ( myid == 0 ) THEN |
---|
94 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
95 | 10 CONTINUE |
---|
96 | #if defined( __mpi2 ) |
---|
97 | IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN |
---|
98 | i = 1 |
---|
99 | ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' ) THEN |
---|
100 | i = 2 |
---|
101 | ELSE |
---|
102 | i = 0 |
---|
103 | ENDIF |
---|
104 | #else |
---|
105 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
106 | i = 1 |
---|
107 | ELSE |
---|
108 | i = 0 |
---|
109 | ENDIF |
---|
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 defined ( __mpi2 ) |
---|
124 | IF ( i == 0 ) THEN |
---|
125 | coupling_mode = 'uncoupled' |
---|
126 | ELSEIF ( i == 1 ) THEN |
---|
127 | coupling_mode = 'atmosphere_to_ocean' |
---|
128 | ELSEIF ( i == 2 ) THEN |
---|
129 | coupling_mode = 'ocean_to_atmosphere' |
---|
130 | ENDIF |
---|
131 | target_id = myid |
---|
132 | #else |
---|
133 | IF ( i == 0 ) THEN |
---|
134 | coupling_mode = 'uncoupled' |
---|
135 | ! |
---|
136 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
137 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
138 | IF ( bc_data(3) == 1 ) THEN |
---|
139 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
140 | WRITE ( 90, '(''TRUE'')' ) |
---|
141 | CLOSE ( 90 ) |
---|
142 | ENDIF |
---|
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 | #endif |
---|
168 | |
---|
169 | ! |
---|
170 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
171 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
172 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
173 | THEN |
---|
174 | coupling_char = '_O' |
---|
175 | ENDIF |
---|
176 | |
---|
177 | END SUBROUTINE init_coupling |
---|