Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2024-04-06 12:11:55

0001 #ifndef FWCore_Concurrency_ThreadsController_h
0002 #define FWCore_Concurrency_ThreadsController_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     FWCore/Concurrency
0006 // Class  :     ThreadsController
0007 //
0008 /**\class ThreadsController ThreadsController.h "ThreadsController.h"
0009 
0010  Description: Controls how many threads and how much stack memory per thread
0011 
0012  Usage:
0013     The lifetime of the ThreadsController sets how long the options are in use.
0014 
0015 */
0016 //
0017 // Original Author:  FWCore
0018 //         Created:  Fri, 18 Nov 2016 20:30:42 GMT
0019 //
0020 
0021 // system include files
0022 #include "oneapi/tbb/global_control.h"
0023 #include "oneapi/tbb/task_arena.h"
0024 #include <memory>
0025 
0026 // user include files
0027 
0028 // forward declarations
0029 
0030 namespace edm {
0031   class ThreadsController {
0032   public:
0033     ThreadsController() = delete;
0034     explicit ThreadsController(unsigned int iNThreads)
0035         : m_nThreads{oneapi::tbb::global_control::max_allowed_parallelism, iNThreads}, m_stackSize{} {}
0036     ThreadsController(unsigned int iNThreads, size_t iStackSize)
0037         : m_nThreads{oneapi::tbb::global_control::max_allowed_parallelism, iNThreads},
0038           m_stackSize{makeStackSize(iStackSize)} {}
0039 
0040     // ---------- member functions ---------------------------
0041     void setStackSize(size_t iStackSize) { m_stackSize = makeStackSize(iStackSize); }
0042 
0043   private:
0044     static std::unique_ptr<oneapi::tbb::global_control> makeStackSize(size_t iStackSize);
0045 
0046     // ---------- member data --------------------------------
0047     oneapi::tbb::global_control m_nThreads;
0048     std::unique_ptr<oneapi::tbb::global_control> m_stackSize;
0049   };
0050 }  // namespace edm
0051 
0052 #endif