ATLAS Offline Software
Loading...
Searching...
No Matches
ConcurrencyFlags.py
Go to the documentation of this file.
1# Copyright (C) 2002-2019 CERN for the benefit of the ATLAS collaboration
2
3#=======================================================================
4# File: AthenaCommon/python/ConcurrencyFlags.py
5#=======================================================================
6""" Flags for concurrency
7"""
8#
9#
10__author__ = 'Charles Leggett'
11__version__="$Revision: 1.0 $"
12__doc__="concurrency flags "
13
14
15
16
17#=======================================================================
18# imports
19#=======================================================================
20from AthenaCommon.JobProperties import JobProperty, JobPropertyContainer
21from AthenaCommon.JobProperties import jobproperties
22
23class NumProcs(JobProperty):
24 """ Flag to indicate number of parallel workers"
25 """
26 statusOn = True
27 allowedTypes = ['int']
28 StoredValue = 0
29 def _do_action(self):
30 import multiprocessing
31 if (self.get_Value() == -1):
32 self.set_Value( multiprocessing.cpu_count() )
33 elif ( self.get_Value() < -1 ) :
34 from AthenaCommon.Logging import log
35 log.fatal("nprocs cannot be < -1")
36 import sys
37 from AthenaCommon import ExitCodes
38 sys.exit(ExitCodes.CONFIGURATION_ERROR)
39 elif (self.get_Value() > multiprocessing.cpu_count()):
40 from AthenaCommon.Logging import log
41 log.warning("nprocs is larger than core count [%s]!",
42 multiprocessing.cpu_count())
43
44 return
45
46class NumThreads(JobProperty):
47 """ Flag to indicate number of concurrent threads, possibly per worker"
48 """
49 statusOn = True
50 allowedTypes = ['int']
51 StoredValue = 0
52
53 def _do_action(self):
54 try:
55 import GaudiHive # noqa: F401
56 except ImportError:
57 from AthenaCommon.Logging import log
58 log.fatal("GaudiHive not in release - can't use --threads parameter")
59 import sys
60 from AthenaCommon import ExitCodes
61 sys.exit(ExitCodes.IMPORT_ERROR)
62
63 if (self.get_Value() < 0):
64 from AthenaCommon.Logging import log
65 log.fatal("Number of threads [%s] cannot be negative",self.get_Value())
66 import sys
67 from AthenaCommon import ExitCodes
68 sys.exit(ExitCodes.CONFIGURATION_ERROR)
69
70 return
71
72
73class NumConcurrentEvents(JobProperty):
74 """ Flag to indicate number of concurrent events, possibly per worker"
75 """
76 statusOn = True
77 allowedTypes = ['int']
78 StoredValue = 0
79
80 def _do_action(self):
81 try:
82 import GaudiHive # noqa: F401
83 except ImportError:
84 from AthenaCommon.Logging import log
85 log.fatal("GaudiHive not in release - can't use --concurrent-events parameter")
86 import sys
87 from AthenaCommon import ExitCodes
88 sys.exit(ExitCodes.IMPORT_ERROR)
89
90 if (self.get_Value() < 0):
91 from AthenaCommon.Logging import log
92 log.fatal("Number of concurrent events [%s] cannot be negative",self.get_Value())
93 import sys
94 from AthenaCommon import ExitCodes
95 sys.exit(ExitCodes.CONFIGURATION_ERROR)
96
97 return
98
99
100class DebugWorkers(JobProperty):
101 """ stops the worker in bootstratp until a SIGUSR1 is recieved. Used as debug hook
102 """
103 statusOn = True
104 allowedTypes = ['bool']
105 StoredValue = False
106
107
108class ConcurrencyFlags(JobPropertyContainer):
109 """ The global ConcurrencyFlags job property container.
110 """
111 pass
112
113# add the concurrency flags container to the top container
114jobproperties.add_Container(ConcurrencyFlags)
115
116# I want always the following flags in the Concurrency container
117list_jobproperties = [
118 NumProcs,
119 NumThreads,
120 NumConcurrentEvents,
121 DebugWorkers,
122]
123
124for i in list_jobproperties:
125 jobproperties.ConcurrencyFlags.add_JobProperty(i)
126
127del list_jobproperties
128
129#=======================================================================