Loading [MathJax]/extensions/tex2jax.js
The Gaudi Framework  v31r0 (aeb156f0)
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
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 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:
136 
137  enum ActivationState { INACTIVE = 0, ACTIVE = 1, FAILURE = 2 };
138 
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"};
147  this, "SimulateExecution", false,
148  "Flag to perform single-pass simulation of execution flow before the actual execution"};
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 
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 
181 
184 
187 
189  inline unsigned int algname2index( const std::string& algoname );
190 
193 
195  inline const std::string& index2algname( unsigned int index );
196 
199 
202 
205 
208 
211 
213  std::atomic_int m_freeSlots;
214 
216  tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
217 
220 
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 
256 
257  // Actions management -----------------------------------------------------
258 
260  tbb::concurrent_bounded_queue<action> m_actionsQueue;
262  // (accessed/modified from the control thread only)
264 
265  // ------------------------------------------------------------------------
266 
267  // Service for thread pool initialization
271 };
272 
273 #endif // GAUDIHIVE_AVALANCHESCHEDULERSVC_H
Gaudi::Property< bool > m_showDataFlow
StatusCode tryPopFinishedEvent(EventContext *&eventContext) override
Try to fetch an event from the scheduler.
virtual StatusCode scheduleEventView(const EventContext *sourceContext, const std::string &nodeName, std::unique_ptr< EventContext > viewContext) override
Method to inform the scheduler about event views.
Class representing an event slot.
Definition: EventSlot.h:14
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:352
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:31
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.
StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts) override
unsigned int m_algosInFlight
Number of algorithms presently in flight.
Gaudi::Property< bool > m_verboseSubSlots
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
StatusCode promoteToScheduled(unsigned int iAlgo, int si, EventContext *)
Algorithm promotion.
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:50
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.
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.
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...
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.