| The Gaudi Framework v27r1

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

ForwardSchedulerSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_FORWARDSCHEDULERSVC_H
2 #define GAUDIHIVE_FORWARDSCHEDULERSVC_H
3
4 // Framework include files
5 #include "GaudiKernel/IScheduler.h"
6 #include "GaudiKernel/IRunable.h"
7 #include "GaudiKernel/Service.h"
8 #include "GaudiKernel/IAlgResourcePool.h"
9 #include "GaudiKernel/IHiveWhiteBoard.h"
10 #include "GaudiKernel/IThreadPoolSvc.h"
11
12 // Local includes
13 #include "AlgsExecutionStates.h"
14 #include "EventSlot.h"
15 #include "ExecutionFlowManager.h"
16 #include "DataFlowManager.h"
17
18 // C++ include files
19 #include <vector>
20 #include <string>
21 #include <unordered_map>
22 #include <functional>
23 #include <thread>
24
25 // External libs
26 #include "tbb/concurrent_queue.h"
27
28 typedef AlgsExecutionStates::State State;
29
30 //---------------------------------------------------------------------------
31
73 class ForwardSchedulerSvc: public extends<Service,
74 IScheduler> {
75 public:
77 ForwardSchedulerSvc( const std::string& name, ISvcLocator* svc );
78
80 ~ForwardSchedulerSvc();
81
83 virtual StatusCode initialize();
84
86 virtual StatusCode finalize();
87
89 virtual StatusCode pushNewEvent(EventContext* eventContext);
90
91 // Make multiple events available to the scheduler
92 virtual StatusCode pushNewEvents(std::vector<EventContext*>& eventContexts);
93
95 virtual StatusCode popFinishedEvent(EventContext*& eventContext);
96
98 virtual StatusCode tryPopFinishedEvent(EventContext*& eventContext);
99
101 virtual unsigned int freeSlots();
102
103
104 private:
105
106 enum ActivationState {
107 INACTIVE = 0,
108 ACTIVE = 1,
109 FAILURE = 2
110 };
111
112 // Utils and shortcuts ----------------------------------------------------
113
115 void activate();
116
118 StatusCode deactivate();
119
121 std::atomic<ActivationState> m_isActive;
122
124 std::thread m_thread;
125
127 inline unsigned int algname2index(const std::string& algoname);
128
130 std::unordered_map<std::string,unsigned int> m_algname_index_map;
131
133 inline const std::string& index2algname (unsigned int index);
134
136 std::vector<std::string> m_algname_vect;
137
139 SmartIF<IHiveWhiteBoard> m_whiteboard;
140
142 std::string m_whiteboardSvcName;
143
145 std::vector<EventSlot> m_eventSlots;
146
148 int m_maxEventsInFlight;
149
151 std::atomic_int m_freeSlots;
152
154 tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
155
157 StatusCode eventFailed(EventContext* eventContext);
158
159
160 // States management ------------------------------------------------------
161
163 unsigned int m_maxAlgosInFlight;
164
166 unsigned int m_algosInFlight;
167
170 StatusCode updateStates(int si=-1, const std::string& algo_name=std::string());
171
173 StatusCode promoteToControlReady(unsigned int iAlgo, int si);
174 StatusCode promoteToDataReady(unsigned int iAlgo, int si);
175 StatusCode promoteToScheduled(unsigned int iAlgo, int si);
176 StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm* algo);
177 StatusCode promoteToFinished(unsigned int iAlgo, int si);
178
180 StatusCode isStalled(int si);
181
183 void dumpSchedulerState(int iSlot);
184
186 bool m_updateNeeded;
187
188 // Algos Management -------------------------------------------------------
190 SmartIF<IAlgResourcePool> m_algResourcePool;
191
193 std::vector<std::vector<std::string>> m_algosDependencies;
194
196 StatusCode m_drain();
197
199 int m_threadPoolSize;
200
201 // Actions management -----------------------------------------------------
202
203 typedef std::function<StatusCode ()> action;
204
206 tbb::concurrent_bounded_queue<action> m_actionsQueue;
207
209 concurrency::ExecutionFlowManager m_efManager;
210 // XXX: CF tests. Temporary property to switch between ControlFlow implementations
211 bool m_CFNext;
212 // XXX: CF tests. Temporary property to switch between DataFlow implementations
213 bool m_DFNext;
214 // Flag to perform single-pass simulation of execution flow before the actual execution
215 bool m_simulateExecution;
216 // Optimization mode in which algorithms, ready for execution, are prioritized in special way
217 std::string m_optimizationMode;
218 // Dump intra-event concurrency dynamics to csv file
219 bool m_dumpIntraEventDynamics;
220
221 // Needed to queue actions on algorithm finishing and decrement algos in flight
222 friend class AlgoExecutionTask;
223
224 // Service for thread pool initialization
225 SmartIF<IThreadPoolSvc> m_threadPoolSvc;
226
227 bool m_first;
228
229 class SchedulerState {
230
231 public:
232 SchedulerState(Algorithm* a, EventContext* e, pthread_t t):
233 m_a(a), m_e(*e), m_t(t)
234 {
235 }
236
237 Algorithm* alg() const { return m_a; }
238 EventContext ctx() const { return m_e; }
239 pthread_t thread() const { return m_t; }
240
241 friend std::ostream& operator<< (std::ostream& os, const SchedulerState& ss) {
242 os << ss.ctx()
243 << " a: " << ss.alg()->name()
244 << " [" << std::hex << ss.alg() << std::dec
245 << "] t: 0x" << std::hex << ss.thread() << std::dec;
246 return os;
247 }
248
249 bool operator== (const SchedulerState& ss) const {
250 return ( m_a == ss.alg() );
251 }
252
253 bool operator== (Algorithm* a) const {
254 return ( m_a == a );
255 }
256
257 bool operator< ( const SchedulerState& rhs) const {
258 return ( m_a < rhs.alg() );
259 }
260
261 private:
262 Algorithm* m_a;
263 EventContext m_e;
264 pthread_t m_t;
265
266 };
267
268 static std::list<SchedulerState> m_sState;
269 static std::mutex m_ssMut;
270
271 public:
272 void addAlg(Algorithm*, EventContext*, pthread_t);
273 bool delAlg(Algorithm*);
274 void dumpState();
275
276 private:
277 void dumpState(std::ostringstream&);
278
279 bool m_checkDeps;
280
281
282 };
283
284 #endif // GAUDIHIVE_FORWARDSCHEDULERSVC_H
ForwardSchedulerSvc::deactivate
StatusCode deactivate()
Deactivate scheduler.
Definition: ForwardSchedulerSvc.cpp:333
IThreadPoolSvc.h
ForwardSchedulerSvc::SchedulerState::SchedulerState
SchedulerState(Algorithm *a, EventContext *e, pthread_t t)
Definition: ForwardSchedulerSvc.h:232
ForwardSchedulerSvc::dumpState
void dumpState()
Definition: ForwardSchedulerSvc.cpp:1041
SmartIF< IHiveWhiteBoard >
ForwardSchedulerSvc::m_CFNext
bool m_CFNext
Definition: ForwardSchedulerSvc.h:211
ForwardSchedulerSvc::eventFailed
StatusCode eventFailed(EventContext *eventContext)
Method to check if an event failed and take appropriate actions.
Definition: ForwardSchedulerSvc.cpp:496
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ForwardSchedulerSvc::ForwardSchedulerSvc
ForwardSchedulerSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Definition: ForwardSchedulerSvc.cpp:37
ForwardSchedulerSvc::initialize
virtual StatusCode initialize()
Initialise.
Definition: ForwardSchedulerSvc.cpp:74
ForwardSchedulerSvc::m_algResourcePool
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
Definition: ForwardSchedulerSvc.h:190
std::atomic< ActivationState >
ExecutionFlowManager.h
std::function
ForwardSchedulerSvc::pushNewEvent
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
Definition: ForwardSchedulerSvc.cpp:370
IRunable.h
ForwardSchedulerSvc::isStalled
StatusCode isStalled(int si)
Check if the scheduling is in a stall.
Definition: ForwardSchedulerSvc.cpp:729
AlgoExecutionTask
Definition: AlgoExecutionTask.h:14
ForwardSchedulerSvc::m_optimizationMode
std::string m_optimizationMode
Definition: ForwardSchedulerSvc.h:217
ForwardSchedulerSvc::SchedulerState::m_e
EventContext m_e
Definition: ForwardSchedulerSvc.h:263
IAlgResourcePool.h
ForwardSchedulerSvc::FAILURE
Definition: ForwardSchedulerSvc.h:109
ForwardSchedulerSvc::SchedulerState
Definition: ForwardSchedulerSvc.h:229
ForwardSchedulerSvc::m_threadPoolSvc
SmartIF< IThreadPoolSvc > m_threadPoolSvc
Definition: ForwardSchedulerSvc.h:225
ForwardSchedulerSvc::popFinishedEvent
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.
Definition: ForwardSchedulerSvc.cpp:457
ForwardSchedulerSvc::m_maxAlgosInFlight
unsigned int m_maxAlgosInFlight
Maximum number of simultaneous algorithms.
Definition: ForwardSchedulerSvc.h:163
State
AlgsExecutionStates::State State
Definition: ForwardSchedulerSvc.h:28
IScheduler.h
ForwardSchedulerSvc
The SchedulerSvc implements the IScheduler interface.
Definition: ForwardSchedulerSvc.h:73
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
ForwardSchedulerSvc::m_whiteboard
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
Definition: ForwardSchedulerSvc.h:139
ForwardSchedulerSvc::promoteToExecuted
StatusCode promoteToExecuted(unsigned int iAlgo, int si, IAlgorithm *algo)
The call to this method is triggered only from within the AlgoExecutionTask.
Definition: ForwardSchedulerSvc.cpp:928
std::mutex
ForwardSchedulerSvc::tryPopFinishedEvent
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)
Try to fetch an event from the scheduler.
Definition: ForwardSchedulerSvc.cpp:479
ForwardSchedulerSvc::m_drain
StatusCode m_drain()
Drain the actions present in the queue.
Definition: ForwardSchedulerSvc.cpp:441
ForwardSchedulerSvc::ACTIVE
Definition: ForwardSchedulerSvc.h:108
ForwardSchedulerSvc::ActivationState
ActivationState
Definition: ForwardSchedulerSvc.h:106
std::string
STL class.
Algorithm::name
const std::string & name() const override
The identifying name of the algorithm object.
Definition: Algorithm.cpp:820
Service.h
ForwardSchedulerSvc::SchedulerState::thread
pthread_t thread() const
Definition: ForwardSchedulerSvc.h:239
ForwardSchedulerSvc::INACTIVE
Definition: ForwardSchedulerSvc.h:107
ForwardSchedulerSvc::m_freeSlots
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
Definition: ForwardSchedulerSvc.h:151
ForwardSchedulerSvc::~ForwardSchedulerSvc
~ForwardSchedulerSvc()
Destructor.
Definition: ForwardSchedulerSvc.cpp:66
ForwardSchedulerSvc::m_threadPoolSize
int m_threadPoolSize
Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose...
Definition: ForwardSchedulerSvc.h:199
ForwardSchedulerSvc::addAlg
void addAlg(Algorithm *, EventContext *, pthread_t)
Definition: ForwardSchedulerSvc.cpp:1002
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
ForwardSchedulerSvc::m_algosInFlight
unsigned int m_algosInFlight
Number of algoritms presently in flight.
Definition: ForwardSchedulerSvc.h:166
concurrency::ExecutionFlowManager
Manage the execution flow using an execution flow graph Once initialized, the graph is const and can ...
Definition: ExecutionFlowManager.h:21
ForwardSchedulerSvc::m_finishedEvents
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
Definition: ForwardSchedulerSvc.h:154
ForwardSchedulerSvc::m_thread
std::thread m_thread
The thread in which the activate function runs.
Definition: ForwardSchedulerSvc.h:124
ForwardSchedulerSvc::SchedulerState::operator<
bool operator<(const SchedulerState &rhs) const
Definition: ForwardSchedulerSvc.h:257
ForwardSchedulerSvc::m_algname_vect
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
Definition: ForwardSchedulerSvc.h:136
ForwardSchedulerSvc::m_sState
static std::list< SchedulerState > m_sState
Definition: ForwardSchedulerSvc.h:268
ForwardSchedulerSvc::m_eventSlots
std::vector< EventSlot > m_eventSlots
Vector of events slots.
Definition: ForwardSchedulerSvc.h:145
ForwardSchedulerSvc::promoteToScheduled
StatusCode promoteToScheduled(unsigned int iAlgo, int si)
Definition: ForwardSchedulerSvc.cpp:875
ForwardSchedulerSvc::promoteToFinished
StatusCode promoteToFinished(unsigned int iAlgo, int si)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
ForwardSchedulerSvc::m_whiteboardSvcName
std::string m_whiteboardSvcName
The whiteboard name.
Definition: ForwardSchedulerSvc.h:142
std::ostringstream
STL class.
ForwardSchedulerSvc::pushNewEvents
virtual StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts)
Definition: ForwardSchedulerSvc.cpp:423
ForwardSchedulerSvc::m_DFNext
bool m_DFNext
Definition: ForwardSchedulerSvc.h:213
ForwardSchedulerSvc::algname2index
unsigned int algname2index(const std::string &algoname)
Convert a name to an integer.
Definition: ForwardSchedulerSvc.cpp:357
ForwardSchedulerSvc::SchedulerState::operator==
bool operator==(const SchedulerState &ss) const
Definition: ForwardSchedulerSvc.h:249
ForwardSchedulerSvc::updateStates
StatusCode updateStates(int si=-1, const std::string &algo_name=std::string())
Loop on algorithm in the slots and promote them to successive states (-1 means all slots...
Definition: ForwardSchedulerSvc.cpp:534
ForwardSchedulerSvc::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: ForwardSchedulerSvc.h:130
std::list
STL class.
IAlgorithm
The IAlgorithm is the interface implemented by the Algorithm base class.
Definition: IAlgorithm.h:25
ForwardSchedulerSvc::freeSlots
virtual unsigned int freeSlots()
Get free slots number.
Definition: ForwardSchedulerSvc.cpp:433
ForwardSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
Queue where closures are stored and picked for execution.
Definition: ForwardSchedulerSvc.h:206
ForwardSchedulerSvc::m_updateNeeded
bool m_updateNeeded
Keep track of update actions scheduled.
Definition: ForwardSchedulerSvc.h:186
ForwardSchedulerSvc::action
std::function< StatusCode()> action
Definition: ForwardSchedulerSvc.h:203
Algorithm
Base class from which all concrete algorithm classes should be derived.
Definition: Algorithm.h:74
ForwardSchedulerSvc::SchedulerState::m_t
pthread_t m_t
Definition: ForwardSchedulerSvc.h:264
std::vector< EventContext * >
ForwardSchedulerSvc::activate
void activate()
Activate scheduler.
Definition: ForwardSchedulerSvc.cpp:295
ForwardSchedulerSvc::m_checkDeps
bool m_checkDeps
Definition: ForwardSchedulerSvc.h:279
ForwardSchedulerSvc::m_simulateExecution
bool m_simulateExecution
Definition: ForwardSchedulerSvc.h:215
IHiveWhiteBoard.h
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
ForwardSchedulerSvc::m_maxEventsInFlight
int m_maxEventsInFlight
Maximum number of event processed simultaneously.
Definition: ForwardSchedulerSvc.h:148
ForwardSchedulerSvc::promoteToControlReady
StatusCode promoteToControlReady(unsigned int iAlgo, int si)
Algorithm promotion: Accepted by the control flow.
Definition: ForwardSchedulerSvc.cpp:836
ForwardSchedulerSvc::m_efManager
concurrency::ExecutionFlowManager m_efManager
Member to take care of the control flow.
Definition: ForwardSchedulerSvc.h:209
ForwardSchedulerSvc::dumpSchedulerState
void dumpSchedulerState(int iSlot)
Dump the state of the scheduler.
Definition: ForwardSchedulerSvc.cpp:754
ForwardSchedulerSvc::m_dumpIntraEventDynamics
bool m_dumpIntraEventDynamics
Definition: ForwardSchedulerSvc.h:219
ForwardSchedulerSvc::SchedulerState::m_a
Algorithm * m_a
Definition: ForwardSchedulerSvc.h:262
std::hex
T hex(T...args)
ForwardSchedulerSvc::m_ssMut
static std::mutex m_ssMut
Definition: ForwardSchedulerSvc.h:269
ForwardSchedulerSvc::index2algname
const std::string & index2algname(unsigned int index)
Convert an integer to a name.
Definition: ForwardSchedulerSvc.cpp:351
ForwardSchedulerSvc::delAlg
bool delAlg(Algorithm *)
Definition: ForwardSchedulerSvc.cpp:1011
ForwardSchedulerSvc::finalize
virtual StatusCode finalize()
Finalise.
Definition: ForwardSchedulerSvc.cpp:266
ForwardSchedulerSvc::SchedulerState::ctx
EventContext ctx() const
Definition: ForwardSchedulerSvc.h:238
ForwardSchedulerSvc::SchedulerState::operator<<
friend std::ostream & operator<<(std::ostream &os, const SchedulerState &ss)
Definition: ForwardSchedulerSvc.h:241
ForwardSchedulerSvc::m_isActive
std::atomic< ActivationState > m_isActive
Flag to track if the scheduler is active or not.
Definition: ForwardSchedulerSvc.h:121
AlgsExecutionStates.h
ForwardSchedulerSvc::SchedulerState::alg
Algorithm * alg() const
Definition: ForwardSchedulerSvc.h:237
ForwardSchedulerSvc::m_first
bool m_first
Definition: ForwardSchedulerSvc.h:227
AlgsExecutionStates::State
State
Execution states of the algorithms.
Definition: AlgsExecutionStates.h:32
DataFlowManager.h
std::ostream
STL class.
std::thread
STL class.
ForwardSchedulerSvc::m_algosDependencies
std::vector< std::vector< std::string > > m_algosDependencies
DEPRECATED!
Definition: ForwardSchedulerSvc.h:193
EventSlot.h
ForwardSchedulerSvc::promoteToDataReady
StatusCode promoteToDataReady(unsigned int iAlgo, int si)
Definition: ForwardSchedulerSvc.cpp:851
std::unordered_map< std::string, unsigned int >