Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-24 02:18:45

0001 // -*- C++ -*-
0002 //
0003 // Package:    Framework
0004 // Class:      TestNThreadsChecker
0005 //
0006 /**\class TestNThreadsChecker TestNThreadsChecker.cc FWCore/Framework/test/stubs/TestNThreadsChecker.cc
0007 
0008  Description: <one line class summary>
0009 
0010  Implementation:
0011      <Notes on implementation>
0012 */
0013 //
0014 // Original Author:  Chris Jones
0015 //         Created:  Thu Jan 03 11:02:00 EST 2013
0016 //
0017 //
0018 
0019 // system include files
0020 #include <memory>
0021 #include <atomic>
0022 #include <unistd.h>
0023 #include "oneapi/tbb/task_arena.h"
0024 
0025 // user include files
0026 #include "FWCore/ParameterSet/interface/ParameterSet.h"
0027 #include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
0028 #include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
0029 #include "FWCore/ServiceRegistry/interface/SystemBounds.h"
0030 
0031 #include "FWCore/Utilities/interface/Exception.h"
0032 
0033 //
0034 // class decleration
0035 //
0036 
0037 class TestNThreadsChecker {
0038 public:
0039   explicit TestNThreadsChecker(const edm::ParameterSet&, edm::ActivityRegistry&);
0040 
0041 private:
0042   // ----------member data ---------------------------
0043   unsigned int m_nExpectedThreads;
0044 };
0045 
0046 //
0047 // constants, enums and typedefs
0048 //
0049 
0050 //
0051 // static data member definitions
0052 //
0053 
0054 //
0055 // constructors and destructor
0056 //
0057 TestNThreadsChecker::TestNThreadsChecker(const edm::ParameterSet& iConfig, edm::ActivityRegistry& iReg)
0058     : m_nExpectedThreads(iConfig.getUntrackedParameter<unsigned int>("nExpectedThreads")) {
0059   unsigned int expectedThreads = m_nExpectedThreads;
0060   if (expectedThreads == 0) {
0061     expectedThreads = oneapi::tbb::this_task_arena::max_concurrency();
0062   }
0063 
0064   //now do what ever initialization is needed
0065   iReg.watchPreallocate([expectedThreads](edm::service::SystemBounds const& iBounds) {
0066     if (expectedThreads != iBounds.maxNumberOfThreads()) {
0067       throw cms::Exception("UnexpectedNumberOfThreads")
0068           << "Expected " << expectedThreads << " threads but actual value is " << iBounds.maxNumberOfThreads();
0069     }
0070   });
0071 }
0072 
0073 //define this as a plug-in
0074 DEFINE_FWK_SERVICE(TestNThreadsChecker);