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

Last change on this file since 1274 was 1037, checked in by raasch, 12 years ago

last commit documented

  • Property svn:keywords set to Id
File size: 5.0 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-2012  Leibniz University Hannover
18!--------------------------------------------------------------------------------!
19!
20! Current revisions:
21! -----------------
22!
23!
24! Former revisions:
25! ------------------
26! $Id: init_coupling.f90 1037 2012-10-22 14:10:22Z heinze $
27!
28! 1036 2012-10-22 13:43:42Z raasch
29! code put under GPL (PALM 3.9)
30!
31! 709 2011-03-30 09:31:40Z raasch
32! formatting adjustments
33!
34! 691 2011-03-04 08:45:30Z maronga
35! Bugfix: combine_plot_fields did not work with data_output_2d_on_each_pe = .T.
36! for precursor ocean runs
37!
38! 667 2010-12-23 12:06:00Z suehring/gryschka
39! determination of target_id's moved to init_pegrid
40!
41! 291 2009-04-16 12:07:26Z raasch
42! Coupling with independent precursor runs.
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
53    USE pegrid
54    USE control_parameters
55    USE indices
56
57    IMPLICIT NONE
58
59!
60!-- Local variables
61    INTEGER               ::  i, inter_color
62    INTEGER, 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)
8410     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
Note: See TracBrowser for help on using the repository browser.