SUBROUTINE init_coupling !------------------------------------------------------------------------------! ! Actual revisions: ! ----------------- ! ! ! Former revisions: ! ------------------ ! $Id: init_coupling.f90 226 2009-02-02 07:39:34Z 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:2) = 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 ENDIF CALL MPI_BCAST( bc_data(0), 3, 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 IF ( coupling_mode == 'ocean_to_atmosphere' ) coupling_char = '_O' END SUBROUTINE init_coupling