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

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

Forced header and separation lines into 80 columns

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