psmile_def_mpi_comm.F90

Go to the documentation of this file.
00001 !-----------------------------------------------------------------------
00002 ! Copyright 2006-2010, NEC Europe Ltd., London, UK.
00003 ! All rights reserved. Use is subject to OASIS4 license terms.
00004 !-----------------------------------------------------------------------
00005 !BOP
00006 !
00007 ! !ROUTINE: PSMILe_Def_MPI_Comm
00008 !
00009 ! !INTERFACE:
00010 !
00011       subroutine psmile_def_mpi_comm (ierror)
00012 !
00013 ! !USES:
00014 !
00015       use PRISM_constants
00016       use PSMILe, dummy_interface => PSMILe_Def_MPI_Comm
00017 
00018       implicit none
00019 !
00020 ! !OUTPUT PARAMETERS:
00021 !
00022       integer, Intent (Out) :: ierror
00023 
00024 !     Returns the error code of PSMILe_get_initial_data;
00025 !             ierror = 0 : No error
00026 !             ierror > 0 : Severe error
00027 !
00028 ! !LOCAL VARIABLES
00029 !
00030       integer            :: index
00031       integer            :: key
00032       integer            :: color
00033       integer            :: comm
00034 
00035       integer, parameter :: nerrp = 1
00036       integer            :: ierrp (nerrp)
00037 !
00038 ! !DESCRIPTION:
00039 !
00040 ! Subroutine PSMILe_Def_MPI_Comm defines the communicators
00041 ! if all processes were simultaneously started by the mpirun/mpiexec
00042 ! command.
00043 !
00044 ! The routine assumes that communicator "comm_global" is defined.
00045 
00046 ! It constructs the     communicator for the application "Appl%comm",
00047 !               the user communicator of the application "Appl%comm_user" and
00048 !               the communicator with the coupler "comm_coupler".
00049 !               the communicator for the PSMILe library "comm_psmile".
00050 !
00051 ! !REVISION HISTORY:
00052 !
00053 !   Date      Programmer   Description
00054 ! ----------  ----------   -----------
00055 ! 01.12.03    R. Redler    created
00056 !
00057 !EOP
00058 !-----------------------------------------------------------------------
00059 !
00060 ! $Id: psmile_def_mpi_comm.F90 2325 2010-04-21 15:00:07Z valcke $
00061 ! $Author: valcke $
00062 !
00063    Character(len=len_cvs_string), save :: mycvs = 
00064        '$Id: psmile_def_mpi_comm.F90 2325 2010-04-21 15:00:07Z valcke $'
00065 !
00066 ! ----------------------------------------------------------------------
00067 
00068 #ifdef VERBOSE
00069       print *, trim(ch_id), ': PSMILe_Def_MPI_Comm: start'
00070 
00071       call psmile_flushstd
00072 #endif /* VERBOSE */
00073 !
00074 ! Create Application Communicator
00075 !
00076       if ( Appl%stand_alone ) then
00077 
00078          comm_coupler = MPI_COMM_NULL
00079 
00080          call MPI_Comm_dup ( comm_global, Appl%comm, ierror )
00081 
00082          if ( ierror /= MPI_SUCCESS ) then
00083             ierrp (1) = ierror
00084             ierror = PRISM_Error_MPI
00085 
00086             call psmile_error ( ierror, 'MPI_Comm_dup', &
00087                                 ierrp, 1, __FILE__, __LINE__ )
00088             return
00089          endif
00090 
00091       else
00092 !
00093 ! 1st Define Communicator for subgroups
00094 ! --------------------------------------
00095 
00096 
00097 ! a) Build communicator for application local communication
00098 ! ---------------------------------------------------------
00099 !
00100 ! Appl%sequence_number is determined in psmile_init_mpi1
00101 !
00102          print *, trim(ch_id), ': Colored application with ', &
00103               Appl%sequence_number
00104 
00105          key   = 0
00106          color = Appl%sequence_number
00107 
00108          call MPI_Comm_Split ( comm_global, color, key, &
00109               Appl%comm, ierror )
00110 
00111          if ( ierror /= MPI_SUCCESS ) then
00112             ierrp (1) = ierror
00113             ierror = PRISM_Error_MPI
00114 
00115             call psmile_error ( ierror, 'MPI_Comm_Split', &
00116                  ierrp, 1, __FILE__, __LINE__ )
00117             return
00118          endif
00119 
00120 ! b) Build communicator for communication between coupler and application
00121 ! -----------------------------------------------------------------------
00122 !
00123          do index = 1, noApplication
00124 
00125 ! i.)  Set one color for each pair [application(index), coupler]
00126 
00127             if ( index == Appl%sequence_number ) then
00128                 color = index
00129             else
00130                 color = MPI_UNDEFINED
00131             end if
00132 
00133             if ( Appl%sequence_number == 0 ) color = index
00134 
00135 ! ii.) Generate a communicator for each pair
00136 
00137             call MPI_Comm_Split ( comm_global, color, key,   &
00138                                   comm, ierror )
00139 
00140             if ( ierror /= MPI_SUCCESS ) then
00141                ierrp (1) = ierror
00142                ierror = PRISM_Error_MPI
00143 
00144                call psmile_error ( ierror, 'MPI_Comm_Split', &
00145                                    ierrp, 1, __FILE__, __LINE__ )
00146                return
00147             endif
00148 
00149 ! iii.) Save the communicator for communication from application to coupler
00150 
00151             if ( index == Appl%sequence_number ) then
00152 
00153                comm_coupler = comm
00154 
00155                call MPI_Comm_Rank ( comm_coupler, coupler_rank, ierror )
00156 
00157                if ( ierror /= MPI_SUCCESS ) then
00158                   ierrp (1) = ierror
00159                   ierror = PRISM_Error_MPI
00160                   call psmile_error ( ierror, 'MPI_Comm_Rank', &
00161                                ierrp, 1,  __FILE__, __LINE__ )
00162                   return
00163                 endif
00164 
00165             endif
00166 
00167          end do  ! 'do index = 1, noApplication'
00168 
00169       endif ! Appl%stand_alone
00170 
00171 ! -----------------------------------------------------------------------
00172 ! c)  Construct a communicator comm_psmile containing all MPI processes
00173 !     which are connected to the PSMILe library
00174 
00175       key   = 0
00176       color = 1
00177       
00178       call MPI_Comm_Split ( comm_global, color, key,  &
00179                             comm_psmile, ierror )
00180       
00181       if ( ierror /= MPI_SUCCESS ) then
00182          ierrp (1) = ierror
00183          ierror = PRISM_Error_MPI
00184          call psmile_error ( ierror, 'MPI_Comm_Split', &
00185                          ierrp, 1,  __FILE__, __LINE__ )
00186          return
00187       endif
00188 
00189 ! -----------------------------------------------------------------------
00190 ! d)  Construct communicator for user application and
00191 !     get rank within comm_appl
00192 
00193       call MPI_Comm_dup ( Appl%comm, Appl%comm_user, ierror )
00194 
00195       if ( ierror /= MPI_SUCCESS ) then
00196          ierrp (1) = ierror
00197          ierror = PRISM_Error_MPI
00198 
00199          call psmile_error ( ierror, 'MPI_Comm_dup', &
00200                              ierrp, 1, __FILE__, __LINE__ )
00201          return
00202       endif
00203 
00204       call MPI_Comm_rank ( Appl%comm,  Appl%rank, ierror )
00205 
00206       if ( ierror /= MPI_SUCCESS ) then
00207          ierrp (1) = ierror
00208          ierror = PRISM_Error_MPI
00209 
00210          call psmile_error ( ierror, 'MPI_Comm_rank', &
00211                              ierrp, 1, __FILE__, __LINE__ )
00212          return
00213       endif
00214 
00215       call MPI_Comm_size ( Appl%comm,  Appl%size, ierror )
00216 
00217       if ( ierror /= MPI_SUCCESS ) then
00218          ierrp (1) = ierror
00219          ierror = PRISM_Error_MPI
00220 
00221          call psmile_error ( ierror, 'MPI_Comm_rank', &
00222                              ierrp, 1, __FILE__, __LINE__ )
00223          return
00224       endif
00225 
00226 #ifdef VERBOSE
00227       print *, trim(ch_id), ': PSMILe_Def_MPI_Comm: eof ierror =', ierror
00228 
00229       call psmile_flushstd
00230 #endif /* VERBOSE */
00231 
00232       end subroutine PSMILe_Def_MPI_Comm

Generated on 18 Mar 2011 for Oasis4 by  doxygen 1.6.1