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