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