[1682] | 1 | !> @file init_coupling.f90 |
---|
[2000] | 2 | !------------------------------------------------------------------------------! |
---|
[2696] | 3 | ! This file is part of the PALM model system. |
---|
[1036] | 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 | ! |
---|
[4360] | 17 | ! Copyright 1997-2020 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 4444 2020-03-05 15:59:50Z maronga $ |
---|
[4444] | 27 | ! bugfix: cpp-directives for serial mode added |
---|
| 28 | ! |
---|
| 29 | ! 4360 2020-01-07 11:25:50Z suehring |
---|
[4182] | 30 | ! Corrected "Former revisions" section |
---|
| 31 | ! |
---|
| 32 | ! 3655 2019-01-07 16:51:22Z knoop |
---|
[3232] | 33 | ! references to mrun replaced by palmrun, and updated |
---|
[2716] | 34 | ! |
---|
[4182] | 35 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 36 | ! Initial revision |
---|
| 37 | ! |
---|
[206] | 38 | ! Description: |
---|
| 39 | ! ------------ |
---|
[1682] | 40 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
| 41 | !> called. |
---|
[206] | 42 | !------------------------------------------------------------------------------! |
---|
[1682] | 43 | SUBROUTINE init_coupling |
---|
| 44 | |
---|
[206] | 45 | |
---|
[1320] | 46 | USE control_parameters, & |
---|
| 47 | ONLY: coupling_char, coupling_mode |
---|
| 48 | |
---|
| 49 | USE kinds |
---|
| 50 | |
---|
[206] | 51 | USE pegrid |
---|
| 52 | |
---|
[2365] | 53 | USE vertical_nesting_mod |
---|
| 54 | |
---|
[206] | 55 | IMPLICIT NONE |
---|
| 56 | |
---|
| 57 | ! |
---|
| 58 | !-- Local variables |
---|
[4444] | 59 | #if defined( __parallel ) |
---|
[1682] | 60 | INTEGER(iwp) :: i !< |
---|
| 61 | INTEGER(iwp) :: inter_color !< |
---|
[4444] | 62 | #endif |
---|
[1320] | 63 | |
---|
[1682] | 64 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
[206] | 65 | |
---|
| 66 | ! |
---|
| 67 | !-- Get information about the coupling mode from the environment variable |
---|
| 68 | !-- which has been set by the mpiexec command. |
---|
| 69 | !-- This method is currently not used because the mpiexec command is not |
---|
| 70 | !-- available on some machines |
---|
[1808] | 71 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
[206] | 72 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
| 73 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
| 74 | |
---|
| 75 | ! |
---|
| 76 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
[2298] | 77 | !-- distribute it to the other PEs. Distribute PEs to 2 new communicators. |
---|
[206] | 78 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
[222] | 79 | #if defined ( __parallel ) |
---|
[667] | 80 | |
---|
[206] | 81 | IF ( myid == 0 ) THEN |
---|
| 82 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
| 83 | 10 CONTINUE |
---|
| 84 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
| 85 | i = 1 |
---|
[2365] | 86 | ELSEIF ( TRIM( coupling_mode ) == 'vnested_twi' ) THEN |
---|
| 87 | i = 9 |
---|
[206] | 88 | ELSE |
---|
| 89 | i = 0 |
---|
| 90 | ENDIF |
---|
[291] | 91 | bc_data(0) = i |
---|
| 92 | |
---|
| 93 | ! |
---|
| 94 | !-- Check if '_O' has to be used as file extension in an uncoupled ocean |
---|
| 95 | !-- run. This is required, if this run shall be continued as a coupled run. |
---|
| 96 | IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 |
---|
| 97 | |
---|
[206] | 98 | ENDIF |
---|
| 99 | |
---|
[291] | 100 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
[206] | 101 | i = bc_data(0) |
---|
| 102 | |
---|
[2365] | 103 | IF ( i == 0 ) THEN |
---|
[206] | 104 | coupling_mode = 'uncoupled' |
---|
[691] | 105 | ! |
---|
| 106 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
| 107 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
| 108 | IF ( bc_data(3) == 1 ) THEN |
---|
| 109 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
| 110 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 111 | CLOSE ( 90 ) |
---|
| 112 | ENDIF |
---|
[2365] | 113 | ELSEIF ( i == 9 ) THEN |
---|
| 114 | |
---|
| 115 | ! |
---|
| 116 | !-- Set a flag to identify runs with vertical nesting |
---|
| 117 | vnested = .TRUE. |
---|
| 118 | |
---|
| 119 | comm_inter = MPI_COMM_WORLD |
---|
| 120 | |
---|
| 121 | ! |
---|
| 122 | !-- Split the total available PE's into two groups |
---|
[3232] | 123 | !-- numprocs for coarse and fine grid are read from stdin (see above, and |
---|
| 124 | !-- execution command in the palmrun script, numprocs are provided via |
---|
| 125 | !-- palmrun option -Y) |
---|
[2365] | 126 | IF ( myid < bc_data(1) ) THEN |
---|
| 127 | inter_color = 0 |
---|
| 128 | numprocs = bc_data(1) |
---|
| 129 | coupling_mode = 'vnested_crse' |
---|
| 130 | ELSE |
---|
| 131 | inter_color = 1 |
---|
| 132 | numprocs = bc_data(2) |
---|
| 133 | coupling_mode = 'vnested_fine' |
---|
| 134 | ENDIF |
---|
| 135 | |
---|
| 136 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 137 | comm2d = comm_palm |
---|
| 138 | |
---|
| 139 | OPEN( 90, FILE='VNESTING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 140 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 141 | CLOSE ( 90 ) |
---|
| 142 | |
---|
[206] | 143 | ELSE |
---|
| 144 | comm_inter = MPI_COMM_WORLD |
---|
| 145 | |
---|
| 146 | IF ( myid < bc_data(1) ) THEN |
---|
[667] | 147 | inter_color = 0 |
---|
| 148 | numprocs = bc_data(1) |
---|
| 149 | coupling_mode = 'atmosphere_to_ocean' |
---|
[206] | 150 | ELSE |
---|
[667] | 151 | inter_color = 1 |
---|
| 152 | numprocs = bc_data(2) |
---|
| 153 | coupling_mode = 'ocean_to_atmosphere' |
---|
[206] | 154 | ENDIF |
---|
[667] | 155 | |
---|
[206] | 156 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 157 | comm2d = comm_palm |
---|
| 158 | |
---|
| 159 | ! |
---|
| 160 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
| 161 | !-- processes. |
---|
| 162 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 163 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 164 | CLOSE ( 90 ) |
---|
| 165 | ENDIF |
---|
| 166 | #endif |
---|
| 167 | |
---|
[291] | 168 | ! |
---|
| 169 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
| 170 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
| 171 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
| 172 | THEN |
---|
| 173 | coupling_char = '_O' |
---|
| 174 | ENDIF |
---|
[206] | 175 | |
---|
[2365] | 176 | IF ( TRIM( coupling_mode ) == 'vnested_fine' ) THEN |
---|
| 177 | ! |
---|
| 178 | !-- Set file extension for vertical nesting |
---|
[2669] | 179 | coupling_char = '_NV' |
---|
[2365] | 180 | ENDIF |
---|
| 181 | |
---|
[206] | 182 | END SUBROUTINE init_coupling |
---|