ATLAS Offline Software
trfMTTools.py
Go to the documentation of this file.
1 # Copyright (C) 2002-2021 CERN for the benefit of the ATLAS collaboration
2 
3 
7 
8 __version__ = '$Revision'
9 
10 import os
11 
12 import logging
13 msg = logging.getLogger(__name__)
14 
15 from PyJobTransforms.trfExeStepTools import commonExecutorStepName
16 from PyJobTransforms.trfExitCodes import trfExit
17 
18 import PyJobTransforms.trfExceptions as trfExceptions
19 
20 
23 def detectAthenaMTThreads(argdict = {}, currentSubstep = '', legacyThreadingRelease = False):
24  athenaMTThreads = 0
25  athenaConcurrentEvents = 0
26  currentSubstep = commonExecutorStepName(currentSubstep)
27 
28  if legacyThreadingRelease:
29  return athenaMTThreads, athenaConcurrentEvents
30 
31  # Try and detect if any AthenaMT has been enabled
32  try:
33  if 'athenaopts' in argdict:
34  for substep in argdict['athenaopts'].value:
35  if substep == 'all' or substep == currentSubstep:
36  threadArg = [opt.replace("--threads=", "") for opt in argdict['athenaopts'].value[substep] if '--threads' in opt]
37  if len(threadArg) == 0:
38  athenaMTThreads = 0
39  elif len(threadArg) == 1:
40  if 'multithreaded' in argdict and substep == 'all':
41  raise ValueError("Detected conflicting methods to configure AthenaMT: --multithreaded and --threads=N (via athenaopts). Only one method must be used")
42  athenaMTThreads = int(threadArg[0])
43  if athenaMTThreads < -1:
44  raise ValueError("--threads was set to a value less than -1")
45  else:
46  raise ValueError("--threads was set more than once in 'athenaopts'")
47  if athenaMTThreads > 0:
48  msg.info('AthenaMT detected from "threads" setting with {0} threads for substep {1}'.format(athenaMTThreads,substep))
49 
50  concurrentEventsArg = [opt.replace("--concurrent-events=", "") for opt in argdict['athenaopts'].value[substep] if '--concurrent-events' in opt]
51  if len(concurrentEventsArg) == 1:
52  athenaConcurrentEvents = int(concurrentEventsArg[0])
53  if athenaConcurrentEvents < -1:
54  raise ValueError("--concurrent-events was set to a value less than -1")
55  msg.info('Custom concurrent event setting read from "concurrent-events" with {0} events for substep {1}'.format(athenaConcurrentEvents,substep))
56  else:
57  athenaConcurrentEvents = athenaMTThreads
58  if (athenaMTThreads == 0 and
59  'ATHENA_CORE_NUMBER' in os.environ and
60  'multithreaded' in argdict and argdict['multithreaded'].value):
61  athenaMTThreads = int(os.environ['ATHENA_CORE_NUMBER'])
62  if athenaMTThreads < -1:
63  raise ValueError("ATHENA_CORE_NUMBER value was less than -1")
64  msg.info('AthenaMT detected from ATHENA_CORE_NUMBER with {0} threads'.format(athenaMTThreads))
65  athenaConcurrentEvents = athenaMTThreads
66  except ValueError as errMsg:
67  myError = 'Problem discovering AthenaMT setup: {0}'.format(errMsg)
68  raise trfExceptions.TransformExecutionException(trfExit.nameToCode('TRF_EXEC_SETUP_FAIL'), myError)
69 
70  return athenaMTThreads, athenaConcurrentEvents
vtune_athena.format
format
Definition: vtune_athena.py:14
CaloCellPos2Ntuple.int
int
Definition: CaloCellPos2Ntuple.py:24
python.trfMTTools.detectAthenaMTThreads
def detectAthenaMTThreads(argdict={}, currentSubstep='', legacyThreadingRelease=False)
Detect if AthenaMT has been requested.
Definition: trfMTTools.py:23
PyJobTransforms.trfExitCodes
Module for transform exit codes.
python.trfExceptions.TransformExecutionException
Base class for execution exceptions.
Definition: trfExceptions.py:62
python.trfExeStepTools.commonExecutorStepName
def commonExecutorStepName(name)
Definition: trfExeStepTools.py:7