The Gaudi Framework  v36r1 (3e2fb5a8)
AvalancheSchedulerSimpleTest.py
Go to the documentation of this file.
1 #!/usr/bin/env gaudirun.py
2 
12 '''
13 Reference optionfile which shows in a simple way how to take advantage of the
14 Gaudi components desicated to concurrency.
15 The components are:
16  o HiveWhiteBoard: a convenient way to collect several TES (one per "processing
17  slot"), accessible in a thread safe way, keeps a catalogue of the products
18  written on each processing slot. The number of slots in the whiteboard
19  determines also the number of events processed simultaneously by the scheduler.
20  o AvalancheSchedulerSvc: state machine of the algorithms interfaced with the
21  TBB runtime. It is responsible for the submission of the algorithms. An
22  algorithm is marked ready for submission when its needed input is available.
23  It deals the asynchronous termination of algorithms with a "receiver" thread
24  and a thread safe queue.
25  o HiveSlimEventLoopMgr: an event factory. Pushes new events and pops finished
26  events to/from the scheduler. It does not manage algorithms/streams.
27  o AlgResourcePool: Service managing the creation of algorithms (through the
28  algorithm manager), including clones. It also manages the algorithms according
29  to the resources they need (parameter NeededResources - vector of strings - of
30  the Algorithm class).
31  o InertMessageSvc: as the TBBMsgSvc, it manages the printing of the messages in
32  a multithreaded environment.
33 
34 The CPUCruncher is not a component dealing with concurrency, but a useful
35 entity to test it. It's an algorithm that simply wastes cpu.
36 
37 '''
38 from Gaudi.Configuration import *
39 from Configurables import (HiveWhiteBoard, HiveSlimEventLoopMgr,
40  AvalancheSchedulerSvc, AlgResourcePool, CPUCruncher,
41  ContextEventCounterPtr, ContextEventCounterData,
42  CPUCrunchSvc)
43 
44 # metaconfig -------------------------------------------------------------------
45 # It's confortable to collect the relevant parameters at the top of the optionfile
46 evtslots = 23
47 evtMax = 50
48 cardinality = 10
49 threads = 10
50 # -------------------------------------------------------------------------------
51 
52 # The configuration of the whiteboard ------------------------------------------
53 # It is useful to call it EventDataSvc to replace the usual data service with
54 # the whiteboard transparently.
55 
56 whiteboard = HiveWhiteBoard("EventDataSvc", EventSlots=evtslots)
57 
58 # -------------------------------------------------------------------------------
59 
60 # Event Loop Manager -----------------------------------------------------------
61 # It's called slim since it has less functionalities overall than the good-old
62 # event loop manager. Here we just set its outputlevel to DEBUG.
63 
64 slimeventloopmgr = HiveSlimEventLoopMgr(
65  SchedulerName="AvalancheSchedulerSvc", OutputLevel=DEBUG)
66 
67 # -------------------------------------------------------------------------------
68 
69 # AvalancheScheduler -----------------------------------------------------------
70 # We just decide how many algorithms in flight we want to have and how many
71 # threads in the pool. The default value is -1, which is for TBB equivalent
72 # to take over the whole machine.
73 
74 scheduler = AvalancheSchedulerSvc(ThreadPoolSize=threads, OutputLevel=WARNING)
75 
76 # -------------------------------------------------------------------------------
77 
78 # Algo Resource Pool -----------------------------------------------------------
79 # Nothing special here, we just set the debug level.
80 AlgResourcePool(OutputLevel=DEBUG)
81 
82 CPUCrunchSvc(shortCalib=True)
83 
84 # -------------------------------------------------------------------------------
85 
86 # Set up of the crunchers, daily business --------------------------------------
87 
88 a1 = CPUCruncher("A1")
89 a1.outKeys = ['/Event/a1']
90 
91 a2 = CPUCruncher("A2")
92 a2.inpKeys = ['/Event/a1']
93 a2.outKeys = ['/Event/a2']
94 
95 a3 = CPUCruncher("A3")
96 a3.inpKeys = ['/Event/a1']
97 a3.outKeys = ['/Event/a3']
98 
99 a4 = CPUCruncher("A4")
100 a4.inpKeys = ['/Event/a2', '/Event/a3']
101 a4.outKeys = ['/Event/a4']
102 
103 for algo in [a1, a2, a3, a4]:
104  algo.Cardinality = cardinality
105  algo.OutputLevel = WARNING
106  algo.varRuntime = .3
107  algo.avgRuntime = .5
108 
109 ctrp = ContextEventCounterPtr("CNT*", Cardinality=0, OutputLevel=INFO)
110 ctrd = ContextEventCounterData("CNT&", Cardinality=0, OutputLevel=INFO)
111 
112 # Application Manager ----------------------------------------------------------
113 # We put everything together and change the type of message service
114 
116  EvtMax=evtMax,
117  EvtSel='NONE',
118  ExtSvc=[whiteboard],
119  EventLoop=slimeventloopmgr,
120  TopAlg=[a1, a2, a3, a4, ctrp, ctrd],
121  MessageSvcType="InertMessageSvc")
122 
123 # -------------------------------------------------------------------------------
Gaudi.Configuration
Definition: Configuration.py:1
ApplicationMgr
Definition: ApplicationMgr.h:57