The Gaudi Framework  v30r3 (a5ef0a68)
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
13 #include "GaudiKernel/ICondSvc.h"
15 #include "GaudiKernel/IRunable.h"
16 #include "GaudiKernel/IScheduler.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 {
102 public:
104  using extends::extends;
105 
107  ~AvalancheSchedulerSvc() override = default;
108 
110  StatusCode initialize() override;
111 
113  StatusCode finalize() override;
114 
116  StatusCode pushNewEvent( EventContext* eventContext ) override;
117 
118  // Make multiple events available to the scheduler
119  StatusCode pushNewEvents( std::vector<EventContext*>& eventContexts ) override;
120 
122  StatusCode popFinishedEvent( EventContext*& eventContext ) override;
123 
125  StatusCode tryPopFinishedEvent( EventContext*& eventContext ) override;
126 
128  unsigned int freeSlots() override;
129 
131  virtual StatusCode scheduleEventView( EventContext const* sourceContext, std::string const& nodeName,
132  EventContext* viewContext ) override;
133 
134 private:
137 
138  enum ActivationState { INACTIVE = 0, ACTIVE = 1, FAILURE = 2 };
139 
141  this, "ThreadPoolSize", -1,
142  "Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose"};
143  Gaudi::Property<std::string> m_whiteboardSvcName{this, "WhiteboardSvc", "EventDataSvc", "The whiteboard name"};
144  Gaudi::Property<std::string> m_IOBoundAlgSchedulerSvcName{this, "IOBoundAlgSchedulerSvc", "IOBoundAlgSchedulerSvc"};
145  Gaudi::Property<unsigned int> m_maxIOBoundAlgosInFlight{this, "MaxIOBoundAlgosInFlight", 0,
146  "Maximum number of simultaneous I/O-bound algorithms"};
148  this, "SimulateExecution", false,
149  "Flag to perform single-pass simulation of execution flow before the actual execution"};
151  "The following modes are currently available: PCE, COD, DRE, E"};
152  Gaudi::Property<bool> m_dumpIntraEventDynamics{this, "DumpIntraEventDynamics", false,
153  "Dump intra-event concurrency dynamics to csv file"};
154  Gaudi::Property<bool> m_useIOBoundAlgScheduler{this, "PreemptiveIOBoundTasks", false,
155  "Turn on preemptive way of scheduling of I/O-bound algorithms"};
156 
157  Gaudi::Property<bool> m_checkDeps{this, "CheckDependencies", false, "Runtime check of Algorithm Data Dependencies"};
158 
160  "Attribute unmet input dependencies to this DataLoader Algorithm"};
161 
162  Gaudi::Property<bool> m_enableCondSvc{this, "EnableConditions", false, "Enable ConditionsSvc"};
163 
164  Gaudi::Property<bool> m_showDataDeps{this, "ShowDataDependencies", true,
165  "Show the INPUT and OUTPUT data dependencies of Algorithms"};
166 
167  Gaudi::Property<bool> m_showDataFlow{this, "ShowDataFlow", false,
168  "Show the configuration of DataFlow between Algorithms"};
169 
170  Gaudi::Property<bool> m_showControlFlow{this, "ShowControlFlow", false,
171  "Show the configuration of all Algorithms and Sequences"};
172 
173  // Utils and shortcuts ----------------------------------------------------
174 
176  void activate();
177 
180 
183 
186 
188  inline unsigned int algname2index( const std::string& algoname );
189 
192 
194  inline const std::string& index2algname( unsigned int index );
195 
198 
201 
204 
207 
210 
212  std::atomic_int m_freeSlots;
213 
215  tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
216 
219 
222 
224  unsigned int m_algosInFlight = 0;
225 
227  unsigned int m_IOBoundAlgosInFlight = 0;
228 
229  // States management ------------------------------------------------------
230 
233  StatusCode updateStates( int si = -1, int algo_index = -1, EventContext* = nullptr );
234 
236  StatusCode promoteToScheduled( unsigned int iAlgo, int si, EventContext* );
237  StatusCode promoteToAsyncScheduled( unsigned int iAlgo, int si, EventContext* ); // tests of an asynchronous scheduler
238  StatusCode promoteToExecuted( unsigned int iAlgo, int si, IAlgorithm* algo, EventContext* );
239  StatusCode promoteToAsyncExecuted( unsigned int iAlgo, int si, IAlgorithm* algo,
240  EventContext* ); // tests of an asynchronous scheduler
241  StatusCode promoteToFinished( unsigned int iAlgo, int si );
242 
244  bool isStalled( const EventSlot& ) const;
246  void eventFailed( EventContext* eventContext );
247 
249  void dumpSchedulerState( int iSlot );
250 
251  // Algos Management -------------------------------------------------------
252 
255 
256  // Actions management -----------------------------------------------------
257 
259  tbb::concurrent_bounded_queue<action> m_actionsQueue;
261  // (accessed/modified from the control thread only)
263 
264  // ------------------------------------------------------------------------
265 
266  // Service for thread pool initialization
270 };
271 
272 #endif // GAUDIHIVE_AVALANCHESCHEDULERSVC_H
Gaudi::Property< bool > m_showDataFlow
StatusCode tryPopFinishedEvent(EventContext *&eventContext) override
Try to fetch an event from the scheduler.
Gaudi::Property< std::string > m_whiteboardSvcName
unsigned int m_IOBoundAlgosInFlight
Number of algorithms presently in flight.
SmartIF< IPrecedenceSvc > m_precSvc
A shortcut to the Precedence Service.
std::vector< unsigned int > m_actionsCounts
Bookkeeping of the number of actions in flight per slot.
Implementation of property with value of concrete type.
Definition: Property.h:381
Gaudi::Property< bool > m_dumpIntraEventDynamics
Gaudi::Property< bool > m_showDataDeps
StatusCode initialize() override
Initialise.
void dumpSchedulerState(int iSlot)
Dump the state of the scheduler.
void activate()
Activate scheduler.
Gaudi::Property< std::string > m_useDataLoader
Gaudi::Property< std::string > m_optimizationMode
This class represents an entry point to all the event specific data.
Definition: EventContext.h:24
unsigned int algname2index(const std::string &algoname)
Convert a name to an integer.
std::atomic< ActivationState > m_isActive
Flag to track if the scheduler is active or not.
std::unordered_map< std::string, unsigned int > m_algname_index_map
Map to bookkeep the information necessary to the name2index conversion.
Gaudi::Property< bool > m_checkDeps
STL class.
Gaudi::Property< bool > m_useIOBoundAlgScheduler
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
virtual StatusCode scheduleEventView(EventContext const *sourceContext, std::string const &nodeName, EventContext *viewContext) override
Method to inform the scheduler about event views.
StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts) override
unsigned int m_algosInFlight
Number of algorithms presently in flight.
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
StatusCode promoteToScheduled(unsigned int iAlgo, int si, EventContext *)
Algorithm promotion.
StatusCode updateStates(int si=-1, int algo_index=-1, EventContext *=nullptr)
Loop on algorithm in the slots and promote them to successive states (-1 for algo_index means skippin...
StatusCode popFinishedEvent(EventContext *&eventContext) override
Blocks until an event is available.
Gaudi::Property< bool > m_showControlFlow
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:51
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
Gaudi::Property< std::string > m_IOBoundAlgSchedulerSvcName
StatusCode finalize() override
Finalise.
~AvalancheSchedulerSvc() override=default
Destructor.
Gaudi::Property< int > m_threadPoolSize
SmartIF< IThreadPoolSvc > m_threadPoolSvc
SmartIF< IAccelerator > m_IOBoundAlgScheduler
A shortcut to IO-bound algorithm scheduler.
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:28
State
Execution states of the algorithms.
StatusCode promoteToAsyncScheduled(unsigned int iAlgo, int si, EventContext *)
StatusCode promoteToFinished(unsigned int iAlgo, int si)
StatusCode pushNewEvent(EventContext *eventContext) override
Make an event available to the scheduler.
STL class.
Gaudi::Property< bool > m_simulateExecution
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
Gaudi::Property< bool > m_enableCondSvc
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
Class representing the event slot.
Definition: EventSlot.h:10
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the AlgoExecutionTask.
SmartIF< ICondSvc > m_condSvc
A shortcut to service for Conditions handling.
void eventFailed(EventContext *eventContext)
Method to execute if an event failed.
unsigned int freeSlots() override
Get free slots number.
std::vector< EventSlot > m_eventSlots
Vector of events slots.
StatusCode promoteToAsyncExecuted(unsigned int iAlgo, int si, IAlgorithm *algo, EventContext *)
The call to this method is triggered only from within the IOBoundAlgTask.
StatusCode deactivate()
Deactivate scheduler.
STL class.
SmartIF< IAlgExecStateSvc > m_algExecStateSvc
Algorithm execution state manager.
Gaudi::Property< unsigned int > m_maxIOBoundAlgosInFlight
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
bool isStalled(const EventSlot &) const
Check if scheduling in a particular slot is in a stall.
std::thread m_thread
The thread in which the activate function runs.