def main():
    Script.registerSwitch("C:", "CPUNormalizationFactor=",
                          "CPUNormalizationFactor, in case it is known")
    Script.parseCommandLine(ignoreErrors=True)

    CPUNormalizationFactor = 0.0
    for unprocSw in Script.getUnprocessedSwitches():
        if unprocSw[0] in ("C", "CPUNormalizationFactor"):
            CPUNormalizationFactor = float(unprocSw[1])

    from DIRAC.WorkloadManagementSystem.Client.CPUNormalization import getCPUTime

    cpuTime = getCPUTime(CPUNormalizationFactor)
    # I hate this kind of output... PhC
    print("CPU time left determined as", cpuTime)
    DIRAC.exit(0)
Example #2
0
def getEventsToProduce(CPUe,
                       CPUTime=None,
                       CPUNormalizationFactor=None,
                       maxNumberOfEvents=None,
                       jobMaxCPUTime=None):
    """ Returns the number of events to produce considering the CPU time available.
      CPUTime and CPUNormalizationFactor are taken from the LocalSite configuration if not provided.
      No checks are made on the values passed !

      Limits can be set.
  """

    if CPUNormalizationFactor is None:
        CPUNormalizationFactor = gConfig.getValue(
            '/LocalSite/CPUNormalizationFactor', 1.0)

    if CPUTime is None:
        CPUTime = getCPUTime(CPUNormalizationFactor)
    if jobMaxCPUTime:
        gLogger.verbose(
            "CPUTimeLeft from the WN perspective: %d; Job maximum CPUTime (in seconds): %d"
            % (CPUTime, jobMaxCPUTime))
        CPUTime = min(CPUTime, jobMaxCPUTime)

    gLogger.verbose("CPUTime = %d, CPUNormalizationFactor = %f, CPUe = %d" %
                    (CPUTime, CPUNormalizationFactor, CPUe))

    eventsToProduce = int(
        math.floor(CPUTime * CPUNormalizationFactor) / float(CPUe))
    gLogger.verbose("Without limits, we can produce %d events" %
                    eventsToProduce)

    gLogger.info("We can produce %d events" % eventsToProduce)
    willProduce = int(eventsToProduce * 0.8)
    gLogger.info("But we take a conservative approach, so 80%% of those: %d" %
                 willProduce)

    if maxNumberOfEvents:
        gLogger.verbose("Limit for MaxNumberOfEvents: %d" % maxNumberOfEvents)
        willProduce = min(willProduce, maxNumberOfEvents)

    if willProduce < 1:
        raise RuntimeError("No time left to produce events")

    return willProduce
# Author :  Federico Stagni
########################################################################
""" Report CPU length of queue, in seconds
    This script is used by the dirac-pilot script to set the CPUTime left, which is a limit for the matching
"""
import DIRAC
from DIRAC.Core.Base import Script

__RCSID__ = "$Id$"

Script.registerSwitch("C:", "CPUNormalizationFactor=",
                      "CPUNormalizationFactor, in case it is known")
Script.setUsageMessage('\n'.join([
    __doc__.split('\n')[1], 'Usage:',
    '  %s [option|cfgfile]' % Script.scriptName
]))
Script.parseCommandLine(ignoreErrors=True)
args = Script.getPositionalArgs()

CPUNormalizationFactor = 0.0
for unprocSw in Script.getUnprocessedSwitches():
    if unprocSw[0] in ("C", "CPUNormalizationFactor"):
        CPUNormalizationFactor = float(unprocSw[1])

if __name__ == "__main__":
    from DIRAC.WorkloadManagementSystem.Client.CPUNormalization import getCPUTime
    cpuTime = getCPUTime(CPUNormalizationFactor)
    # I hate this kind of output... PhC
    print "CPU time left determined as", cpuTime
    DIRAC.exit(0)
# File :    dirac-wms-get-queue-cpu-time.py
# Author :  Federico Stagni
########################################################################
""" Report CPU length of queue, in seconds
    This script is used by the dirac-pilot script to set the CPUTime left, which is a limit for the matching
"""
__RCSID__ = "$Id$"

import DIRAC
from DIRAC.Core.Base import Script

Script.registerSwitch( "C:", "CPUNormalizationFactor=", "CPUNormalizationFactor, in case it is known" )

Script.setUsageMessage( '\n'.join( [ __doc__.split( '\n' )[1],
                                     'Usage:',
                                     '  %s [option|cfgfile]' % Script.scriptName ] ) )
Script.parseCommandLine( ignoreErrors = True )
args = Script.getPositionalArgs()

CPUNormalizationFactor = 0.0
for unprocSw in Script.getUnprocessedSwitches():
  if unprocSw[0] in ( "C", "CPUNormalizationFactor" ):
    CPUNormalizationFactor = float( unprocSw[1] )    

if __name__ == "__main__":
  from DIRAC.WorkloadManagementSystem.Client.CPUNormalization import getCPUTime
  cpuTime = getCPUTime( CPUNormalizationFactor )
  print cpuTime

DIRAC.exit( 0 )