[1682] | 1 | !> @file init_coupling.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[1036] | 3 | ! This file is part of PALM. |
---|
| 4 | ! |
---|
[2000] | 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. |
---|
[1036] | 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 | ! |
---|
[2101] | 17 | ! Copyright 1997-2017 Leibniz Universitaet Hannover |
---|
[2000] | 18 | !------------------------------------------------------------------------------! |
---|
[1036] | 19 | ! |
---|
[484] | 20 | ! Current revisions: |
---|
[206] | 21 | ! ----------------- |
---|
[2001] | 22 | ! |
---|
| 23 | ! |
---|
[1321] | 24 | ! Former revisions: |
---|
| 25 | ! ------------------ |
---|
| 26 | ! $Id: init_coupling.f90 2365 2017-08-21 14:59:59Z knoop $ |
---|
[2365] | 27 | ! Vertical nesting implemented (SadiqHuq) |
---|
| 28 | ! |
---|
| 29 | ! 2298 2017-06-29 09:28:18Z raasch |
---|
[2298] | 30 | ! MPI2 coupling removed |
---|
| 31 | ! |
---|
| 32 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1809] | 33 | ! |
---|
[2001] | 34 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 35 | ! Forced header and separation lines into 80 columns |
---|
| 36 | ! |
---|
[1809] | 37 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 38 | ! routine local_getenv replaced by standard FORTRAN routine |
---|
[1321] | 39 | ! |
---|
[1683] | 40 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 41 | ! Code annotations made doxygen readable |
---|
| 42 | ! |
---|
[1321] | 43 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 44 | ! ONLY-attribute added to USE-statements, |
---|
| 45 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 46 | ! kinds are defined in new module kinds, |
---|
| 47 | ! revision history before 2012 removed, |
---|
| 48 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 49 | ! all variable declaration statements |
---|
[206] | 50 | ! |
---|
[1037] | 51 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 52 | ! code put under GPL (PALM 3.9) |
---|
| 53 | ! |
---|
[226] | 54 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 55 | ! Initial revision |
---|
| 56 | ! |
---|
[206] | 57 | ! Description: |
---|
| 58 | ! ------------ |
---|
[1682] | 59 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
| 60 | !> called. |
---|
[206] | 61 | !------------------------------------------------------------------------------! |
---|
[1682] | 62 | SUBROUTINE init_coupling |
---|
| 63 | |
---|
[206] | 64 | |
---|
[1320] | 65 | USE control_parameters, & |
---|
| 66 | ONLY: coupling_char, coupling_mode |
---|
| 67 | |
---|
| 68 | USE kinds |
---|
| 69 | |
---|
[206] | 70 | USE pegrid |
---|
| 71 | |
---|
[2365] | 72 | USE vertical_nesting_mod |
---|
| 73 | |
---|
[206] | 74 | IMPLICIT NONE |
---|
| 75 | |
---|
| 76 | ! |
---|
| 77 | !-- Local variables |
---|
[1682] | 78 | INTEGER(iwp) :: i !< |
---|
| 79 | INTEGER(iwp) :: inter_color !< |
---|
[1320] | 80 | |
---|
[1682] | 81 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
[206] | 82 | |
---|
| 83 | ! |
---|
| 84 | !-- Get information about the coupling mode from the environment variable |
---|
| 85 | !-- which has been set by the mpiexec command. |
---|
| 86 | !-- This method is currently not used because the mpiexec command is not |
---|
| 87 | !-- available on some machines |
---|
[1808] | 88 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
[206] | 89 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
| 90 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
| 91 | |
---|
| 92 | ! |
---|
| 93 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
[2298] | 94 | !-- distribute it to the other PEs. Distribute PEs to 2 new communicators. |
---|
[206] | 95 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
[222] | 96 | #if defined ( __parallel ) |
---|
[667] | 97 | |
---|
[206] | 98 | IF ( myid == 0 ) THEN |
---|
| 99 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
| 100 | 10 CONTINUE |
---|
| 101 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
| 102 | i = 1 |
---|
[2365] | 103 | ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' ) THEN |
---|
| 104 | i = 9 |
---|
[206] | 105 | ELSE |
---|
| 106 | i = 0 |
---|
| 107 | ENDIF |
---|
[291] | 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 | |
---|
[206] | 115 | ENDIF |
---|
| 116 | |
---|
[291] | 117 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
[206] | 118 | i = bc_data(0) |
---|
| 119 | |
---|
[2365] | 120 | IF ( i == 0 ) THEN |
---|
[206] | 121 | coupling_mode = 'uncoupled' |
---|
[691] | 122 | ! |
---|
| 123 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
| 124 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
| 125 | IF ( bc_data(3) == 1 ) THEN |
---|
| 126 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
| 127 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 128 | CLOSE ( 90 ) |
---|
| 129 | ENDIF |
---|
[2365] | 130 | ELSEIF ( i == 9 ) THEN |
---|
| 131 | |
---|
| 132 | ! |
---|
| 133 | !-- Set a flag to identify runs with vertical nesting |
---|
| 134 | vnested = .TRUE. |
---|
| 135 | |
---|
| 136 | comm_inter = MPI_COMM_WORLD |
---|
| 137 | |
---|
| 138 | ! |
---|
| 139 | !-- Split the total available PE's into two groups |
---|
| 140 | !-- numprocs for Coarse and Fine Grid are specified via mrun argument -N |
---|
| 141 | IF ( myid < bc_data(1) ) THEN |
---|
| 142 | inter_color = 0 |
---|
| 143 | numprocs = bc_data(1) |
---|
| 144 | coupling_mode = 'vnested_crse' |
---|
| 145 | ELSE |
---|
| 146 | inter_color = 1 |
---|
| 147 | numprocs = bc_data(2) |
---|
| 148 | coupling_mode = 'vnested_fine' |
---|
| 149 | ENDIF |
---|
| 150 | |
---|
| 151 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 152 | comm2d = comm_palm |
---|
| 153 | |
---|
| 154 | OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 155 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 156 | CLOSE ( 90 ) |
---|
| 157 | |
---|
[206] | 158 | ELSE |
---|
| 159 | comm_inter = MPI_COMM_WORLD |
---|
| 160 | |
---|
| 161 | IF ( myid < bc_data(1) ) THEN |
---|
[667] | 162 | inter_color = 0 |
---|
| 163 | numprocs = bc_data(1) |
---|
| 164 | coupling_mode = 'atmosphere_to_ocean' |
---|
[206] | 165 | ELSE |
---|
[667] | 166 | inter_color = 1 |
---|
| 167 | numprocs = bc_data(2) |
---|
| 168 | coupling_mode = 'ocean_to_atmosphere' |
---|
[206] | 169 | ENDIF |
---|
[667] | 170 | |
---|
[206] | 171 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 172 | comm2d = comm_palm |
---|
| 173 | |
---|
| 174 | ! |
---|
| 175 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
| 176 | !-- processes. |
---|
| 177 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 178 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 179 | CLOSE ( 90 ) |
---|
| 180 | ENDIF |
---|
| 181 | #endif |
---|
| 182 | |
---|
[291] | 183 | ! |
---|
| 184 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
| 185 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
| 186 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
| 187 | THEN |
---|
| 188 | coupling_char = '_O' |
---|
| 189 | ENDIF |
---|
[206] | 190 | |
---|
[2365] | 191 | IF ( TRIM( coupling_mode ) == 'vnested_fine' ) THEN |
---|
| 192 | ! |
---|
| 193 | !-- Set file extension for vertical nesting |
---|
| 194 | coupling_char = '_N' |
---|
| 195 | ENDIF |
---|
| 196 | |
---|
[206] | 197 | END SUBROUTINE init_coupling |
---|