SUBROUTINE init_coupling !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! Coupling with independent precursor runs. ! ! Former revisions: ! ------------------ ! $Id: init_coupling.f90 291 2009-04-16 12:07:26Z weinreis $ ! ! 222 2009-01-12 16:04:16Z letzel ! Initial revision ! ! Description: ! ------------ ! Initializing coupling via MPI-1 or MPI-2 if the coupled version of PALM is ! called. !------------------------------------------------------------------------------! USE pegrid USE control_parameters IMPLICIT NONE ! !-- Local variables INTEGER :: i, inter_color INTEGER, DIMENSION(:) :: bc_data(0:3) = 0 ! !-- Get information about the coupling mode from the environment variable !-- which has been set by the mpiexec command. !-- This method is currently not used because the mpiexec command is not !-- available on some machines ! CALL local_getenv( 'coupling_mode', 13, coupling_mode, i ) ! IF ( i == 0 ) coupling_mode = 'uncoupled' ! IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' ! !-- Get information about the coupling mode from standard input (PE0 only) and !-- distribute it to the other PEs. If __mpi2 was defined, suggest a !-- coupling via MPI-2. Otherwise initate a coupling using MPI-1 only. !-- In this case, distribute PEs to 2 new communicators. !-- ATTENTION: numprocs will be reset according to the new communicators #if defined ( __parallel ) IF ( myid == 0 ) THEN READ (*,*,ERR=10,END=10) coupling_mode, bc_data(1), bc_data(2) 10 CONTINUE #if defined( __mpi2 ) IF ( TRIM( coupling_mode ) == 'atmosphere_to_ocean' ) THEN i = 1 ELSEIF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' ) THEN i = 2 ELSE i = 0 ENDIF #else IF ( TRIM( coupling_mode ) == 'coupled_run' ) THEN i = 1 ELSE i = 0 ENDIF #endif bc_data(0) = i ! !-- Check if '_O' has to be used as file extension in an uncoupled ocean !-- run. This is required, if this run shall be continued as a coupled run. IF ( TRIM( coupling_mode ) == 'precursor_ocean' ) bc_data(3) = 1 ENDIF CALL MPI_BCAST( bc_data(0), 4, MPI_INTEGER, 0, MPI_COMM_WORLD, ierr ) i = bc_data(0) #if defined ( __mpi2 ) IF ( i == 0 ) THEN coupling_mode = 'uncoupled' ELSEIF ( i == 1 ) THEN coupling_mode = 'atmosphere_to_ocean' ELSEIF ( i == 2 ) THEN coupling_mode = 'ocean_to_atmosphere' ENDIF target_id = myid #else IF ( i == 0 ) THEN coupling_mode = 'uncoupled' ELSE comm_inter = MPI_COMM_WORLD IF ( myid < bc_data(1) ) THEN inter_color = 0 numprocs = bc_data(1) ELSE inter_color = 1 numprocs = bc_data(2) ENDIF ! !-- Calculate the target PE for coupling and set up the new communicators. !-- Currently only 1:1 topologies are supported. target_id = myid - ISIGN( numprocs, inter_color - 1 ) IF ( inter_color == 0 ) THEN coupling_mode = 'atmosphere_to_ocean' ELSE coupling_mode = 'ocean_to_atmosphere' ENDIF CALL MPI_COMM_SPLIT( MPI_COMM_WORLD, inter_color, 0, comm_palm, ierr ) comm2d = comm_palm ! !-- Write a flag file for the ocean model and the other atmosphere !-- processes. OPEN( 90, FILE='COUPLING_PORT_OPENED', FORM='FORMATTED' ) WRITE ( 90, '(''TRUE'')' ) CLOSE ( 90 ) ENDIF #endif #endif ! !-- In case of a precursor ocean run (followed by a coupled run), or a !-- coupled atmosphere-ocean run, set the file extension for the ocean files IF ( TRIM( coupling_mode ) == 'ocean_to_atmosphere' .OR. bc_data(3) == 1 ) & THEN coupling_char = '_O' ENDIF END SUBROUTINE init_coupling