ESMF_CompSetVMMaxPEs Subroutine

public subroutine ESMF_CompSetVMMaxPEs(compp, max, pref_intra_process, pref_intra_ssi, pref_inter_ssi, pthreadMinStackSize, openMpHandling, openMpNumThreads, forceChildPthreads, rc)

Arguments

Type IntentOptional Attributes Name
type(ESMF_CompClass), pointer :: compp
integer, intent(in), optional :: max
integer, intent(in), optional :: pref_intra_process
integer, intent(in), optional :: pref_intra_ssi
integer, intent(in), optional :: pref_inter_ssi
integer, intent(in), optional :: pthreadMinStackSize
character(len=*), intent(in), optional :: openMpHandling
integer, intent(in), optional :: openMpNumThreads
logical, intent(in), optional :: forceChildPthreads
integer, intent(out), optional :: rc

Source Code

  subroutine ESMF_CompSetVMMaxPEs(compp, max, pref_intra_process, &
    pref_intra_ssi, pref_inter_ssi, pthreadMinStackSize, openMpHandling, &
    openMpNumThreads, forceChildPthreads, rc)
!
! !ARGUMENTS:
    type(ESMF_CompClass), pointer               :: compp
    integer,              intent(in),  optional :: max
    integer,              intent(in),  optional :: pref_intra_process
    integer,              intent(in),  optional :: pref_intra_ssi
    integer,              intent(in),  optional :: pref_inter_ssi
    integer,              intent(in),  optional :: pthreadMinStackSize
    character(*),         intent(in),  optional :: openMpHandling
    integer,              intent(in),  optional :: openMpNumThreads
    logical,              intent(in),  optional :: forceChildPthreads
    integer,              intent(out), optional :: rc
!
! !DESCRIPTION:
!     Print VM internals
!
!     The arguments are:
!     \begin{description}
!     \item[compp] 
!          component object
!     \item[{[max]}] 
!          Maximum number of PEs per PET
!     \item[{[pref\_intra\_process]}] 
!          Intra process communication preference
!     \item[{[pref\_intra\_ssi]}] 
!          Intra SSI communication preference
!     \item[{[pref\_inter\_ssi]}] 
!          Inter process communication preference
!     \item[{[pthreadMinStackSize]}] 
!          Minimum stack size for child PETs executing as Pthreads.
!     \item[{[openMpHandling]}] 
!          Handling of OpenMP threads. Supported: "none", "set", "init", "pin"
!          (default).
!     \item[{[openMpNumThreads]}] 
!          Number of OpenMP threads under each PET. By default each PET uses
!          its local peCount.
!     \item[{[forceChildPthreads]}] 
!          For {\tt .true.}, force each child PET to execute in its own Pthread.
!          By default, {\tt .false.}, single PETs spawned from a parent PET
!          execute in the same thread (or MPI process) as the parent PET. Multiple
!          child PETs spawned by the same parent PET always execute as their own
!          Pthreads.
!     \item[{[rc]}] 
!          Return code; equals {\tt ESMF\_SUCCESS} if there are no errors.
!     \end{description}
!
!EOPI
!------------------------------------------------------------------------------
    integer                 :: localrc      ! local return code
    integer                 :: intOpenMpHandling
    character(len=:), allocatable  :: lowerOpenMpHandling

    ! Initialize return code; assume not implemented until success is certain
    localrc = ESMF_RC_NOT_IMPL
    if (present(rc)) rc = ESMF_RC_NOT_IMPL

    ! Test incoming compp object
    if (.not.associated(compp)) then
      call ESMF_LogSetError(ESMF_RC_OBJ_BAD, &
        msg="Not a valid pointer to ESMF Component object", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif

    ! Check init status of arguments
    ESMF_INIT_CHECK_DEEP(ESMF_CompClassGetInit, compp, rc)

    ! ensure that this is not a child_in_parent_vm plan
    if (compp%contextflag == ESMF_CONTEXT_PARENT_VM) then
      call ESMF_LogSetError(ESMF_RC_NOT_VALID, &
        msg="CompSetVM() calls are incompatible with CHILD_IN_PARENT_VM component", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif
    
    ! ensure that this component's VM wasn't already created
    if (compp%vm_info /= ESMF_NULL_POINTER) then
      call ESMF_LogSetError(ESMF_RC_NOT_VALID, &
        msg="CompSetVM() calls cannot be called on components with existing VM", &
        ESMF_CONTEXT, rcToReturn=rc)
      return
    endif

    ! call CompClass method
    call ESMF_VMPlanMaxPEs(compp%vmplan, compp%vm_parent, max, &
      pref_intra_process, pref_intra_ssi, pref_inter_ssi, &
      compp%npetlist, compp%petlist, forceChildPthreads, rc=localrc)
    if (ESMF_LogFoundError(localrc, &
      ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! set pthreadMinStackSize
    call ESMF_VMPlanSetMinStackSize(compp%vmplan, pthreadMinStackSize, &
      rc=localrc)
    if (ESMF_LogFoundError(localrc, &
      ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! set openMpHandling
    intOpenMpHandling = 3 ! default: pin OpenMP threads to PEs
    if (present(openMpHandling)) then
      lowerOpenMpHandling = ESMF_UtilStringLowerCase(openMpHandling, rc=localrc)
      if (ESMF_LogFoundError(localrc, &
        ESMF_ERR_PASSTHRU, &
        ESMF_CONTEXT, rcToReturn=rc)) return
      if (trim(lowerOpenMpHandling) == "none") then
        intOpenMpHandling = 0
      else if (trim(lowerOpenMpHandling) == "set") then
        intOpenMpHandling = 1
      else if (trim(lowerOpenMpHandling) == "init") then
        intOpenMpHandling = 2
      else if ((trim(lowerOpenMpHandling) == "pin") .or. &
        (trim(lowerOpenMpHandling) == "")) then
        intOpenMpHandling = 3 ! default
      else
        ! not a supported option -> error out
        deallocate(lowerOpenMpHandling)
        call ESMF_LogSetError(ESMF_RC_NOT_VALID, &
          msg="Invalid 'openMpHandling' option provided.", &
          ESMF_CONTEXT, rcToReturn=rc)
        return
      endif
      deallocate(lowerOpenMpHandling)
    endif
    call ESMF_VMPlanSetOpenMP(compp%vmplan, intOpenMpHandling, &
      openMpNumThreads, rc=localrc)
    if (ESMF_LogFoundError(localrc, &
      ESMF_ERR_PASSTHRU, &
      ESMF_CONTEXT, rcToReturn=rc)) return

    ! Return successfully
    if (present(rc)) rc = ESMF_SUCCESS

  end subroutine ESMF_CompSetVMMaxPEs