function ESMF_TestMaxPETs(petCount, file, line, unit)
! !RETURN VALUE:
logical :: ESMF_TestMaxPETs
! !ARGUMENTS:
integer, intent(in) :: petCount ! maximum number of acceptable PETs
character(*), intent(in) :: file ! test file name
integer, intent(in) :: line ! test file line number
integer, intent(in), optional :: unit ! additional output unit number
! !DESCRIPTION:
! Verifies we are not running on too many PETs.
! If {\tt unit} is specified, will in addition write the same message
! to that Fortran unit number.
!
!EOP
!-------------------------------------------------------------------------------
character(ESMF_MAXSTR) :: msg, failMsg
type(ESMF_VM) :: globalVM
integer :: numPETs, localrc
character(16) :: linestr
write (linestr,*) line
linestr = adjustl (linestr)
! assume failure until sure of success
ESMF_TestMaxPETs = .false.
! Get the global VM and pet count.
call ESMF_VMGetGlobal(globalVM, rc=localrc)
if (localrc .ne. ESMF_SUCCESS) then
failMsg = "Unable to get global VM"
write(msg, *) "FAIL ", trim(file), ", line ", trim (linestr), ": ", trim(failMsg)
print *, trim(msg)
call ESMF_LogWrite(trim(msg), ESMF_LOGMSG_INFO)
if (present(unit)) write(unit, *) trim(msg)
return
end if
call ESMF_VMGet(globalVM, petCount=numPETs, rc=localrc)
if (localrc .ne. ESMF_SUCCESS) then
failMsg = "Unable to query global VM"
write(msg, *) "FAIL ", trim(file), ", line ", &
trim (linestr), ": ", trim(failMsg)
print *, trim(msg)
call ESMF_LogWrite(trim(msg), ESMF_LOGMSG_INFO)
if (present(unit)) write(unit, *) trim(msg)
return
endif
! Return neither a PASS or FAIL message, but SKIPPED. The nightly
! build scripts are smarter about not looking for output from a
! file which only contains multiproc tags if it is being run uni,
! but this is more for the user to see.
if (petCount .lt. numPETs) then
write(failMsg, *) "These tests must run not more than", petCount, " processors."
write(msg, *) "SKIP ", trim(file), ", line ", &
trim (linestr), ": ", trim(failMsg)
print *, trim(msg)
call ESMF_LogWrite(trim(msg), ESMF_LOGMSG_INFO)
if (present(unit)) write(unit, *) trim(msg)
return
endif
ESMF_TestMaxPETs = .true.
return
end function ESMF_TestMaxPETs