File indexing completed on 2024-04-06 12:12:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <memory>
0021 #include <atomic>
0022 #include <unistd.h>
0023 #include "oneapi/tbb/task_arena.h"
0024
0025
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
0035
0036
0037 class TestNThreadsChecker {
0038 public:
0039 explicit TestNThreadsChecker(const edm::ParameterSet&, edm::ActivityRegistry&);
0040
0041 private:
0042
0043 unsigned int m_nExpectedThreads;
0044 };
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
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
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
0074 DEFINE_FWK_SERVICE(TestNThreadsChecker);