| The Gaudi Framework v27r1

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

- File List
- File Members

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 extends<Service,
42 IScheduler> {
43 public:
45 ParallelSequentialSchedulerSvc( const std::string& name, ISvcLocator* svc );
46
48 ~ParallelSequentialSchedulerSvc();
49
51 virtual StatusCode initialize();
52
54 virtual StatusCode finalize();
55
57 virtual StatusCode pushNewEvent(EventContext* eventContext);
58
59 // Make multiple events available to the scheduler
60 virtual StatusCode pushNewEvents(std::vector<EventContext*>& eventContexts);
61
63 virtual StatusCode popFinishedEvent(EventContext*& eventContext);
64
66 virtual StatusCode tryPopFinishedEvent(EventContext*& eventContext);
67
69 virtual unsigned int freeSlots();
70
71
72 private:
73
75 bool m_useTopAlgList;
76
78 std::list<IAlgorithm*> m_algList;
79
81 tbb::concurrent_bounded_queue<EventContext*> m_finishedEvents;
82
84 // number of events in flight
85 std::atomic_int m_freeSlots;
86
88 SmartIF<IHiveWhiteBoard> m_whiteboard;
89
91 std::string m_whiteboardSvcName;
92
94 SmartIF<IAlgResourcePool> m_algResourcePool;
95
97 int m_threadPoolSize;
98
99 //TBB scheduler
100 std::unique_ptr<tbb::task_scheduler_init> m_tbb_sched;
101
102 //control flow manager
103 concurrency::ExecutionFlowManager m_controlFlow;
104
106 std::vector<std::string> m_algname_vect;
107
109 std::unordered_map<std::string,unsigned int> m_algname_index_map;
110
111 // Needed to queue actions on algorithm finishing and decrement algos in flight
112 friend class SequentialTask;
113
114 };
115
116 class SequentialTask: public tbb::task {
117 public:
118 SequentialTask(ISvcLocator* svcLocator,
119 EventContext* eventContext,
120 ParallelSequentialSchedulerSvc* scheduler,
121 IAlgResourcePool* algPool):
122
123 m_serviceLocator(svcLocator),
124 m_eventContext(eventContext),
125 m_scheduler(scheduler),
126 m_algPool(algPool){
127
128 };
129 virtual tbb::task* execute();
130 private:
131 SmartIF<ISvcLocator> m_serviceLocator;
132 EventContext* m_eventContext;
133 SmartIF<ParallelSequentialSchedulerSvc> m_scheduler;
134 SmartIF<IAlgResourcePool> m_algPool;
135 };
136
137 #endif // GAUDIHIVE_PARALLELSEQUENTIALSCHEDULERSVC_H
ParallelSequentialSchedulerSvc::m_algList
std::list< IAlgorithm * > m_algList
Cache the list of algs to be executed.
Definition: ParallelSequentialSchedulerSvc.h:78
SmartIF< IHiveWhiteBoard >
SequentialTask::execute
virtual tbb::task * execute()
Definition: ParallelSequentialSchedulerSvc.cpp:224
ISvcLocator
The ISvcLocator is the interface implemented by the Service Factory in the Application Manager to loc...
Definition: ISvcLocator.h:25
ExecutionFlowManager.h
ParallelSequentialSchedulerSvc::ParallelSequentialSchedulerSvc
ParallelSequentialSchedulerSvc(const std::string &name, ISvcLocator *svc)
Constructor.
Definition: ParallelSequentialSchedulerSvc.cpp:28
IRunable.h
IAlgResourcePool.h
ParallelSequentialSchedulerSvc::m_tbb_sched
std::unique_ptr< tbb::task_scheduler_init > m_tbb_sched
Definition: ParallelSequentialSchedulerSvc.h:100
EventContext.h
SequentialTask::m_scheduler
SmartIF< ParallelSequentialSchedulerSvc > m_scheduler
Definition: ParallelSequentialSchedulerSvc.h:133
SequentialTask::m_eventContext
EventContext * m_eventContext
Definition: ParallelSequentialSchedulerSvc.h:132
ParallelSequentialSchedulerSvc::m_finishedEvents
tbb::concurrent_bounded_queue< EventContext * > m_finishedEvents
Queue of finished events.
Definition: ParallelSequentialSchedulerSvc.h:81
SequentialTask::SequentialTask
SequentialTask(ISvcLocator *svcLocator, EventContext *eventContext, ParallelSequentialSchedulerSvc *scheduler, IAlgResourcePool *algPool)
Definition: ParallelSequentialSchedulerSvc.h:118
IScheduler.h
EventContext
This class represents an entry point to all the event specific data.
Definition: EventContext.h:25
ParallelSequentialSchedulerSvc::pushNewEvent
virtual StatusCode pushNewEvent(EventContext *eventContext)
Make an event available to the scheduler.
Definition: ParallelSequentialSchedulerSvc.cpp:160
std::string
STL class.
IAlgResourcePool
The IAlgResourcePool is the interface for managing algorithm instances, in particular if clones of th...
Definition: IAlgResourcePool.h:27
Service.h
Service::name
const std::string & name() const override
Retrieve name of the service.
Definition: Service.cpp:319
ParallelSequentialSchedulerSvc::m_useTopAlgList
bool m_useTopAlgList
Decide if the top alglist or its flat version has to be used.
Definition: ParallelSequentialSchedulerSvc.h:75
ParallelSequentialSchedulerSvc::m_whiteboard
SmartIF< IHiveWhiteBoard > m_whiteboard
A shortcut to the whiteboard.
Definition: ParallelSequentialSchedulerSvc.h:88
SequentialTask
Definition: ParallelSequentialSchedulerSvc.h:116
ParallelSequentialSchedulerSvc::m_threadPoolSize
int m_threadPoolSize
Size of the threadpool initialised by TBB; a value of -1 gives TBB the freedom to choose...
Definition: ParallelSequentialSchedulerSvc.h:97
SequentialTask::m_algPool
SmartIF< IAlgResourcePool > m_algPool
Definition: ParallelSequentialSchedulerSvc.h:134
Gaudi::svcLocator
GAUDI_API ISvcLocator * svcLocator()
concurrency::ExecutionFlowManager
Manage the execution flow using an execution flow graph Once initialized, the graph is const and can ...
Definition: ExecutionFlowManager.h:21
ParallelSequentialSchedulerSvc::pushNewEvents
virtual StatusCode pushNewEvents(std::vector< EventContext * > &eventContexts)
Definition: ParallelSequentialSchedulerSvc.cpp:167
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
CommonMessaging.h
ParallelSequentialSchedulerSvc::m_whiteboardSvcName
std::string m_whiteboardSvcName
The whiteboard name.
Definition: ParallelSequentialSchedulerSvc.h:91
ParallelSequentialSchedulerSvc::m_freeSlots
std::atomic_int m_freeSlots
Atomic to account for asyncronous updates by the scheduler wrt the rest.
Definition: ParallelSequentialSchedulerSvc.h:85
ParallelSequentialSchedulerSvc::freeSlots
virtual unsigned int freeSlots()
Get free slots number.
Definition: ParallelSequentialSchedulerSvc.cpp:220
ParallelSequentialSchedulerSvc::~ParallelSequentialSchedulerSvc
~ParallelSequentialSchedulerSvc()
Destructor.
Definition: ParallelSequentialSchedulerSvc.cpp:38
std::list< IAlgorithm * >
std::vector< EventContext * >
std::unique_ptr< tbb::task_scheduler_init >
extends
Base class used to extend a class implementing other interfaces.
Definition: extends.h:10
SequentialTask::m_serviceLocator
SmartIF< ISvcLocator > m_serviceLocator
Definition: ParallelSequentialSchedulerSvc.h:131
ParallelSequentialSchedulerSvc::finalize
virtual StatusCode finalize()
Finalise.
Definition: ParallelSequentialSchedulerSvc.cpp:148
AlgResourcePool.h
AtomicAlgSequencerTest.scheduler
tuple scheduler
Definition: AtomicAlgSequencerTest.py:39
DataFlowManager.h
ParallelSequentialSchedulerSvc::m_algname_vect
std::vector< std::string > m_algname_vect
Vector to bookkeep the information necessary to the index2name conversion.
Definition: ParallelSequentialSchedulerSvc.h:106
ParallelSequentialSchedulerSvc::m_controlFlow
concurrency::ExecutionFlowManager m_controlFlow
Definition: ParallelSequentialSchedulerSvc.h:103
ParallelSequentialSchedulerSvc
This SchedulerSvc implements the IScheduler interface.
Definition: ParallelSequentialSchedulerSvc.h:41
ParallelSequentialSchedulerSvc::initialize
virtual StatusCode initialize()
Initialise.
Definition: ParallelSequentialSchedulerSvc.cpp:41
ParallelSequentialSchedulerSvc::m_algResourcePool
SmartIF< IAlgResourcePool > m_algResourcePool
Cache for the algorithm resource pool.
Definition: ParallelSequentialSchedulerSvc.h:94
ParallelSequentialSchedulerSvc::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: ParallelSequentialSchedulerSvc.h:109
ParallelSequentialSchedulerSvc::tryPopFinishedEvent
virtual StatusCode tryPopFinishedEvent(EventContext *&eventContext)
Try to fetch an event from the scheduler.
Definition: ParallelSequentialSchedulerSvc.cpp:205
ParallelSequentialSchedulerSvc::popFinishedEvent
virtual StatusCode popFinishedEvent(EventContext *&eventContext)
Blocks until an event is availble.
Definition: ParallelSequentialSchedulerSvc.cpp:192
std::unordered_map< std::string, unsigned int >