| The Gaudi Framework v32r1 (f65d50dc)

AvalancheSchedulerSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_AVALANCHESCHEDULERSVC_H
2 #define GAUDIHIVE_AVALANCHESCHEDULERSVC_H
3
4 // Local includes
5 #include "AlgsExecutionStates.h"
6 #include "EventSlot.h"
7 #include "PrecedenceSvc.h"
8
9 // Framework include files
10 #include "GaudiKernel/IAccelerator.h"
11 #include "GaudiKernel/IAlgExecStateSvc.h"
12 #include "GaudiKernel/IAlgResourcePool.h"
13 #include "GaudiKernel/ICondSvc.h"
14 #include "GaudiKernel/IHiveWhiteBoard.h"
15 #include "GaudiKernel/IRunable.h"
16 #include "GaudiKernel/IScheduler.h"
17 #include "GaudiKernel/IThreadPoolSvc.h"
18 #include "GaudiKernel/Service.h"
19
20 // C++ include files
21 #include <functional>
22 #include <string>
23 #include <thread>
24 #include <unordered_map>
25 #include <vector>
26
27 // External libs
28 #include "tbb/concurrent_queue.h"
29 #include "tbb/task.h"
30
31 class IAlgorithm;
32
33 //---------------------------------------------------------------------------
34
100 class AvalancheSchedulerSvc : public extends<Service, IScheduler> {
101 public:
103 using extends::extends;
104
106 ~AvalancheSchedulerSvc() override = default;
107
109 StatusCode initialize() override;
110
112 StatusCode finalize() override;
113
115 StatusCode pushNewEvent( EventContext* eventContext ) override;
116
117 // Make multiple events available to the scheduler
118 StatusCode pushNewEvents( std::vector<EventContext*>& eventContexts ) override;
119
121 StatusCode popFinishedEvent( EventContext*& eventContext ) override;
122
124 StatusCode tryPopFinishedEvent( EventContext*& eventContext ) override;
125
127 unsigned int freeSlots() override;
128
130 virtual StatusCode scheduleEventView( const EventContext* sourceContext, const std::string& nodeName,
131 std::unique_ptr<EventContext> viewContext ) override;
132
133 private:
134 using AState = AlgsExecutionStates::State;
135 using action = std::function<StatusCode()>;
136
137 enum ActivationState { INACTIVE = 0, ACTIVE = 1, FAILURE = 2 };
138
139 Gaudi::Property<int> m_threadPoolSize{
140 this, "ThreadPoolSize", -1,
141 "Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose"};
142 Gaudi::Property<std::string> m_whiteboardSvcName{this, "WhiteboardSvc", "EventDataSvc", "The whiteboard name"};
143 Gaudi::Property<std::string> m_IOBoundAlgSchedulerSvcName{this, "IOBoundAlgSchedulerSvc", "IOBoundAlgSchedulerSvc"};
144 Gaudi::Property<unsigned int> m_maxIOBoundAlgosInFlight{this, "MaxIOBoundAlgosInFlight", 0,
145 "Maximum number of simultaneous I/O-bound algorithms"};
146 Gaudi::Property<bool> m_simulateExecution{
147 this, "SimulateExecution", false,
148 "Flag to perform single-pass simulation of execution flow before the actual execution"};
149 Gaudi::Property<std::string> m_optimizationMode{this, "Optimizer", "",
150 "The following modes are currently available: PCE, COD, DRE, E"};
151 Gaudi::Property<bool> m_dumpIntraEventDynamics{this, "DumpIntraEventDynamics", false,
152 "Dump intra-event concurrency dynamics to csv file"};
153 Gaudi::Property<bool> m_useIOBoundAlgScheduler{this, "PreemptiveIOBoundTasks", false,
154 "Turn on preemptive way of scheduling of I/O-bound algorithms"};
155
156 Gaudi::Property<bool> m_checkDeps{this, "CheckDependencies", false, "Runtime check of Algorithm Data Dependencies"};
157
158 Gaudi::Property<std::string> m_useDataLoader{this, "DataLoaderAlg", "",
159 "Attribute unmet input dependencies to this DataLoader Algorithm"};
160
161 Gaudi::Property<bool> m_enableCondSvc{this, "EnableConditions", false, "Enable ConditionsSvc"};
162
163 Gaudi::Property<bool> m_showDataDeps{this, "ShowDataDependencies", true,
164 "Show the INPUT and OUTPUT data dependencies of Algorithms"};
165
166 Gaudi::Property<bool> m_showDataFlow{this, "ShowDataFlow", false,
167 "Show the configuration of DataFlow between Algorithms"};
168
169 Gaudi::Property<bool> m_showControlFlow{this, "ShowControlFlow", false,
170 "Show the configuration of all Algorithms and Sequences"};
171
172 Gaudi::Property<bool> m_verboseSubSlots{this, "VerboseSubSlots", false, "Dump algorithm states for all sub-slots"};
173
174 // Utils and shortcuts ----------------------------------------------------
175
177 void activate();
178
180 StatusCode deactivate();
181
183 std::atomic<ActivationState> m_isActive{INACTIVE};
184
186 std::thread m_thread;
187
189 inline unsigned int algname2index( const std::string& algoname );
190
192 std::unordered_map<std::string, unsigned int> m_algname_index_map;
193
195 inline const std::string& index2algname( unsigned int index );
196
198 std::vector<std::string> m_algname_vect;
199
201 SmartIF<IPrecedenceSvc> m_precSvc;
202
204 SmartIF<IHiveWhiteBoard> m_whiteboard;
205
207 SmartIF<IAccelerator> m_IOBoundAlgScheduler;
208
210 std::vector<EventSlot> m_eventSlots;
211
213 std::atomic_int m_freeSlots;
214
216 tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
217
219 SmartIF<IAlgExecStateSvc> m_algExecStateSvc;
220
222 SmartIF<ICondSvc> m_condSvc;
223
225 unsigned int m_algosInFlight = 0;
226
228 unsigned int m_IOBoundAlgosInFlight = 0;
229
230 // States management ------------------------------------------------------
231
234 StatusCode updateStates( int si = -1, int algo_index = -1, int sub_slot = -1, int source_slot = -1 );
235
237 StatusCode promoteToScheduled( unsigned int iAlgo, int si, EventContext* );
238 StatusCode promoteToAsyncScheduled( unsigned int iAlgo, int si, EventContext* ); // tests of an asynchronous scheduler
239 StatusCode promoteToExecuted( unsigned int iAlgo, int si, IAlgorithm* algo, EventContext* );
240 StatusCode promoteToAsyncExecuted( unsigned int iAlgo, int si, IAlgorithm* algo,
241 EventContext* ); // tests of an asynchronous scheduler
242 StatusCode promoteToFinished( unsigned int iAlgo, int si );
243
245 bool isStalled( const EventSlot& ) const;
247 void eventFailed( EventContext* eventContext );
248
250 void dumpSchedulerState( int iSlot );
251
252 // Algos Management -------------------------------------------------------
253
255 SmartIF<IAlgResourcePool> m_algResourcePool;
256
257 // Actions management -----------------------------------------------------
258
260 tbb::concurrent_bounded_queue<action> m_actionsQueue;
262 // (accessed/modified from the control thread only)
263 std::vector<unsigned int> m_actionsCounts;
264
265 // ------------------------------------------------------------------------
266
267 // Service for thread pool initialization
268 SmartIF<IThreadPoolSvc> m_threadPoolSvc;
269 size_t m_maxEventsInFlight{0};
270 size_t m_maxAlgosInFlight{1};
271 };
272
273 #endif // GAUDIHIVE_AVALANCHESCHEDULERSVC_H
AvalancheSchedulerSvc::m_showDataFlow
Gaudi::Property< bool > m_showDataFlow
Definition: AvalancheSchedulerSvc.h:166
IThreadPoolSvc.h
AvalancheSchedulerSvc::isStalled
bool isStalled(const EventSlot &) const
Check if scheduling in a particular slot is in a stall.
Definition: AvalancheSchedulerSvc.cpp:735
AvalancheSchedulerSvc::tryPopFinishedEvent
StatusCode tryPopFinishedEvent(EventContext *&eventContext) override
Try to fetch an event from the scheduler.
Definition: AvalancheSchedulerSvc.cpp:553
AvalancheSchedulerSvc::scheduleEventView
virtual StatusCode scheduleEventView(const EventContext *sourceContext, const std::string &nodeName, std::unique_ptr< EventContext > viewContext) override
Method to inform the scheduler about event views.
Definition: AvalancheSchedulerSvc.cpp:1110
SmartIF< IPrecedenceSvc >
EventSlot
Class representing an event slot.
Definition: EventSlot.h:14
AvalancheSchedulerSvc::INACTIVE
Definition: AvalancheSchedulerSvc.h:137
AvalancheSchedulerSvc::m_whiteboardSvcName
Gaudi::Property< std::string > m_whiteboardSvcName
Definition: AvalancheSchedulerSvc.h:142
AvalancheSchedulerSvc::m_IOBoundAlgosInFlight
unsigned int m_IOBoundAlgosInFlight
Number of algorithms presently in flight.
Definition: AvalancheSchedulerSvc.h:228
AvalancheSchedulerSvc::m_precSvc
SmartIF< IPrecedenceSvc > m_precSvc
A shortcut to the Precedence Service.
Definition: AvalancheSchedulerSvc.h:201
std::atomic< ActivationState >
AvalancheSchedulerSvc::m_actionsCounts
std::vector< unsigned int > m_actionsCounts
Bookkeeping of the number of actions in flight per slot.
Definition: AvalancheSchedulerSvc.h:263
IAlgExecStateSvc.h
std::function< StatusCode()>
Gaudi::Property
Implementation of property with value of concrete type.
Definition: Property.h:352
AvalancheSchedulerSvc::m_dumpIntraEventDynamics
Gaudi::Property< bool > m_dumpIntraEventDynamics
Definition: AvalancheSchedulerSvc.h:151
AvalancheSchedulerSvc::m_showDataDeps
Gaudi::Property< bool > m_showDataDeps
Definition: AvalancheSchedulerSvc.h:163
AvalancheSchedulerSvc::initialize
StatusCode initialize() override
Initialise.
Definition: AvalancheSchedulerSvc.cpp:63
AvalancheSchedulerSvc::dumpSchedulerState
void dumpSchedulerState(int iSlot)
Dump the state of the scheduler.
Definition: AvalancheSchedulerSvc.cpp:775
IRunable.h
IAlgResourcePool.h
AvalancheSchedulerSvc::ACTIVE
Definition: AvalancheSchedulerSvc.h:137
AvalancheSchedulerSvc::activate
void activate()
Activate scheduler.
Definition: AvalancheSchedulerSvc.cpp:368
AvalancheSchedulerSvc::m_useDataLoader
Gaudi::Property< std::string > m_useDataLoader
Definition: AvalancheSchedulerSvc.h:158
AvalancheSchedulerSvc::m_optimizationMode
Gaudi::Property< std::string > m_optimizationMode
Definition: AvalancheSchedulerSvc.h:149
IScheduler.h
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
AvalancheSchedulerSvc::algname2index
unsigned int algname2index(const std::string &algoname)
Convert a name to an integer.
Definition: AvalancheSchedulerSvc.cpp:443
AvalancheSchedulerSvc::m_isActive
std::atomic< ActivationState > m_isActive
Flag to track if the scheduler is active or not.
Definition: AvalancheSchedulerSvc.h:183
AvalancheSchedulerSvc::m_algname_index_map
std::unordered_map< std::string, unsigned int > m_algname_index_map
Map to bookkeep the information necessary to the name2index conversion.
Definition: AvalancheSchedulerSvc.h:192
AvalancheSchedulerSvc::m_checkDeps
Gaudi::Property< bool > m_checkDeps
Definition: AvalancheSchedulerSvc.h:156
std::string
STL class.
AvalancheSchedulerSvc::m_useIOBoundAlgScheduler
Gaudi::Property< bool > m_useIOBoundAlgScheduler
Definition: AvalancheSchedulerSvc.h:153
Service.h
AvalancheSchedulerSvc::m_freeSlots
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
Definition: AvalancheSchedulerSvc.h:213
AvalancheSchedulerSvc::pushNewEvents
StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts) override
Definition: AvalancheSchedulerSvc.cpp:515
AvalancheSchedulerSvc::m_algosInFlight
unsigned int m_algosInFlight
Number of algorithms presently in flight.
Definition: AvalancheSchedulerSvc.h:225
AvalancheSchedulerSvc::m_verboseSubSlots
Gaudi::Property< bool > m_verboseSubSlots
Definition: AvalancheSchedulerSvc.h:172
AvalancheSchedulerSvc::m_algResourcePool
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
Definition: AvalancheSchedulerSvc.h:255
AvalancheSchedulerSvc::promoteToScheduled
StatusCode promoteToScheduled(unsigned int iAlgo, int si, EventContext *)
Algorithm promotion.
Definition: AvalancheSchedulerSvc.cpp:885
AvalancheSchedulerSvc::popFinishedEvent
StatusCode popFinishedEvent(EventContext *&eventContext) override
Blocks until an event is available.
Definition: AvalancheSchedulerSvc.cpp:532
AvalancheSchedulerSvc::ActivationState
ActivationState
Definition: AvalancheSchedulerSvc.h:137
AvalancheSchedulerSvc::m_showControlFlow
Gaudi::Property< bool > m_showControlFlow
Definition: AvalancheSchedulerSvc.h:169
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:50
AvalancheSchedulerSvc::m_whiteboard
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
Definition: AvalancheSchedulerSvc.h:204
AvalancheSchedulerSvc::m_finishedEvents
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
Definition: AvalancheSchedulerSvc.h:216
AvalancheSchedulerSvc::m_algname_vect
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
Definition: AvalancheSchedulerSvc.h:198
AvalancheSchedulerSvc::m_IOBoundAlgSchedulerSvcName
Gaudi::Property< std::string > m_IOBoundAlgSchedulerSvcName
Definition: AvalancheSchedulerSvc.h:143
AvalancheSchedulerSvc::finalize
StatusCode finalize() override
Finalise.
Definition: AvalancheSchedulerSvc.cpp:337
AvalancheSchedulerSvc::~AvalancheSchedulerSvc
~AvalancheSchedulerSvc() override=default
Destructor.
AvalancheSchedulerSvc::m_threadPoolSize
Gaudi::Property< int > m_threadPoolSize
Definition: AvalancheSchedulerSvc.h:139
AvalancheSchedulerSvc::m_threadPoolSvc
SmartIF< IThreadPoolSvc > m_threadPoolSvc
Definition: AvalancheSchedulerSvc.h:268
AvalancheSchedulerSvc::m_IOBoundAlgScheduler
SmartIF< IAccelerator > m_IOBoundAlgScheduler
A shortcut to IO-bound algorithm scheduler.
Definition: AvalancheSchedulerSvc.h:207
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
AlgsExecutionStates::State
State
Execution states of the algorithms.
Definition: AlgsExecutionStates.h:29
AvalancheSchedulerSvc
Definition: AvalancheSchedulerSvc.h:100
AvalancheSchedulerSvc::promoteToAsyncScheduled
StatusCode promoteToAsyncScheduled(unsigned int iAlgo, int si, EventContext *)
Definition: AvalancheSchedulerSvc.cpp:946
AvalancheSchedulerSvc::promoteToFinished
StatusCode promoteToFinished(unsigned int iAlgo, int si)
AvalancheSchedulerSvc::pushNewEvent
StatusCode pushNewEvent(EventContext *eventContext) override
Make an event available to the scheduler.
Definition: AvalancheSchedulerSvc.cpp:457
std::vector
STL class.
std::unique_ptr< EventContext >
AvalancheSchedulerSvc::m_simulateExecution
Gaudi::Property< bool > m_simulateExecution
Definition: AvalancheSchedulerSvc.h:146
IHiveWhiteBoard.h
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
AvalancheSchedulerSvc::m_enableCondSvc
Gaudi::Property< bool > m_enableCondSvc
Definition: AvalancheSchedulerSvc.h:161
AvalancheSchedulerSvc::index2algname
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
Definition: AvalancheSchedulerSvc.cpp:439
PrecedenceSvc.h
AvalancheSchedulerSvc::m_maxAlgosInFlight
size_t m_maxAlgosInFlight
Definition: AvalancheSchedulerSvc.h:270
AvalancheSchedulerSvc::promoteToExecuted
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the AlgoExecutionTask.
Definition: AvalancheSchedulerSvc.cpp:1002
AvalancheSchedulerSvc::m_condSvc
SmartIF< ICondSvc > m_condSvc
A shortcut to service for Conditions handling.
Definition: AvalancheSchedulerSvc.h:222
AvalancheSchedulerSvc::eventFailed
void eventFailed(EventContext *eventContext)
Method to execute if an event failed.
Definition: AvalancheSchedulerSvc.cpp:754
AvalancheSchedulerSvc::freeSlots
unsigned int freeSlots() override
Get free slots number.
Definition: AvalancheSchedulerSvc.cpp:526
AvalancheSchedulerSvc::m_eventSlots
std::vector< EventSlot > m_eventSlots
Vector of events slots.
Definition: AvalancheSchedulerSvc.h:210
AvalancheSchedulerSvc::promoteToAsyncExecuted
StatusCode promoteToAsyncExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the IOBoundAlgTask.
Definition: AvalancheSchedulerSvc.cpp:1056
AvalancheSchedulerSvc::deactivate
StatusCode deactivate()
Deactivate scheduler.
Definition: AvalancheSchedulerSvc.cpp:413
AlgsExecutionStates.h
AvalancheSchedulerSvc::FAILURE
Definition: AvalancheSchedulerSvc.h:137
AvalancheSchedulerSvc::updateStates
StatusCode updateStates(int si=-1, int algo_index=-1, int sub_slot=-1, int source_slot=-1)
Loop on algorithm in the slots and promote them to successive states (-1 for algo_index means skippin...
Definition: AvalancheSchedulerSvc.cpp:576
ICondSvc.h
IAccelerator.h
std::thread
STL class.
AvalancheSchedulerSvc::m_algExecStateSvc
SmartIF< IAlgExecStateSvc > m_algExecStateSvc
Algorithm execution state manager.
Definition: AvalancheSchedulerSvc.h:219
AvalancheSchedulerSvc::m_maxIOBoundAlgosInFlight
Gaudi::Property< unsigned int > m_maxIOBoundAlgosInFlight
Definition: AvalancheSchedulerSvc.h:144
AvalancheSchedulerSvc::m_maxEventsInFlight
size_t m_maxEventsInFlight
Definition: AvalancheSchedulerSvc.h:269
EventSlot.h
AvalancheSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
Definition: AvalancheSchedulerSvc.h:260
std::unordered_map< std::string, unsigned int >
AvalancheSchedulerSvc::m_thread
std::thread m_thread
The thread in which the activate function runs.
Definition: AvalancheSchedulerSvc.h:186