ATLAS Offline Software
Loading...
Searching...
No Matches
python.AthenaMPConfig Namespace Reference

Functions

 athenaMPRunArgsToFlags (runArgs, flags)
 AthenaMPCfg (flags)
int getChunkSize (flags)

Variables

 flags = initConfigFlags()
 Files
 MaxEvents
 NumProcs
 cfg = MainServicesCfg(flags)

Function Documentation

◆ AthenaMPCfg()

python.AthenaMPConfig.AthenaMPCfg ( flags)

Definition at line 49 of file AthenaMPConfig.py.

49def AthenaMPCfg(flags):
50
51 os.putenv('XRD_ENABLEFORKHANDLERS','1')
52 os.putenv('XRD_RUNFORKHANDLER','1')
53
54 result = ComponentAccumulator()
55
56 # Configure MP Event Loop Manager
57 mpevtloop = CompFactory.AthMpEvtLoopMgr(EventPrintoutInterval = flags.Exec.EventPrintoutInterval)
58
59 mpevtloop.NWorkers = flags.Concurrency.NumProcs
60
61 # For e.g. event generation, if we use SharedQueue the job does not complete correctly
62 myStrategy = flags.MP.Strategy
63 if flags.Input.Files == [] and flags.MP.Strategy == 'SharedQueue':
64 msg.info('MP strategy "SharedQueue" will not work without input files when maxEvents=-1. Switching to "RoundRobin" just in case')
65 myStrategy = 'RoundRobin'
66
67 mpevtloop.Strategy = myStrategy
68 mpevtloop.WorkerTopDir = flags.MP.WorkerTopDir
69 mpevtloop.OutputReportFile = flags.MP.OutputReportFile
70 mpevtloop.CollectSubprocessLogs = flags.MP.CollectSubprocessLogs
71 mpevtloop.PollingInterval = flags.MP.PollingInterval
72 mpevtloop.MemSamplingInterval = flags.MP.MemSamplingInterval
73 mpevtloop.IsPileup = flags.Common.ProductionStep in [ProductionStep.Digitization, ProductionStep.PileUpPresampling, ProductionStep.FastChain] and flags.Digitization.PileUp
74 mpevtloop.EventsBeforeFork = 0 if myStrategy == 'EventService' else flags.MP.EventsBeforeFork
75
76 # Configure Gaudi File Manager
77 filemgr = CompFactory.FileMgr(LogFile="FileManagerLog")
78 result.addService(filemgr)
79
80 # Save PoolFileCatalog.xml if exists in the run directory
81 # The saved file will be copied over to workers' run directories just after forking
82 if os.path.isfile('PoolFileCatalog.xml'):
83 shutil.copyfile('PoolFileCatalog.xml','PoolFileCatalog.xml.AthenaMP-saved')
84
85 # Compute event chunk size
86 chunk_size = getChunkSize(flags)
87 if chunk_size < 1:
88 msg.warning('Nonpositive ChunkSize (%i) caught, setting it to 1', chunk_size)
89 chunk_size = 1
90 elif chunk_size > 1:
91 # Check whether there are enough events to distribute across workers;
92 # if not, set the chunk size to 1.
93 # Ensuring that each worker processes at least some events is important
94 # for maintaining the integrity of the metadata produced by each worker.
95 requested_events = flags.Exec.MaxEvents
96 available_events = max(0, flags.Input.FileNentries - flags.Exec.SkipEvents)
97 total_entries = available_events if requested_events == -1 else min(available_events, requested_events)
98 if 0 < total_entries <= (flags.Concurrency.NumProcs-1) * chunk_size:
99 chunk_size = 1
100 msg.warning('Not enough events (%d) to fill all workers (%d) with chunk size %d. Chunk size is set to 1',
101 total_entries, flags.Concurrency.NumProcs, chunk_size)
102
103 # Configure Strategy
104 debug_worker = flags.Concurrency.DebugWorkers
105 event_range_channel = flags.MP.EventRangeChannel
106 use_shared_reader = flags.MP.UseSharedReader
107 use_shared_writer = flags.MP.UseSharedWriter
108 unique_id = f"{str(os.getpid())}-{uuid.uuid4().hex}"
109
110 if myStrategy == 'SharedQueue' or myStrategy == 'RoundRobin':
111 if use_shared_reader:
112 AthenaSharedMemoryTool = CompFactory.AthenaSharedMemoryTool
113
114 if flags.Input.Format is Format.BS:
115 evSel = CompFactory.EventSelectorByteStream("EventSelector")
116
117 from ByteStreamCnvSvc.ByteStreamConfig import ByteStreamReadCfg
118 bscfg = ByteStreamReadCfg(flags)
119 result.merge(bscfg)
120 else:
121 evSel = CompFactory.EventSelectorAthenaPoolSharedIO("EventSelector")
122
123 inputStreamingTool = AthenaSharedMemoryTool("InputStreamingTool",
124 SharedMemoryName=f"InputStream{unique_id}")
125
126 from AthenaPoolCnvSvc.PoolReadConfig import PoolReadCfg
127 result.merge(PoolReadCfg(flags))
128 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolSharedIOCnvSvcCfg
129 result.merge(AthenaPoolSharedIOCnvSvcCfg(flags, InputStreamingTool=inputStreamingTool))
130
131 evSel.SharedMemoryTool = AthenaSharedMemoryTool("EventStreamingTool",
132 SharedMemoryName=f"EventStream{unique_id}")
133 result.addService(evSel)
134
135 if use_shared_writer:
136 if any((flags.Output.doWriteESD,
137 flags.Output.doWriteAOD,
138 flags.Output.doWriteDAOD,
139 flags.Output.doWriteRDO)) or flags.Output.HITSFileName!='':
140 AthenaSharedMemoryTool = CompFactory.AthenaSharedMemoryTool
141 outputStreamingTool = AthenaSharedMemoryTool("OutputStreamingTool",
142 SharedMemoryName=f"OutputStream{unique_id}")
143
144 from AthenaPoolCnvSvc.PoolCommonConfig import AthenaPoolSharedIOCnvSvcCfg
145 result.merge(AthenaPoolSharedIOCnvSvcCfg(flags, OutputStreamingTool=outputStreamingTool))
146
147 if myStrategy == 'SharedQueue':
148 queue_provider = CompFactory.SharedEvtQueueProvider(UseSharedReader=use_shared_reader,
149 IsPileup=mpevtloop.IsPileup,
150 EventsBeforeFork=mpevtloop.EventsBeforeFork,
151 ChunkSize=chunk_size)
152 mpevtloop.Tools += [ queue_provider ]
153
154 if flags.Concurrency.NumThreads > 0:
155 if mpevtloop.IsPileup:
156 raise Exception('Running pileup digitization in mixed MP+MT currently not supported')
157 from AthenaConfiguration.MainServicesConfig import AthenaMtesEventLoopMgrCfg
158 result.merge(AthenaMtesEventLoopMgrCfg(flags))
159 queue_consumer = CompFactory.SharedHiveEvtQueueConsumer(UseSharedWriter=use_shared_writer,
160 EventsBeforeFork=mpevtloop.EventsBeforeFork,
161 Debug=debug_worker)
162 else:
163 queue_consumer = CompFactory.SharedEvtQueueConsumer(UseSharedReader=use_shared_reader,
164 UseSharedWriter=use_shared_writer,
165 IsPileup=mpevtloop.IsPileup,
166 IsRoundRobin=(myStrategy=='RoundRobin'),
167 EventsBeforeFork=mpevtloop.EventsBeforeFork,
168 ReadEventOrders=flags.MP.ReadEventOrders,
169 EventOrdersFile=flags.MP.EventOrdersFile,
170 Debug=debug_worker)
171 mpevtloop.Tools += [ queue_consumer ]
172
173 if use_shared_writer:
174 shared_writer = CompFactory.SharedWriterTool(MotherProcess=(mpevtloop.EventsBeforeFork>0),
175 IsPileup=mpevtloop.IsPileup,
176 Debug=debug_worker)
177 mpevtloop.Tools += [ shared_writer ]
178
179 elif myStrategy=='EventService':
180 channelScatterer2Processor = "AthenaMP_Scatterer2Processor"
181 channelProcessor2EvtSel = "AthenaMP_Processor2EvtSel"
182
183 mpevtloop.Tools += [ CompFactory.EvtRangeScatterer(ProcessorChannel = channelScatterer2Processor,
184 EventRangeChannel = event_range_channel,
185 DoCaching=flags.MP.EvtRangeScattererCaching) ]
186 mpevtloop.Tools += [ CompFactory.EvtRangeProcessor(IsPileup=mpevtloop.IsPileup,
187 Channel2Scatterer = channelScatterer2Processor,
188 Channel2EvtSel = channelProcessor2EvtSel,
189 Debug=debug_worker) ]
190
191 from AthenaServices.OutputStreamSequencerSvcConfig import OutputStreamSequencerSvcCfg
192 result.merge(OutputStreamSequencerSvcCfg(flags,incidentName="NextEventRange"))
193 else:
194 msg.warning("Unknown strategy %s. No MP tools will be configured", myStrategy)
195
196 result.addService(mpevtloop, primary=True)
197
198 return result
199
#define min(a, b)
Definition cfImp.cxx:40
#define max(a, b)
Definition cfImp.cxx:41
This class provides the IPCTool for SharedMemory objects.

◆ athenaMPRunArgsToFlags()

python.AthenaMPConfig.athenaMPRunArgsToFlags ( runArgs,
flags )
Fill MP configuration flags from run arguments.

Definition at line 14 of file AthenaMPConfig.py.

14def athenaMPRunArgsToFlags(runArgs, flags):
15 """Fill MP configuration flags from run arguments."""
16 if hasattr(runArgs, "athenaMPWorkerTopDir"):
17 flags.MP.WorkerTopDir = runArgs.athenaMPWorkerTopDir
18
19 if hasattr(runArgs, "athenaMPOutputReportFile"):
20 flags.MP.OutputReportFile = runArgs.athenaMPOutputReportFile
21
22 if hasattr(runArgs, "athenaMPCollectSubprocessLogs"):
23 flags.MP.CollectSubprocessLogs = runArgs.athenaMPCollectSubprocessLogs
24
25 if hasattr(runArgs, "athenaMPStrategy"):
26 flags.MP.Strategy = runArgs.athenaMPStrategy
27
28 if hasattr(runArgs, "athenaMPReadEventOrders"):
29 flags.MP.ReadEventOrders = runArgs.athenaMPReadEventOrders
30
31 if hasattr(runArgs, "athenaMPEventOrdersFile"):
32 flags.MP.EventOrdersFile = runArgs.athenaMPEventOrdersFile
33
34 if hasattr(runArgs, "athenaMPEventsBeforeFork"):
35 flags.MP.EventsBeforeFork = runArgs.athenaMPEventsBeforeFork
36
37 if hasattr(runArgs, "sharedWriter"):
38 flags.MP.UseSharedWriter = runArgs.sharedWriter
39
40 if hasattr(runArgs, "sharedReader"):
41 flags.MP.UseSharedReader = runArgs.sharedReader
42
43 if hasattr(runArgs, "parallelCompression"):
44 flags.MP.UseParallelCompression = runArgs.parallelCompression
45
46 if hasattr(runArgs, "eventService"):
47 flags.MP.Strategy = "EventService"
48

◆ getChunkSize()

int python.AthenaMPConfig.getChunkSize ( flags)

Definition at line 200 of file AthenaMPConfig.py.

200def getChunkSize(flags) -> int:
201 chunk_size = 1
202 if flags.MP.ChunkSize > 0:
203 chunk_size = flags.MP.ChunkSize
204 msg.info('Chunk size set to %i', chunk_size)
205 else:
206 if '_ATHENA_GENERIC_INPUTFILE_NAME_' in flags.Input.Files:
207 msg.info('Running an input-less job. Setting Chunk Size to 1')
208 else:
209 md = GetFileMD(flags.Input.Files)
210 #Don't use auto flush for shared reader
211 if flags.MP.UseSharedReader:
212 msg.info('Shared Reader in use, chunk_size set to default (%i)', chunk_size)
213 #Use auto flush only if file is compressed with LZMA, else use default chunk_size
214 elif flags.MP.ChunkSize == -1:
215 if md.get('file_comp_alg',-1) == 2:
216 chunk_size = md.get('auto_flush',-1)
217 msg.info('Chunk size set to auto flush (%i)', chunk_size)
218 else:
219 msg.info('LZMA algorithm not in use, chunk_size set to default (%i)', chunk_size)
220 #Use auto flush only if file is compressed with LZMA or ZLIB, else use default chunk_size
221 elif flags.MP.ChunkSize == -2:
222 if md.get('file_comp_alg',-1) in [1,2]:
223 chunk_size = md.get('auto_flush',-1)
224 msg.info('Chunk size set to auto flush (%i)', chunk_size)
225 else:
226 msg.info('LZMA nor ZLIB in use, chunk_size set to default (%i)', chunk_size)
227 #Use auto flush only if file is compressed with LZMA, ZLIB or LZ4, else use default chunk_size
228 elif flags.MP.ChunkSize == -3:
229 if md.get('file_comp_alg',-1) in [1,2,4]:
230 chunk_size = md.get('auto_flush',-1)
231 msg.info('Chunk size set to auto flush (%i)', chunk_size)
232 else:
233 msg.info('LZMA, ZLIB nor LZ4 in use, chunk_size set to (%i)', chunk_size)
234 #Use auto flush value for chunk_size, regardless of compression algorithm
235 elif flags.MP.ChunkSize <= -4:
236 chunk_size = md.get('auto_flush',-1)
237 msg.info('Chunk size set to auto flush (%i)', chunk_size)
238 else:
239 msg.warning('Invalid ChunkSize, Chunk Size set to default (%i)', chunk_size)
240
241 return chunk_size
242
243

Variable Documentation

◆ cfg

python.AthenaMPConfig.cfg = MainServicesCfg(flags)

Definition at line 253 of file AthenaMPConfig.py.

◆ Files

python.AthenaMPConfig.Files

Definition at line 249 of file AthenaMPConfig.py.

◆ flags

python.AthenaMPConfig.flags = initConfigFlags()

Definition at line 248 of file AthenaMPConfig.py.

◆ MaxEvents

python.AthenaMPConfig.MaxEvents

Definition at line 250 of file AthenaMPConfig.py.

◆ NumProcs

python.AthenaMPConfig.NumProcs

Definition at line 251 of file AthenaMPConfig.py.