function ESMF_TestMinPETs(petCount, file, line, unit)
! !RETURN VALUE:
logical :: ESMF_TestMinPETs
! !ARGUMENTS:
integer, intent(in) :: petCount ! minimum 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 running on at least the minimum number of 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_TestMinPETs = .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 get number of PETS from 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 SKIP. 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 .gt. numPETs) then
write(failMsg, *) "These tests must run on at least", 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_TestMinPETs = .true.
return
end function ESMF_TestMinPETs