1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
// -*- C++ -*-
//
// Package: Framework
// Class: TestNThreadsChecker
//
/**\class TestNThreadsChecker TestNThreadsChecker.cc FWCore/Framework/test/stubs/TestNThreadsChecker.cc
Description: <one line class summary>
Implementation:
<Notes on implementation>
*/
//
// Original Author: Chris Jones
// Created: Thu Jan 03 11:02:00 EST 2013
//
//
// system include files
#include <memory>
#include <atomic>
#include <unistd.h>
#include "oneapi/tbb/task_arena.h"
// user include files
#include "FWCore/ParameterSet/interface/ParameterSet.h"
#include "FWCore/ServiceRegistry/interface/ActivityRegistry.h"
#include "FWCore/ServiceRegistry/interface/ServiceMaker.h"
#include "FWCore/ServiceRegistry/interface/SystemBounds.h"
#include "FWCore/Utilities/interface/Exception.h"
//
// class decleration
//
class TestNThreadsChecker {
public:
explicit TestNThreadsChecker(const edm::ParameterSet&, edm::ActivityRegistry&);
private:
// ----------member data ---------------------------
unsigned int m_nExpectedThreads;
};
//
// constants, enums and typedefs
//
//
// static data member definitions
//
//
// constructors and destructor
//
TestNThreadsChecker::TestNThreadsChecker(const edm::ParameterSet& iConfig, edm::ActivityRegistry& iReg)
: m_nExpectedThreads(iConfig.getUntrackedParameter<unsigned int>("nExpectedThreads")) {
unsigned int expectedThreads = m_nExpectedThreads;
if (expectedThreads == 0) {
expectedThreads = oneapi::tbb::this_task_arena::max_concurrency();
}
//now do what ever initialization is needed
iReg.watchPreallocate([expectedThreads](edm::service::SystemBounds const& iBounds) {
if (expectedThreads != iBounds.maxNumberOfThreads()) {
throw cms::Exception("UnexpectedNumberOfThreads")
<< "Expected " << expectedThreads << " threads but actual value is " << iBounds.maxNumberOfThreads();
}
});
}
//define this as a plug-in
DEFINE_FWK_SERVICE(TestNThreadsChecker);
|