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

Last change on this file since 1682 was 1682, checked in by knoop, 9 years ago

Code annotations made doxygen readable

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