source: palm/trunk/SOURCE/init_coupling.f90 @ 1320

Last change on this file since 1320 was 1320, checked in by raasch, 7 years ago

ONLY-attribute added to USE-statements,
kind-parameters added to all INTEGER and REAL declaration statements,
kinds are defined in new module kinds,
old module precision_kind is removed,
revision history before 2012 removed,
comment fields (!:) to be used for variable explanations added to all variable declaration statements

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