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 terms |
---|
6 | ! of the GNU General Public License as published by the Free Software Foundation, |
---|
7 | ! either version 3 of the License, or (at your option) any later version. |
---|
8 | ! |
---|
9 | ! PALM is distributed in the hope that it will be useful, but WITHOUT ANY |
---|
10 | ! WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR |
---|
11 | ! A PARTICULAR PURPOSE. See the GNU General Public License for more details. |
---|
12 | ! |
---|
13 | ! You should have received a copy of the GNU General Public License along with |
---|
14 | ! PALM. If not, see <http://www.gnu.org/licenses/>. |
---|
15 | ! |
---|
16 | ! Copyright 1997-2014 Leibniz Universitaet Hannover |
---|
17 | !--------------------------------------------------------------------------------! |
---|
18 | ! |
---|
19 | ! Current revisions: |
---|
20 | ! ----------------- |
---|
21 | ! Code annotations made doxygen readable |
---|
22 | ! |
---|
23 | ! Former revisions: |
---|
24 | ! ------------------ |
---|
25 | ! $Id: init_coupling.f90 1682 2015-10-07 23:56:08Z knoop $ |
---|
26 | ! |
---|
27 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
28 | ! ONLY-attribute added to USE-statements, |
---|
29 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
30 | ! kinds are defined in new module kinds, |
---|
31 | ! revision history before 2012 removed, |
---|
32 | ! comment fields (!:) to be used for variable explanations added to |
---|
33 | ! all variable declaration statements |
---|
34 | ! |
---|
35 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
36 | ! code put under GPL (PALM 3.9) |
---|
37 | ! |
---|
38 | ! 222 2009-01-12 16:04:16Z letzel |
---|
39 | ! Initial revision |
---|
40 | ! |
---|
41 | ! Description: |
---|
42 | ! ------------ |
---|
43 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
44 | !> called. |
---|
45 | !------------------------------------------------------------------------------! |
---|
46 | SUBROUTINE init_coupling |
---|
47 | |
---|
48 | |
---|
49 | USE control_parameters, & |
---|
50 | ONLY: coupling_char, coupling_mode |
---|
51 | |
---|
52 | USE kinds |
---|
53 | |
---|
54 | USE pegrid |
---|
55 | |
---|
56 | IMPLICIT NONE |
---|
57 | |
---|
58 | ! |
---|
59 | !-- Local variables |
---|
60 | INTEGER(iwp) :: i !< |
---|
61 | INTEGER(iwp) :: inter_color !< |
---|
62 | |
---|
63 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
64 | |
---|
65 | ! |
---|
66 | !-- Get information about the coupling mode from the environment variable |
---|
67 | !-- which has been set by the mpiexec command. |
---|
68 | !-- This method is currently not used because the mpiexec command is not |
---|
69 | !-- available on some machines |
---|
70 | ! CALL local_getenv( 'coupling_mode', 13, coupling_mode, i ) |
---|
71 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
72 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
73 | |
---|
74 | ! |
---|
75 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
76 | !-- distribute it to the other PEs. If __mpi2 was defined, suggest a |
---|
77 | !-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only. |
---|
78 | !-- In this case, distribute PEs to 2 new communicators. |
---|
79 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
80 | #if defined ( __parallel ) |
---|
81 | |
---|
82 | !myid_absolut = myid |
---|
83 | IF ( myid == 0 ) THEN |
---|
84 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
85 | 10 CONTINUE |
---|
86 | #if defined( __mpi2 ) |
---|
87 | IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN |
---|
88 | i = 1 |
---|
89 | ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' ) THEN |
---|
90 | i = 2 |
---|
91 | ELSE |
---|
92 | i = 0 |
---|
93 | ENDIF |
---|
94 | #else |
---|
95 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
96 | i = 1 |
---|
97 | ELSE |
---|
98 | i = 0 |
---|
99 | ENDIF |
---|
100 | #endif |
---|
101 | bc_data(0) = i |
---|
102 | |
---|
103 | ! |
---|
104 | !-- Check if '_O' has to be used as file extension in an uncoupled ocean |
---|
105 | !-- run. This is required, if this run shall be continued as a coupled run. |
---|
106 | IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 |
---|
107 | |
---|
108 | ENDIF |
---|
109 | |
---|
110 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
111 | i = bc_data(0) |
---|
112 | |
---|
113 | #if defined ( __mpi2 ) |
---|
114 | IF ( i == 0 ) THEN |
---|
115 | coupling_mode = 'uncoupled' |
---|
116 | ELSEIF ( i == 1 ) THEN |
---|
117 | coupling_mode = 'atmosphere_to_ocean' |
---|
118 | ELSEIF ( i == 2 ) THEN |
---|
119 | coupling_mode = 'ocean_to_atmosphere' |
---|
120 | ENDIF |
---|
121 | target_id = myid |
---|
122 | #else |
---|
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 | ELSE |
---|
134 | comm_inter = MPI_COMM_WORLD |
---|
135 | |
---|
136 | IF ( myid < bc_data(1) ) THEN |
---|
137 | inter_color = 0 |
---|
138 | numprocs = bc_data(1) |
---|
139 | coupling_mode = 'atmosphere_to_ocean' |
---|
140 | ELSE |
---|
141 | inter_color = 1 |
---|
142 | numprocs = bc_data(2) |
---|
143 | coupling_mode = 'ocean_to_atmosphere' |
---|
144 | ENDIF |
---|
145 | |
---|
146 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
147 | comm2d = comm_palm |
---|
148 | |
---|
149 | ! |
---|
150 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
151 | !-- processes. |
---|
152 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
153 | WRITE ( 90, '(''TRUE'')' ) |
---|
154 | CLOSE ( 90 ) |
---|
155 | ENDIF |
---|
156 | #endif |
---|
157 | #endif |
---|
158 | |
---|
159 | ! |
---|
160 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
161 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
162 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
163 | THEN |
---|
164 | coupling_char = '_O' |
---|
165 | ENDIF |
---|
166 | |
---|
167 | END SUBROUTINE init_coupling |
---|