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

Last change on this file since 1723 was 1683, checked in by knoop, 8 years ago

last commit documented

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