The Gaudi Framework  v39r1 (adb068b2)
FiberManager Class Reference

#include </builds/gaudi/Gaudi/GaudiHive/src/FiberManager.h>

Collaboration diagram for FiberManager:

Public Member Functions

 FiberManager (int n_threads)
 FiberManager constructor. More...
 
 ~FiberManager ()
 
template<typename F >
void schedule (F &&func)
 Schedule work to run on the asynchronous pool. More...
 

Private Attributes

boost::fibers::condition_variable m_shuttingDown_cv {}
 
boost::fibers::mutex m_shuttingDown_mtx {}
 
std::vector< std::threadm_threads
 
bool m_activated = false
 

Detailed Description

The FiberManager manages a pool of threads used to run boost::fiber fibers.

These fibers can be suspended while waiting for GPU operations (with CUDA and HIP support built-in), remote I/O operations, and the like, providing a base for asynchronous algorithm support.

Author
Beojan Stanislaus
Version
1.0
Date
November 2023

Definition at line 34 of file FiberManager.h.

Constructor & Destructor Documentation

◆ FiberManager()

FiberManager::FiberManager ( int  n_threads)
inline

FiberManager constructor.

Parameters
n_threadsNumber of threads for CPU portion of asynchronous algorithms. These are in addition to the TBB worker threads used for CPU algorithms.

Definition at line 41 of file FiberManager.h.

41  {
42  for ( int i = 0; i < n_threads; ++i ) {
44  boost::fibers::use_scheduling_algorithm<boost::fibers::algo::shared_work>( true );
46  m_shuttingDown_cv.wait( lck );
47  } ) );
48  }
49  }

◆ ~FiberManager()

FiberManager::~FiberManager ( )
inline

Definition at line 51 of file FiberManager.h.

51  {
52  m_shuttingDown_cv.notify_all();
53 
54  for ( std::thread& t : m_threads ) { t.join(); }
55  }

Member Function Documentation

◆ schedule()

template<typename F >
void FiberManager::schedule ( F &&  func)
inline

Schedule work to run on the asynchronous pool.

AsynchronousAlgorithms should use a relatively small amount of CPU time, and should use boost::fiber functionality to yield while waiting for offloaded work to complete.

Parameters
funcThe AlgTask, when used in AvalancheSchedulerSvc

Definition at line 66 of file FiberManager.h.

66  {
67  if ( !m_activated ) {
68  // Since we never call boost::this_fiber::yield, fibers never actually run on this thread
69  boost::fibers::use_scheduling_algorithm<boost::fibers::algo::shared_work>( true );
70  m_activated = true;
71  }
72  boost::fibers::fiber( boost::fibers::launch::post, std::forward<F>( func ) ).detach();
73  }

Member Data Documentation

◆ m_activated

bool FiberManager::m_activated = false
private

Definition at line 79 of file FiberManager.h.

◆ m_shuttingDown_cv

boost::fibers::condition_variable FiberManager::m_shuttingDown_cv {}
private

Definition at line 76 of file FiberManager.h.

◆ m_shuttingDown_mtx

boost::fibers::mutex FiberManager::m_shuttingDown_mtx {}
private

Definition at line 77 of file FiberManager.h.

◆ m_threads

std::vector<std::thread> FiberManager::m_threads
private

Definition at line 78 of file FiberManager.h.


The documentation for this class was generated from the following file:
FiberManager::m_threads
std::vector< std::thread > m_threads
Definition: FiberManager.h:78
prepareBenchmark.n_threads
n_threads
Definition: prepareBenchmark.py:40
bug_34121.t
t
Definition: bug_34121.py:31
std::thread
STL class.
cpluginsvc.func
func
Definition: cpluginsvc.py:235
std::unique_lock
STL class.
FiberManager::m_shuttingDown_mtx
boost::fibers::mutex m_shuttingDown_mtx
Definition: FiberManager.h:77
std::vector::emplace_back
T emplace_back(T... args)
FiberManager::m_activated
bool m_activated
Definition: FiberManager.h:79
FiberManager::m_shuttingDown_cv
boost::fibers::condition_variable m_shuttingDown_cv
Definition: FiberManager.h:76