[206] | 1 | SUBROUTINE init_coupling |
---|
| 2 | |
---|
| 3 | !------------------------------------------------------------------------------! |
---|
[484] | 4 | ! Current revisions: |
---|
[206] | 5 | ! ----------------- |
---|
[710] | 6 | ! |
---|
[206] | 7 | ! |
---|
| 8 | ! Former revisions: |
---|
| 9 | ! ------------------ |
---|
| 10 | ! $Id: init_coupling.f90 710 2011-03-30 09:45:27Z letzel $ |
---|
| 11 | ! |
---|
[710] | 12 | ! 709 2011-03-30 09:31:40Z raasch |
---|
| 13 | ! formatting adjustments |
---|
| 14 | ! |
---|
[692] | 15 | ! 691 2011-03-04 08:45:30Z maronga |
---|
| 16 | ! Bugfix: combine_plot_fields did not work with data_output_2d_on_each_pe = .T. |
---|
| 17 | ! for precursor ocean runs |
---|
| 18 | ! |
---|
[668] | 19 | ! 667 2010-12-23 12:06:00Z suehring/gryschka |
---|
| 20 | ! determination of target_id's moved to init_pegrid |
---|
| 21 | ! |
---|
[392] | 22 | ! 291 2009-04-16 12:07:26Z raasch |
---|
| 23 | ! Coupling with independent precursor runs. |
---|
| 24 | ! |
---|
[226] | 25 | ! 222 2009-01-12 16:04:16Z letzel |
---|
| 26 | ! Initial revision |
---|
| 27 | ! |
---|
[206] | 28 | ! Description: |
---|
| 29 | ! ------------ |
---|
| 30 | ! Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is |
---|
| 31 | ! called. |
---|
| 32 | !------------------------------------------------------------------------------! |
---|
| 33 | |
---|
| 34 | USE pegrid |
---|
| 35 | USE control_parameters |
---|
[667] | 36 | USE indices |
---|
[206] | 37 | |
---|
| 38 | IMPLICIT NONE |
---|
| 39 | |
---|
| 40 | ! |
---|
| 41 | !-- Local variables |
---|
| 42 | INTEGER :: i, inter_color |
---|
[291] | 43 | INTEGER, DIMENSION(:) :: bc_data(0:3) = 0 |
---|
[206] | 44 | |
---|
| 45 | ! |
---|
| 46 | !-- Get information about the coupling mode from the environment variable |
---|
| 47 | !-- which has been set by the mpiexec command. |
---|
| 48 | !-- This method is currently not used because the mpiexec command is not |
---|
| 49 | !-- available on some machines |
---|
| 50 | ! CALL local_getenv( 'coupling_mode', 13, coupling_mode, i ) |
---|
| 51 | ! IF ( i == 0 ) coupling_mode = 'uncoupled' |
---|
| 52 | ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' |
---|
| 53 | |
---|
| 54 | ! |
---|
| 55 | !-- Get information about the coupling mode from standard input (PE0 only) and |
---|
| 56 | !-- distribute it to the other PEs. If __mpi2 was defined, suggest a |
---|
| 57 | !-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only. |
---|
| 58 | !-- In this case, distribute PEs to 2 new communicators. |
---|
| 59 | !-- ATTENTION: numprocs will be reset according to the new communicators |
---|
[222] | 60 | #if defined ( __parallel ) |
---|
[667] | 61 | |
---|
| 62 | !myid_absolut = myid |
---|
[206] | 63 | IF ( myid == 0 ) THEN |
---|
| 64 | READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) |
---|
| 65 | 10 CONTINUE |
---|
| 66 | #if defined( __mpi2 ) |
---|
| 67 | IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN |
---|
| 68 | i = 1 |
---|
| 69 | ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' ) THEN |
---|
| 70 | i = 2 |
---|
| 71 | ELSE |
---|
| 72 | i = 0 |
---|
| 73 | ENDIF |
---|
| 74 | #else |
---|
| 75 | IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN |
---|
| 76 | i = 1 |
---|
| 77 | ELSE |
---|
| 78 | i = 0 |
---|
| 79 | ENDIF |
---|
| 80 | #endif |
---|
[291] | 81 | bc_data(0) = i |
---|
| 82 | |
---|
| 83 | ! |
---|
| 84 | !-- Check if '_O' has to be used as file extension in an uncoupled ocean |
---|
| 85 | !-- run. This is required, if this run shall be continued as a coupled run. |
---|
| 86 | IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 |
---|
| 87 | |
---|
[206] | 88 | ENDIF |
---|
| 89 | |
---|
[291] | 90 | CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) |
---|
[206] | 91 | i = bc_data(0) |
---|
| 92 | |
---|
| 93 | #if defined ( __mpi2 ) |
---|
| 94 | IF ( i == 0 ) THEN |
---|
| 95 | coupling_mode = 'uncoupled' |
---|
| 96 | ELSEIF ( i == 1 ) THEN |
---|
| 97 | coupling_mode = 'atmosphere_to_ocean' |
---|
| 98 | ELSEIF ( i == 2 ) THEN |
---|
| 99 | coupling_mode = 'ocean_to_atmosphere' |
---|
| 100 | ENDIF |
---|
| 101 | target_id = myid |
---|
| 102 | #else |
---|
| 103 | IF ( i == 0 ) THEN |
---|
| 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 |
---|
[206] | 113 | ELSE |
---|
| 114 | comm_inter = MPI_COMM_WORLD |
---|
| 115 | |
---|
| 116 | IF ( myid < bc_data(1) ) THEN |
---|
[667] | 117 | inter_color = 0 |
---|
| 118 | numprocs = bc_data(1) |
---|
| 119 | coupling_mode = 'atmosphere_to_ocean' |
---|
[206] | 120 | ELSE |
---|
[667] | 121 | inter_color = 1 |
---|
| 122 | numprocs = bc_data(2) |
---|
| 123 | coupling_mode = 'ocean_to_atmosphere' |
---|
[206] | 124 | ENDIF |
---|
[667] | 125 | |
---|
[206] | 126 | CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) |
---|
| 127 | comm2d = comm_palm |
---|
| 128 | |
---|
| 129 | ! |
---|
| 130 | !-- Write a flag file for the ocean model and the other atmosphere |
---|
| 131 | !-- processes. |
---|
| 132 | OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) |
---|
| 133 | WRITE ( 90, '(''TRUE'')' ) |
---|
| 134 | CLOSE ( 90 ) |
---|
| 135 | ENDIF |
---|
| 136 | #endif |
---|
[222] | 137 | #endif |
---|
[206] | 138 | |
---|
[291] | 139 | ! |
---|
| 140 | !-- In case of a precursor ocean run (followed by a coupled run), or a |
---|
| 141 | !-- coupled atmosphere-ocean run, set the file extension for the ocean files |
---|
| 142 | IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & |
---|
| 143 | THEN |
---|
| 144 | coupling_char = '_O' |
---|
| 145 | ENDIF |
---|
[206] | 146 | |
---|
| 147 | END SUBROUTINE init_coupling |
---|