All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
ParallelSequentialSchedulerSvc.h
Go to the documentation of this file.
1 #ifndef GAUDIHIVE_PARALLELSEQUENTIALSCHEDULERSVC_H
2 #define GAUDIHIVE_PARALLELSEQUENTIALSCHEDULERSVC_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/CommonMessaging.h"
10 #include "GaudiKernel/EventContext.h"
11 
12 #include "AlgResourcePool.h"
13 #include "ExecutionFlowManager.h"
14 #include "DataFlowManager.h"
15 
16 // C++ include files
17 #include <vector>
18 #include <string>
19 #include <unordered_map>
20 #include <functional>
21 #include <thread>
22 
23 // External libs
24 #include "tbb/concurrent_queue.h"
25 #include "tbb/task.h"
26 #include "tbb/task_scheduler_init.h"
27 
28 class SequentialTask; //forward declaration
29 
30 
31 //---------------------------------------------------------------------------
32 
41 class ParallelSequentialSchedulerSvc: public extends1<Service, IScheduler> {
42 public:
44  ParallelSequentialSchedulerSvc( const std::string& name, ISvcLocator* svc );
45 
48 
50  virtual StatusCode initialize();
51 
53  virtual StatusCode finalize();
54 
56  virtual StatusCode pushNewEvent(EventContext* eventContext);
57 
58  // Make multiple events available to the scheduler
59  virtual StatusCode pushNewEvents(std::vector<EventContext*>& eventContexts);
60 
62  virtual StatusCode popFinishedEvent(EventContext*& eventContext);
63 
65  virtual StatusCode tryPopFinishedEvent(EventContext*& eventContext);
66 
68  virtual unsigned int freeSlots();
69 
70 
71 private:
72 
75 
77  std::list<IAlgorithm*> m_algList;
78 
80  tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
81 
83  // number of events in flight
84  std::atomic_int m_freeSlots;
85 
88 
90  std::string m_whiteboardSvcName;
91 
94 
97 
98  //TBB scheduler
99  std::unique_ptr<tbb::task_scheduler_init> m_tbb_sched;
100 
101  //control flow manager
103 
105  std::vector<std::string> m_algname_vect;
106 
108  std::unordered_map<std::string,unsigned int> m_algname_index_map;
109 
111  std::vector<std::vector<std::string>> m_algosDependencies;
112 
113  // Needed to queue actions on algorithm finishing and decrement algos in flight
114  friend class SequentialTask;
115 
116 };
117 
118 class SequentialTask: public tbb::task {
119 public:
121  EventContext* eventContext,
123  IAlgResourcePool* algPool):
124 
125  m_serviceLocator(svcLocator),
126  m_eventContext(eventContext),
127  m_scheduler(scheduler),
128  m_algPool(algPool){
129 
130  };
131  virtual tbb::task* execute();
132 private:
137 };
138 
139 #endif // GAUDIHIVE_PARALLELSEQUENTIALSCHEDULERSVC_H
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
virtual tbb::task * execute()
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ParallelSequentialSchedulerSvc(const std::string &name, ISvcLocator *svc)
Constructor.
std::unique_ptr< tbb::task_scheduler_init > m_tbb_sched
SmartIF< ParallelSequentialSchedulerSvc > m_scheduler
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
SequentialTask(ISvcLocator *svcLocator, EventContext *eventContext, ParallelSequentialSchedulerSvc *scheduler, IAlgResourcePool *algPool)
This class represents an entry point to all the event specific data.
Definition: EventContext.h:22
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
The IAlgResourcePool is the interface for managing algorithm instances, in particular if clones of th...
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
int m_threadPoolSize
Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose...
SmartIF< IAlgResourcePool > m_algPool
GAUDI_API ISvcLocator * svcLocator()
Manage the execution flow using an execution flow graph Once initialized, the graph is const and can ...
virtual StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::string m_whiteboardSvcName
The whiteboard name.
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
virtual unsigned int freeSlots()
Get free slots number.
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
SmartIF< ISvcLocator > m_serviceLocator
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
concurrency::ExecutionFlowManager m_controlFlow
This SchedulerSvc implements the IScheduler interface.
virtual StatusCode initialize()
Initialise.
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
std::unordered_map< std::string, unsigned int > m_algname_index_map
Map to bookkeep the information necessary to the name2index conversion.
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)
Try to fetch an event from the scheduler.
std::vector< std::vector< std::string > > m_algosDependencies
Ugly, will disappear when the deps are declared only within the C++ code of the algos.
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.