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

Last change on this file since 1036 was 1036, checked in by raasch, 11 years ago

code has been put under the GNU General Public License (v3)

  • 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 1036 2012-10-22 13:43:42Z raasch $
27!
28! 709 2011-03-30 09:31:40Z raasch
29! formatting adjustments
30!
31! 691 2011-03-04 08:45:30Z maronga
32! Bugfix: combine_plot_fields did not work with data_output_2d_on_each_pe = .T.
33! for precursor ocean runs
34!
35! 667 2010-12-23 12:06:00Z suehring/gryschka
36! determination of target_id's moved to init_pegrid
37!
38! 291 2009-04-16 12:07:26Z raasch
39! Coupling with independent precursor runs.
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
50    USE pegrid
51    USE control_parameters
52    USE indices
53
54    IMPLICIT NONE
55
56!
57!-- Local variables
58    INTEGER               ::  i, inter_color
59    INTEGER, DIMENSION(:) ::  bc_data(0:3) = 0
60
61!
62!-- Get information about the coupling mode from the environment variable
63!-- which has been set by the mpiexec command.
64!-- This method is currently not used because the mpiexec command is not
65!-- available on some machines
66!    CALL local_getenv( 'coupling_mode', 13, coupling_mode, i )
67!    IF ( i == 0 )  coupling_mode = 'uncoupled'
68!    IF ( coupling_mode == 'ocean_to_atmosphere' )  coupling_char = '_O'
69
70!
71!-- Get information about the coupling mode from standard input (PE0 only) and
72!-- distribute it to the other PEs. If __mpi2 was defined, suggest a
73!-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only.
74!-- In this case, distribute PEs to 2 new communicators.
75!-- ATTENTION: numprocs will be reset according to the new communicators
76#if defined ( __parallel )
77
78!myid_absolut = myid
79    IF ( myid == 0 )  THEN
80       READ (*,*,ERR=10,END=10)  coupling_mode, bc_data(1), bc_data(2)
8110     CONTINUE
82#if defined( __mpi2 )
83       IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' )  THEN
84          i = 1
85       ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' )  THEN
86          i = 2
87       ELSE
88          i = 0
89       ENDIF
90#else
91       IF ( TRIM( coupling_mode ) == 'coupled_run' )  THEN
92          i = 1
93       ELSE
94          i = 0
95       ENDIF
96#endif
97       bc_data(0) = i
98
99!
100!--    Check if '_O' has to be used as file extension in an uncoupled ocean
101!--    run. This is required, if this run shall be continued as a coupled run.
102       IF ( TRIM( coupling_mode ) == 'precursor_ocean' )  bc_data(3) = 1
103
104    ENDIF
105
106    CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr )
107    i = bc_data(0)
108
109#if defined ( __mpi2 )
110    IF ( i == 0 )  THEN
111       coupling_mode = 'uncoupled'
112    ELSEIF ( i == 1 )  THEN
113       coupling_mode = 'atmosphere_to_ocean'
114    ELSEIF ( i == 2 )  THEN
115       coupling_mode = 'ocean_to_atmosphere'
116    ENDIF
117    target_id = myid
118#else
119    IF ( i == 0 ) THEN
120       coupling_mode = 'uncoupled'
121!
122!--    In case of a precursor ocean run, an additional flag file is created.
123!--    This is necessary for data_output_2d_on_each_pe = .T.
124       IF ( bc_data(3) == 1 )  THEN
125          OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' )
126          WRITE ( 90, '(''TRUE'')' )
127          CLOSE ( 90 )
128       ENDIF
129    ELSE
130       comm_inter = MPI_COMM_WORLD
131
132       IF ( myid < bc_data(1) ) THEN
133          inter_color     = 0
134          numprocs        = bc_data(1)
135          coupling_mode   = 'atmosphere_to_ocean'
136       ELSE
137          inter_color     = 1
138          numprocs        = bc_data(2)
139          coupling_mode   = 'ocean_to_atmosphere'
140       ENDIF
141
142       CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr )
143       comm2d = comm_palm
144
145!
146!--    Write a flag file for the ocean model and the other atmosphere
147!--    processes.
148       OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' )
149       WRITE ( 90, '(''TRUE'')' )
150       CLOSE ( 90 )
151    ENDIF
152#endif
153#endif
154
155!
156!-- In case of a precursor ocean run (followed by a coupled run), or a
157!-- coupled atmosphere-ocean run, set the file extension for the ocean files
158    IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) &
159    THEN
160       coupling_char = '_O'
161    ENDIF
162
163 END SUBROUTINE init_coupling
Note: See TracBrowser for help on using the repository browser.