The Gaudi Framework  v29r0 (ff2e7097)
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:
Collaboration diagram for IOBoundAlgSchedulerSvc:

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::stringgetInterfaceNames () 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< actionm_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

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 }
bool m_isActive
Flag to track if the scheduler is active or not.
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;
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 }
bool m_isActive
Flag to track if the scheduler is active or not.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
STL class.
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 }
bool m_isActive
Flag to track if the scheduler is active or not.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
StatusCode IOBoundAlgSchedulerSvc::finalize ( )
override

Finalise.

Here the scheduler is deactivated and the thread joined.

Definition at line 55 of file IOBoundAlgSchedulerSvc.cpp.

56 {
57 
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 }
StatusCode finalize() override
Definition: Service.cpp:174
std::thread m_thread
The thread in which the activate function runs.
T join(T...args)
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
StatusCode deactivate()
Deactivate scheduler.
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, ...)
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;
47 
48  return sc;
49 }
StatusCode initialize() override
Definition: Service.cpp:64
std::thread m_thread
The thread in which the activate function runs.
This class is used for returning status codes from appropriate routines.
Definition: StatusCode.h:28
T bind(T...args)
void activate()
Activate scheduler.
STL class.
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 }
virtual StatusCode execute()=0
tbb::concurrent_bounded_queue< action > m_actionsQueue
This is done since the copy of the lambda storage is too expensive.
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: