The Gaudi Framework  master (1304469f)
Loading...
Searching...
No Matches
AvalancheSchedulerSimpleTest.py
Go to the documentation of this file.
1#!/usr/bin/env gaudirun.py
2
12"""
13Reference optionfile which shows in a simple way how to take advantage of the
14Gaudi components desicated to concurrency.
15The 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
34The CPUCruncher is not a component dealing with concurrency, but a useful
35entity to test it. It's an algorithm that simply wastes cpu.
36
37"""
38
39from Configurables import (
40 AlgResourcePool,
41 AvalancheSchedulerSvc,
42 ContextEventCounterData,
43 ContextEventCounterPtr,
44 CPUCruncher,
45 CPUCrunchSvc,
46 HiveSlimEventLoopMgr,
47 HiveWhiteBoard,
48)
49from Gaudi.Configuration import *
50
51# metaconfig -------------------------------------------------------------------
52# It's confortable to collect the relevant parameters at the top of the optionfile
53evtslots = 23
54evtMax = 50
55cardinality = 10
56threads = 10
57# -------------------------------------------------------------------------------
58
59# The configuration of the whiteboard ------------------------------------------
60# It is useful to call it EventDataSvc to replace the usual data service with
61# the whiteboard transparently.
62
63whiteboard = HiveWhiteBoard("EventDataSvc", EventSlots=evtslots)
64
65# -------------------------------------------------------------------------------
66
67# Event Loop Manager -----------------------------------------------------------
68# It's called slim since it has less functionalities overall than the good-old
69# event loop manager. Here we just set its outputlevel to DEBUG.
70
71slimeventloopmgr = HiveSlimEventLoopMgr(SchedulerName="AvalancheSchedulerSvc")
72
73# -------------------------------------------------------------------------------
74
75# AvalancheScheduler -----------------------------------------------------------
76# We just decide how many algorithms in flight we want to have and how many
77# threads in the pool. The default value is -1, which is for TBB equivalent
78# to take over the whole machine.
79
81 ThreadPoolSize=threads, OutputLevel=WARNING, DataDepsGraphFile="graphDump.dot"
82)
83
84# -------------------------------------------------------------------------------
85
86CPUCrunchSvc(shortCalib=True)
87
88# -------------------------------------------------------------------------------
89
90# Set up of the crunchers, daily business --------------------------------------
91
92a1 = CPUCruncher("A1")
93a1.outKeys = ["/Event/a1"]
94
95a2 = CPUCruncher("A2")
96a2.inpKeys = ["/Event/a1"]
97a2.outKeys = ["/Event/a2"]
98
99a3 = CPUCruncher("A3")
100a3.inpKeys = ["/Event/a1"]
101a3.outKeys = ["/Event/a3"]
102
103a4 = CPUCruncher("A4")
104a4.inpKeys = ["/Event/a2", "/Event/a3"]
105a4.outKeys = ["/Event/a4"]
106
107for algo in [a1, a2, a3, a4]:
108 algo.Cardinality = cardinality
109 algo.OutputLevel = WARNING
110 algo.varRuntime = 0.3
111 algo.avgRuntime = 0.5
112
113ctrp = ContextEventCounterPtr("CNT*", Cardinality=0, OutputLevel=INFO)
114ctrd = ContextEventCounterData("CNT&", Cardinality=0, OutputLevel=INFO)
115
116# Application Manager ----------------------------------------------------------
117# We put everything together and change the type of message service
118
120 EvtMax=evtMax,
121 EvtSel="NONE",
122 ExtSvc=[whiteboard],
123 EventLoop=slimeventloopmgr,
124 TopAlg=[a1, a2, a3, a4, ctrp, ctrd],
125 MessageSvcType="InertMessageSvc",
126)
127
128# -------------------------------------------------------------------------------
The Application Manager class.
A class that implements a search for prime numbers.
Definition CPUCruncher.h:30
Data service base class.