[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 2298 2017-06-29 09:28:18Z suehring $ |
---|
[2298] | 27 | ! MPI2 coupling removed |
---|
| 28 | ! |
---|
| 29 | ! 2101 2017-01-05 16:42:31Z suehring |
---|
[1809] | 30 | ! |
---|
[2001] | 31 | ! 2000 2016-08-20 18:09:15Z knoop |
---|
| 32 | ! Forced header and separation lines into 80 columns |
---|
| 33 | ! |
---|
[1809] | 34 | ! 1808 2016-04-05 19:44:00Z raasch |
---|
| 35 | ! routine local_getenv replaced by standard FORTRAN routine |
---|
[1321] | 36 | ! |
---|
[1683] | 37 | ! 1682 2015-10-07 23:56:08Z knoop |
---|
| 38 | ! Code annotations made doxygen readable |
---|
| 39 | ! |
---|
[1321] | 40 | ! 1320 2014-03-20 08:40:49Z raasch |
---|
[1320] | 41 | ! ONLY-attribute added to USE-statements, |
---|
| 42 | ! kind-parameters added to all INTEGER and REAL declaration statements, |
---|
| 43 | ! kinds are defined in new module kinds, |
---|
| 44 | ! revision history before 2012 removed, |
---|
| 45 | ! comment fields (!:) to be used for variable explanations added to |
---|
| 46 | ! all variable declaration statements |
---|
[206] | 47 | ! |
---|
[1037] | 48 | ! 1036 2012-10-22 13:43:42Z raasch |
---|
| 49 | ! code put under GPL (PALM 3.9) |
---|
| 50 | ! |
---|
[226] | 51 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 52 | ! Initial revision |
---|
| 53 | ! |
---|
[206] | 54 | ! Description: |
---|
| 55 | ! ------------ |
---|
[1682] | 56 | !> Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
| 57 | !> called. |
---|
[206] | 58 | !------------------------------------------------------------------------------! |
---|
[1682] | 59 | SUBROUTINE init_coupling |
---|
| 60 | |
---|
[206] | 61 | |
---|
[1320] | 62 | USE control_parameters, & |
---|
| 63 | ONLY: coupling_char, coupling_mode |
---|
| 64 | |
---|
| 65 | USE kinds |
---|
| 66 | |
---|
[206] | 67 | USE pegrid |
---|
| 68 | |
---|
| 69 | IMPLICIT NONE |
---|
| 70 | |
---|
| 71 | ! |
---|
| 72 | !-- Local variables |
---|
[1682] | 73 | INTEGER(iwp) :: i !< |
---|
| 74 | INTEGER(iwp) :: inter_color !< |
---|
[1320] | 75 | |
---|
[1682] | 76 | INTEGER(iwp), DIMENSION(:) :: bc_data(0:3) = 0 !< |
---|
[206] | 77 | |
---|
| 78 | ! |
---|
| 79 | !-- Get information about the coupling mode from the environment variable |
---|
| 80 | !-- which has been set by the mpiexec command. |
---|
| 81 | !-- This method is currently not used because the mpiexec command is not |
---|
| 82 | !-- available on some machines |
---|
[1808] | 83 | ! CALL GET_ENVIRONMENT_VARIABLE( 'coupling_mode', coupling_mode, i ) |
---|
[206] | 84 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
| 85 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
| 86 | |
---|
| 87 | ! |
---|
| 88 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
[2298] | 89 | !-- distribute it to the other PEs. Distribute PEs to 2 new communicators. |
---|
[206] | 90 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
[222] | 91 | #if defined ( __parallel ) |
---|
[667] | 92 | |
---|
[206] | 93 | IF ( myid == 0 ) THEN |
---|
| 94 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
| 95 | 10 CONTINUE |
---|
| 96 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
| 97 | i = 1 |
---|
| 98 | ELSE |
---|
| 99 | i = 0 |
---|
| 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 ( i == 0 ) THEN |
---|
| 114 | coupling_mode = 'uncoupled' |
---|
[691] | 115 | ! |
---|
| 116 | !-- In case of a precursor ocean run, an additional flag file is created. |
---|
| 117 | !-- This is necessary for data_output_2d_on_each_pe = .T. |
---|
| 118 | IF ( bc_data(3) == 1 ) THEN |
---|
| 119 | OPEN( 90, FILE='PRECURSOR_OCEAN', FORM='FORMATTED' ) |
---|
| 120 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 121 | CLOSE ( 90 ) |
---|
| 122 | ENDIF |
---|
[206] | 123 | ELSE |
---|
| 124 | comm_inter = MPI_COMM_WORLD |
---|
| 125 | |
---|
| 126 | IF ( myid < bc_data(1) ) THEN |
---|
[667] | 127 | inter_color = 0 |
---|
| 128 | numprocs = bc_data(1) |
---|
| 129 | coupling_mode = 'atmosphere_to_ocean' |
---|
[206] | 130 | ELSE |
---|
[667] | 131 | inter_color = 1 |
---|
| 132 | numprocs = bc_data(2) |
---|
| 133 | coupling_mode = 'ocean_to_atmosphere' |
---|
[206] | 134 | ENDIF |
---|
[667] | 135 | |
---|
[206] | 136 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 137 | comm2d = comm_palm |
---|
| 138 | |
---|
| 139 | ! |
---|
| 140 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
| 141 | !-- processes. |
---|
| 142 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 143 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 144 | CLOSE ( 90 ) |
---|
| 145 | ENDIF |
---|
| 146 | #endif |
---|
| 147 | |
---|
[291] | 148 | ! |
---|
| 149 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
| 150 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
| 151 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
| 152 | THEN |
---|
| 153 | coupling_char = '_O' |
---|
| 154 | ENDIF |
---|
[206] | 155 | |
---|
| 156 | END SUBROUTINE init_coupling |
---|