| The Gaudi Framework v28r2-patches (bc4ad17a)

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

- Class List
- Class Index
- Class Hierarchy
- Class Members

Public Member Functions | Private Types | Private Member Functions | Private Attributes | List of all members
IOBoundAlgSchedulerSvc Class Reference

Please refer to the full documentation of the methods for more details. More...

`#include <GaudiHive/src/IOBoundAlgSchedulerSvc.h>`

Inheritance diagram for IOBoundAlgSchedulerSvc:
[legend]
Collaboration diagram for IOBoundAlgSchedulerSvc:
[legend]

## Public Member Functions
| IOBoundAlgSchedulerSvc (const std::string &name, ISvcLocator *svc)
| Constructor. More...
| ~IOBoundAlgSchedulerSvc () override
| Destructor. More...
StatusCode | initialize () override
| Initialise. More...
StatusCode | finalize () override
| Finalise. More...
StatusCode | push (IAlgTask &task) override
| Add an algorithm to local queue to run on accelerator. More...
Public Member Functions inherited from extends< BASE, Interfaces >
void * | i_cast (const InterfaceID &tid) const override
| Implementation of IInterface::i_cast. More...
StatusCode | queryInterface (const InterfaceID &ti, void **pp) override
| Implementation of IInterface::queryInterface. More...
std::vector< std::string > | getInterfaceNames () const override
| Implementation of IInterface::getInterfaceNames. More...
| ~extends () override=default
| Virtual destructor. More...
Public Member Functions inherited from extend_interfaces< Interfaces... >
| ~extend_interfaces () override=default
| Virtual destructor. More...

## Private Types
typedef std::function< StatusCode()> | action

## Private Member Functions
void | activate ()
| Activate scheduler. More...
StatusCode | deactivate ()
| Deactivate scheduler. More...

## Private Attributes
bool | m_isActive
| Flag to track if the scheduler is active or not. More...
std::thread | m_thread
| The thread in which the activate function runs. More...
tbb::concurrent_bounded_queue< action > | m_actionsQueue
| This is done since the copy of the lambda storage is too expensive. More...

## Additional Inherited Members
Public Types inherited from extends< BASE, Interfaces >
using | base_class = extends
| Typedef to this class. More...
using | extend_interfaces_base = extend_interfaces< Interfaces... >
| Typedef to the base of this class. More...
Public Types inherited from extend_interfaces< Interfaces... >
using | ext_iids = typename Gaudi::interface_list_cat< typename Interfaces::ext_iids... >::type
| take union of the ext_iids of all Interfaces... More...

## Detailed Description

Please refer to the full documentation of the methods for more details.

Author
  Illya Shapoval

Version
  1.0

Definition at line 25 of file IOBoundAlgSchedulerSvc.h.

## Member Typedef Documentation

typedef std::function<StatusCode()> IOBoundAlgSchedulerSvc::action
| private

Definition at line 60 of file IOBoundAlgSchedulerSvc.h.

## Constructor & Destructor Documentation

IOBoundAlgSchedulerSvc::IOBoundAlgSchedulerSvc | ( | const std::string & | name,
|  | ISvcLocator * | svc
| ) |  |

Constructor.

Definition at line 24 of file IOBoundAlgSchedulerSvc.cpp.

24 :
25 base_class(name,svcLoc),
26 m_isActive(false)
27 {}
IOBoundAlgSchedulerSvc::m_isActive
bool m_isActive
Flag to track if the scheduler is active or not.
Definition: IOBoundAlgSchedulerSvc.h:53
extends::base_class
extends base_class
Typedef to this class.
Definition: extends.h:14

IOBoundAlgSchedulerSvc::~IOBoundAlgSchedulerSvc | ( |  | ) |
| override

Destructor.

Definition at line 30 of file IOBoundAlgSchedulerSvc.cpp.

30 {}

## Member Function Documentation

void IOBoundAlgSchedulerSvc::activate | ( |  | ) |
| private

Activate scheduler.

Activate the scheduler.

From this moment on the queue of actions is checked. The checking will stop when the m_isActive flag is false and the queue is not empty. This will guarantee that all actions are executed and a stall is not created.

Definition at line 80 of file IOBoundAlgSchedulerSvc.cpp.

80 {
81
82 // Now it's running
83 m_isActive=true;
84
85 // Wait for actions pushed into the queue by finishing tasks.
86 action thisAction;
87 StatusCode sc(StatusCode::SUCCESS);
88
89 // Continue to wait if the scheduler is running or there is something to do
90 info() << "Start checking the queue of I/O-bound algorithm tasks.." << endmsg;
91 while(m_isActive or m_actionsQueue.size() > 0){
92 m_actionsQueue.pop(thisAction);
93 std::thread th(thisAction);
94 th.detach();
95 }
96 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
std::function< StatusCode()>
IOBoundAlgSchedulerSvc::m_isActive
bool m_isActive
Flag to track if the scheduler is active or not.
Definition: IOBoundAlgSchedulerSvc.h:53
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IOBoundAlgSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
Definition: IOBoundAlgSchedulerSvc.h:64
std::thread
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

StatusCode IOBoundAlgSchedulerSvc::deactivate | ( |  | ) |
| private

Deactivate scheduler.

Deactivates the scheduler.

Two actions are pushed into the queue: 1) Drain the scheduler until all events are finished. 2) Flip the status flag m_isActive to false This second action is the last one to be executed by the scheduler.

Definition at line 106 of file IOBoundAlgSchedulerSvc.cpp.

106 {
107
108 if (m_isActive){
109 // Drain the scheduler
110 //m_actionsQueue.push(std::bind(&IOBoundSchedulerSvc::m_drain,
111 // this));
112 // we set the flag in this thread, not in the last action, to avoid stall,
113 // since we execute tasks asynchronously, in a detached thread, and it's possible that
114 // the task doesn't complete by the time the last while-iteration is entered
115 m_isActive = false;
116 // This would be the last (empty) action, just to trigger one last while-iteration
117 m_actionsQueue.push([this]() -> StatusCode {return StatusCode::SUCCESS;});
118 }
119
120 return StatusCode::SUCCESS;
121 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
IOBoundAlgSchedulerSvc::m_isActive
bool m_isActive
Flag to track if the scheduler is active or not.
Definition: IOBoundAlgSchedulerSvc.h:53
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IOBoundAlgSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
Definition: IOBoundAlgSchedulerSvc.h:64

StatusCode IOBoundAlgSchedulerSvc::finalize | ( |  | ) |
| override

Finalise.

Here the scheduler is deactivated and the thread joined.

Definition at line 57 of file IOBoundAlgSchedulerSvc.cpp.

57 {
58
59 StatusCode sc(Service::finalize());
60 if (!sc.isSuccess())
61 warning () << "Base class could not be finalized" << endmsg;
62
63 sc = deactivate();
64 if (!sc.isSuccess())
65 warning () << "Scheduler could not be deactivated" << endmsg;
66
67 info() << "Joining preemptive scheduler's thread" << endmsg;
68 m_thread.join();
69
70 return sc;
71
72 }
Service::finalize
StatusCode finalize() override
Definition: Service.cpp:174
IOBoundAlgSchedulerSvc::m_thread
std::thread m_thread
The thread in which the activate function runs.
Definition: IOBoundAlgSchedulerSvc.h:56
std::thread::join
T join(T...args)
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
IOBoundAlgSchedulerSvc::deactivate
StatusCode deactivate()
Deactivate scheduler.
Definition: IOBoundAlgSchedulerSvc.cpp:106
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

StatusCode IOBoundAlgSchedulerSvc::initialize | ( |  | ) |
| override

Initialise.

Here, among some "bureaucracy" operations, the scheduler is activated, executing the activate() function in a new thread.

Definition at line 37 of file IOBoundAlgSchedulerSvc.cpp.

37 {
38
39 // Initialise mother class (read properties, ...)
40 StatusCode sc(Service::initialize());
41 if (!sc.isSuccess())
42 warning () << "Base class could not be initialized" << endmsg;
43
44 // Activate the scheduler in another thread.
45 info() << "Activating scheduler in a separate thread" << endmsg;
46 m_thread = std::thread (std::bind(&IOBoundAlgSchedulerSvc::activate,
47 this));
48
49 return sc;
50
51 }
Service::initialize
StatusCode initialize() override
Definition: Service.cpp:64
IOBoundAlgSchedulerSvc::m_thread
std::thread m_thread
The thread in which the activate function runs.
Definition: IOBoundAlgSchedulerSvc.h:56
StatusCode
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:26
std::bind
T bind(T...args)
IOBoundAlgSchedulerSvc::activate
void activate()
Activate scheduler.
Definition: IOBoundAlgSchedulerSvc.cpp:80
std::thread
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

StatusCode IOBoundAlgSchedulerSvc::push | ( | IAlgTask & | task | ) |
| override

Add an algorithm to local queue to run on accelerator.

Definition at line 123 of file IOBoundAlgSchedulerSvc.cpp.

123 {
124
125 // the temporary lambda should be moved into the queue in here
126 auto actionn = [&](){
127 debug() << " .. launching I/O-bound algo-closure .. " << endmsg;
128 return task.execute();
129 };
130
131 m_actionsQueue.push(actionn);
132
133 // until the queue to accelerator becomes limited
134 return StatusCode::SUCCESS;
135 }
StatusCode::SUCCESS
Definition: StatusCode.h:30
IAlgTask::execute
virtual StatusCode execute()=0
IOBoundAlgSchedulerSvc::m_actionsQueue
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
Definition: IOBoundAlgSchedulerSvc.h:64
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:244

## Member Data Documentation

tbb::concurrent_bounded_queue<action> IOBoundAlgSchedulerSvc::m_actionsQueue
| private

This is done since the copy of the lambda storage is too expensive.

Queue where closures are stored and picked for execution

Definition at line 64 of file IOBoundAlgSchedulerSvc.h.

bool IOBoundAlgSchedulerSvc::m_isActive
| private

Flag to track if the scheduler is active or not.

Definition at line 53 of file IOBoundAlgSchedulerSvc.h.

std::thread IOBoundAlgSchedulerSvc::m_thread
| private

The thread in which the activate function runs.

Definition at line 56 of file IOBoundAlgSchedulerSvc.h.

The documentation for this class was generated from the following files:

- GaudiHive/src/IOBoundAlgSchedulerSvc.h
- GaudiHive/src/IOBoundAlgSchedulerSvc.cpp