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

Last change on this file since 1951 was 1818, checked in by maronga, 9 years ago

last commit documented / copyright update

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