MCTWorld is a datatype which acts as a component model registry. All models communicating through MCT must participate in initialization of MCTWorld. The single instance of MCTWorld, ThisMCTWorld stores the component id and local and global processor rank of each component. This module contains methods for creating and destroying ThisMCTWorld as well as inquiry functions.
INTERFACE:
module m_MCTWorldUSES:
use m_List, only : List ! Support for List components. implicit none private ! exceptPUBLIC TYPES:
public :: MCTWorld ! The MCTWorld class data structure type MCTWorld integer :: MCT_comm ! MCT communicator integer :: ncomps ! Total number of components integer :: mygrank ! Rank of this processor in ! global communicator. integer,dimension(:),pointer :: nprocspid ! Number of processes ! each component is on (e.g. rank of its ! local communicator. integer,dimension(:,:),pointer :: idGprocid ! Translate between local component rank ! rank in global communicator. ! idGprocid(modelid,localrank)=globalrank end type MCTWorldPUBLIC DATA MEMBERS:
type(MCTWorld) :: ThisMCTWorld ! declare the MCTWorldPUBLIC MEMBER FUNCTIONS:
public :: initialized ! Determine if MCT is initialized public :: init ! Create a MCTWorld public :: clean ! Destroy a MCTWorld public :: printnp ! Print contents of a MCTWorld public :: NumComponents ! Number of Components in the MCTWorld public :: ComponentNumProcs ! Number of processes owned by a given ! component public :: ComponentToWorldRank ! Given the rank of a process on a ! component, return its rank on the ! world communicator public :: ComponentRootRank ! Return the rank on the world ! communicator of the root process of ! a component public :: ThisMCTWorld ! Instantiation of the MCTWorld interface initialized ; module procedure & initialized_ end interface interface init ; module procedure & initd_, & initm_, & initr_ end interface interface clean ; module procedure clean_ ; end interface interface printnp ; module procedure printnp_ ; end interface interface NumComponents ; module procedure & NumComponents_ end interface interface ComponentNumProcs ; module procedure & ComponentNumProcs_ end interface interface ComponentToWorldRank ; module procedure & ComponentToWorldRank_ end interface interface ComponentRootRank ; module procedure & ComponentRootRank_ end interfaceREVISION HISTORY:
19Jan01 - R. Jacob <[email protected]> - initial prototype 05Feb01 - J. Larson <[email protected]> - added query and local-to-global mapping services NumComponents, ComponentNumProcs, ComponentToWorldRank, and ComponentRootRank 08Feb01 - R. Jacob <[email protected]> - add mylrank and mygrank to datatype 20Apr01 - R. Jacob <[email protected]> - remove allids from MCTWorld datatype. Not needed because component ids are always from 1 to number-of-components. 07Jun01 - R. Jacob <[email protected]> - remove myid, mynprocs and mylrank from MCTWorld datatype because they are not clearly defined in PCM mode. Add MCT_comm for future use. 03Aug01 - E. Ong <[email protected]> - explicity specify starting address in mpi_irecv 27Nov01 - E. Ong <[email protected]> - added R. Jacob's version of initd_ to support PCM mode. 15Feb02 - R. Jacob - elminate use of MP_COMM_WORLD. Use argument globalcomm instead. Create MCT_comm from globalcomm
This routine may be used to determine whether MCTWorld::init has been called. If not, the user must call init before performing any other MCT library calls.
INTERFACE:
logical function initialized_()USES:
INPUT PARAMETERS:
REVISION HISTORY:
01June07 - R. Loy <[email protected]> - initial version
Do a distributed init of MCTWorld for the case where a set of processors contains more then one model and the models may not span the set of processors. ncomps is the total number of components in the entire coupled system. globalcomm encompasses all the models (typically this can be MPI_COMM_WORLD). mycomms is an array of MPI communicators, each sized for the appropriate model and myids is a corresponding array of integers containing the model ids for the models on this particular set of processors.
This routine is called once for the models covered by the set of processors.
INTERFACE:
subroutine initm_(ncomps,globalcomm,mycomms,myids)USES:
use m_mpif90 use m_die use m_stdio implicit noneINPUT PARAMETERS:
integer, intent(in) :: ncomps ! number of components integer, intent(in) :: globalcomm ! global communicator integer, dimension(:),pointer :: mycomms ! my communicators integer, dimension(:),pointer :: myids ! component idsREVISION HISTORY:
20Sep07 - T. Craig migrated code from initd routine 20Sep07 - T. Craig - made mycomms an array
Do a distributed init of MCTWorld using the total number of components ncomps and either a unique integer component id myid or, if more than one model is placed on a processor, an array of integer ids specifying the models myids. Also required is the local communicator mycomm and global communicator globalcomm which encompasses all the models (typically this can be MPI_COMM_WORLD). This routine must be called once by each component (using myid) or component group (using myids).
INTERFACE:
subroutine initd_(ncomps,globalcomm,mycomm,myid,myids)USES:
use m_mpif90 use m_die use m_stdio implicit noneINPUT PARAMETERS:
integer, intent(in) :: ncomps ! number of components integer, intent(in) :: globalcomm ! global communicator integer, intent(in) :: mycomm ! my communicator integer, intent(in),optional :: myid ! my component id integer, dimension(:),pointer,optional :: myids ! component idsREVISION HISTORY:
19Jan01 - R. Jacob <[email protected]> - initial prototype 07Feb01 - R. Jacob <[email protected]> - non fatal error if init is called a second time. 08Feb01 - R. Jacob <[email protected]> - initialize the new mygrank and mylrank 20Apr01 - R. Jacob <[email protected]> - remove allids from MCTWorld datatype. Not needed because component ids are always from 1 to number-of-components. 22Jun01 - R. Jacob <[email protected]> - move Bcast and init of MCTWorld to initr_ 20Sep07 - T. Craig migrated code to new initm routine
Initialize MCTWorld using information valid only on the global root. This is called by initm_ but could also be called by the user for very complex model-processor geometries.
INTERFACE:
subroutine initr_(ncomps,globalcomm,rnprocspid,ridGprocid)USES:
use m_mpif90 use m_die use m_stdio implicit noneINPUT PARAMETERS:
integer, intent(in) :: ncomps ! total number of components integer, intent(in) :: globalcomm ! the global communicator integer, dimension(:),intent(in) :: rnprocspid ! number of processors for each component integer, dimension(:,:),intent(in) :: ridGprocid ! an array of size (1:ncomps) x (0:Gsize-1) ! which maps local ranks to global ranks ! it's actually 1:Gsize hereREVISION HISTORY:
22Jun01 - R. Jacob <[email protected]> - initial prototype
This routine deallocates the arrays of ThisMCTWorld It also zeros out the integer components.
INTERFACE:
subroutine clean_()USES:
use m_die implicit noneREVISION HISTORY:
19Jan01 - R. Jacob <[email protected]> - initial prototype 08Feb01 - R. Jacob <[email protected]> - clean the new mygrank and mylrank 20Apr01 - R. Jacob <[email protected]> - remove allids from MCTWorld datatype. Not needed because component ids are always from 1 to number-of-components. 07Jun01 - R. Jacob <[email protected]> - remove myid,mynprocs and mylrank.
The function NumComponents_ takes an input MCTWorld argument World, and returns the number of component models present.
INTERFACE:
integer function NumComponents_(World)USES:
use m_die use m_stdio implicit noneINPUT PARAMETERS:
type(MCTWorld), intent(in) :: WorldREVISION HISTORY:
05Feb01 - J. Larson <[email protected]> - initial version
The function ComponentNumProcs_ takes an input MCTWorld argument World, and a component ID comp_id, and returns the number of processes owned by that component.
INTERFACE:
integer function ComponentNumProcs_(World, comp_id)USES:
use m_die use m_stdio implicit noneINPUT PARAMETERS:
type(MCTWorld), intent(in) :: World integer, intent(in) :: comp_idREVISION HISTORY:
05Feb01 - J. Larson <[email protected]> - initial version 07Jun01 - R. Jacob <[email protected]> - modify to use nprocspid and comp_id instead of World%mynprocs\end{verbatim} %///////////////////////////////////////////////////////////// \mbox{}\hrulefill\ \subsubsection{ComponentToWorldRank\_ - Determine rank on COMM\_WORLD.} The function {\tt ComponentToWorldRank\_} takes an input component ID {\tt comp\_id} and input rank on that component communicator {\tt comp\_rank}, and returns the rank of that process on the world communicator of {\tt MCTWorld}. \bigskip{\sf INTERFACE:} \begin{verbatim} integer function ComponentToWorldRank_(comp_rank, comp_id, World)USES:
use m_die use m_stdio implicit noneINPUT PARAMETERS:
integer, intent(in) :: comp_rank ! process rank on the communicator ! associated with comp_id integer, intent(in) :: comp_id ! component id type(MCTWorld), intent(in) :: World ! WorldREVISION HISTORY:
05Feb01 - J. Larson <[email protected]> - initial version 14Jul02 - E. Ong <[email protected]> - made argument checking required
The function ComponentRootRank_ takes an input component ID comp_id and input MCTWorld variable World, and returns the global rank of the root of this component.
INTERFACE:
integer function ComponentRootRank_(comp_id, World)USES:
use m_die use m_stdio implicit noneINPUT PARAMETERS:
integer, intent(in) :: comp_id ! component id type(MCTWorld), intent(in) :: World ! WorldREVISION HISTORY:
05Feb01 - J. Larson <[email protected]> - initial version 14Jul02 - E. Ong <[email protected]> - made argument checking required
Print out number of MPI processes for the givin component id.
INTERFACE:
subroutine printnp_(compid,lun)USES:
use m_die use m_mpif90 implicit noneINPUT/OUTPUT PARAMETERS:
integer, intent(in) :: compid integer, intent(in) :: lunREVISION HISTORY:
06Jul12 - R. Jacob <[email protected]> - initial version