| The Gaudi Framework v29r1 (5cd95fa2)

- 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.

25 : base_class( name, svcLoc ), m_isActive( false )
26 {
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:15

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 76 of file IOBoundAlgSchedulerSvc.cpp.

77 {
78
79 // Now it's running
80 m_isActive = true;
81
82 // Wait for actions pushed into the queue by finishing tasks.
83 action thisAction;
84 StatusCode sc( StatusCode::SUCCESS );
85
86 // Continue to wait if the scheduler is running or there is something to do
87 info() << "Start checking the queue of I/O-bound algorithm tasks.." << endmsg;
88 while ( m_isActive or m_actionsQueue.size() > 0 ) {
89 m_actionsQueue.pop( thisAction );
90 std::thread th( thisAction );
91 th.detach();
92 }
93 }
StatusCode::SUCCESS
Definition: StatusCode.h:31
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:28
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:209

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 103 of file IOBoundAlgSchedulerSvc.cpp.

104 {
105
106 if ( m_isActive ) {
107 // Drain the scheduler
108 // m_actionsQueue.push(std::bind(&IOBoundSchedulerSvc::m_drain,
109 // this));
110 // we set the flag in this thread, not in the last action, to avoid stall,
111 // since we execute tasks asynchronously, in a detached thread, and it's possible that
112 // the task doesn't complete by the time the last while-iteration is entered
113 m_isActive = false;
114 // This would be the last (empty) action, just to trigger one last while-iteration
115 m_actionsQueue.push( [this]() -> StatusCode { return StatusCode::SUCCESS; } );
116 }
117
118 return StatusCode::SUCCESS;
119 }
StatusCode::SUCCESS
Definition: StatusCode.h:31
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:28
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 55 of file IOBoundAlgSchedulerSvc.cpp.

56 {
57
58 StatusCode sc( Service::finalize() );
59 if ( !sc.isSuccess() ) warning() << "Base class could not be finalized" << endmsg;
60
61 sc = deactivate();
62 if ( !sc.isSuccess() ) warning() << "Scheduler could not be deactivated" << endmsg;
63
64 info() << "Joining preemptive scheduler's thread" << endmsg;
65 m_thread.join();
66
67 return sc;
68 }
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:28
IOBoundAlgSchedulerSvc::deactivate
StatusCode deactivate()
Deactivate scheduler.
Definition: IOBoundAlgSchedulerSvc.cpp:103
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

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.

38 {
39
40 // Initialise mother class (read properties, ...)
41 StatusCode sc( Service::initialize() );
42 if ( !sc.isSuccess() ) 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, this ) );
47
48 return sc;
49 }
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:28
std::bind
T bind(T...args)
IOBoundAlgSchedulerSvc::activate
void activate()
Activate scheduler.
Definition: IOBoundAlgSchedulerSvc.cpp:76
std::thread
STL class.
endmsg
MsgStream & endmsg(MsgStream &s)
MsgStream Modifier: endmsg. Calls the output method of the MsgStream.
Definition: MsgStream.h:209

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

Add an algorithm to local queue to run on accelerator.

Definition at line 121 of file IOBoundAlgSchedulerSvc.cpp.

122 {
123
124 // the temporary lambda should be moved into the queue in here
125 auto actionn = [&]() {
126 debug() << " .. launching I/O-bound algo-closure .. " << endmsg;
127 return task.execute();
128 };
129
130 m_actionsQueue.push( actionn );
131
132 // until the queue to accelerator becomes limited
133 return StatusCode::SUCCESS;
134 }
StatusCode::SUCCESS
Definition: StatusCode.h:31
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:209

## 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