| The Gaudi Framework v32r1 (f65d50dc)

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