Skip to content
Snippets Groups Projects
Commit 215f2b11 authored by Marco Clemencic's avatar Marco Clemencic
Browse files

added ConcurrencyFlags class

The static ConcurrencyFlags allows easy access to information
about the number of threads, concurrent events, and processes.

For running in serial, numThreads == 0, numConcEvents == 0,
numProcs == 0, useful to distinguish between running serial,
and running MT with 1 thread, or MP with 1 process.

See merge request !277
parents 34172faf 6b43b1e4
No related branches found
No related tags found
1 merge request!277added ConcurrencyFlags class
Pipeline #
......@@ -6,6 +6,7 @@
#include "GaudiKernel/IDataManagerSvc.h"
#include "GaudiKernel/SvcFactory.h"
#include "GaudiKernel/ThreadLocalContext.h"
#include "GaudiKernel/ConcurrencyFlags.h"
// Local
#include "AlgResourcePool.h"
......@@ -105,6 +106,9 @@ StatusCode ForwardSchedulerSvc::initialize()
}
}
// set global concurrency flags
Gaudi::Concurrency::ConcurrencyFlags::setNumConcEvents( numberOfWBSlots );
// Get dedicated scheduler for I/O-bound algorithms
if ( m_useIOBoundAlgScheduler ) {
m_IOBoundAlgScheduler = serviceLocator()->service( m_IOBoundAlgSchedulerSvcName );
......
#include "ThreadPoolSvc.h"
#include "GaudiKernel/SvcFactory.h"
#include "GaudiKernel/ConcurrencyFlags.h"
#include "ThreadInitTask.h"
#include "tbb/task_scheduler_init.h"
......@@ -113,8 +114,12 @@ ThreadPoolSvc::initPool(const int& poolSize) {
if (msgLevel(MSG::DEBUG)){
debug() << "creating barrier of size " << thePoolSize << endmsg;
}
Gaudi::Concurrency::ConcurrencyFlags::setNumThreads(thePoolSize);
m_barrier = std::unique_ptr<boost::barrier>( new boost::barrier(thePoolSize) );
} else {
Gaudi::Concurrency::ConcurrencyFlags::setNumThreads(1);
}
// Launch the init tool tasks
......
#ifndef GAUDIKERNEL_CONCURRENCYFLAGS_H
#define GAUDIKERNEL_CONCURRENCYFLAGS_H 1
#include <cstddef>
#include "GaudiKernel/Kernel.h"
class ThreadPoolSvc;
class ForwardSchedulerSvc;
/** @class ConcurrencyFlags ConcurrencyFlags.h GaudiKernel/ConcurrencyFlags.h
*
* Provides information about the level of concurrency of the currently
* executing job
*
* will enumerate the number of Worker Threads (for multi-threading),
* Processes (for multi-processing), and total number of concurrent events.
*
*/
namespace Gaudi {
namespace Concurrency {
class ConcurrencyFlags {
friend class ::ThreadPoolSvc;
friend class ::ForwardSchedulerSvc;
public:
/** number of Worker Threads (for MT)
*/
static GAUDI_API std::size_t numThreads() {return n_threads; }
/** number of Concurrent Events (for MT)
*/
static GAUDI_API std::size_t numConcurrentEvents() { return n_concEvts; }
/** number of forked child processes (for MP)
*/
static GAUDI_API std::size_t numProcs() { return n_procs; }
/** serial operation, or some form of concurrency
*/
static GAUDI_API bool concurrent() {
return ( n_threads || n_concEvts || n_procs );
}
private:
static GAUDI_API void setNumThreads(const std::size_t& nT) {n_threads=nT;}
static GAUDI_API void setNumConcEvents(const std::size_t& nE) {n_concEvts=nE;}
static GAUDI_API void setNumProcs(const std::size_t& nP) {n_procs=nP;}
private:
static std::size_t n_threads; // worker threads for MT
static std::size_t n_concEvts; // concurrent events for MT
static std::size_t n_procs; // child processes for MP
};
}
}
#endif
#include "GaudiKernel/ConcurrencyFlags.h"
namespace Gaudi {
namespace Concurrency {
std::size_t ConcurrencyFlags::n_threads { 0 };
std::size_t ConcurrencyFlags::n_concEvts { 0 };
std::size_t ConcurrencyFlags::n_procs { 0 };
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment