diff --git a/GaudiHive/src/ForwardSchedulerSvc.cpp b/GaudiHive/src/ForwardSchedulerSvc.cpp index 4538341d6be656a0f2a1be7f4f81c2a61310369c..a4aad12e92c3d1a4ca9095e13cac2adcdabe861b 100644 --- a/GaudiHive/src/ForwardSchedulerSvc.cpp +++ b/GaudiHive/src/ForwardSchedulerSvc.cpp @@ -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 ); diff --git a/GaudiHive/src/ThreadPoolSvc.cpp b/GaudiHive/src/ThreadPoolSvc.cpp index 3adc0c6c627558e03b21a733e5f6317c83528e8a..f98765d14924aa7a7838f0a4788e662c718a98da 100644 --- a/GaudiHive/src/ThreadPoolSvc.cpp +++ b/GaudiHive/src/ThreadPoolSvc.cpp @@ -1,6 +1,7 @@ #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 diff --git a/GaudiKernel/GaudiKernel/ConcurrencyFlags.h b/GaudiKernel/GaudiKernel/ConcurrencyFlags.h new file mode 100644 index 0000000000000000000000000000000000000000..c556c3845ff17391ed9ffa45b32046a397620f64 --- /dev/null +++ b/GaudiKernel/GaudiKernel/ConcurrencyFlags.h @@ -0,0 +1,65 @@ +#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 diff --git a/GaudiKernel/src/Lib/ConcurrencyFlags.cpp b/GaudiKernel/src/Lib/ConcurrencyFlags.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ec433afd890e7b70613520d08175cb09b6e52a1d --- /dev/null +++ b/GaudiKernel/src/Lib/ConcurrencyFlags.cpp @@ -0,0 +1,11 @@ +#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 }; + + } +}