-
Notifications
You must be signed in to change notification settings - Fork 4.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #30908 from Dr15Jones/fixCmsRunThreads
Properly set number of threads in CmsRun python module
- Loading branch information
Showing
9 changed files
with
146 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#ifndef FWCore_Concurrency_setNThreads_h | ||
#define FWCore_Concurrency_setNThreads_h | ||
// | ||
// setNThreads.h | ||
// CMSSW | ||
// | ||
// Created by Chris Jones on 7/24/20. | ||
// | ||
#include <memory> | ||
#include "tbb/task_scheduler_init.h" | ||
|
||
namespace edm { | ||
unsigned int setNThreads(unsigned int iNThreads, | ||
unsigned int iStackSize, | ||
std::unique_ptr<tbb::task_scheduler_init>& oPtr); | ||
} | ||
#endif /* FWCore_Concurrency_setNThreads_h */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// | ||
// setNThreads.cc | ||
// CMSSW | ||
// | ||
// Created by Chris Jones on 7/24/20. | ||
// | ||
|
||
#include "FWCore/Concurrency/interface/setNThreads.h" | ||
|
||
namespace edm { | ||
unsigned int setNThreads(unsigned int iNThreads, | ||
unsigned int iStackSize, | ||
std::unique_ptr<tbb::task_scheduler_init>& oPtr) { | ||
//The TBB documentation doesn't explicitly say this, but when the task_scheduler_init's | ||
// destructor is run it does a 'wait all' for all tasks to finish and then shuts down all the threads. | ||
// This provides a clean synchronization point. | ||
//We have to destroy the old scheduler before starting a new one in order to | ||
// get tbb to actually switch the number of threads. If we do not, tbb stays at 1 threads | ||
|
||
//stack size is given in KB but passed in as bytes | ||
iStackSize *= 1024; | ||
|
||
oPtr.reset(); | ||
if (0 == iNThreads) { | ||
//Allow TBB to decide how many threads. This is normally the number of CPUs in the machine. | ||
iNThreads = tbb::task_scheduler_init::default_num_threads(); | ||
} | ||
oPtr = std::make_unique<tbb::task_scheduler_init>(static_cast<int>(iNThreads), iStackSize); | ||
|
||
return iNThreads; | ||
} | ||
} // namespace edm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef FWCore_ParameterSet_ThreadsInfo_h | ||
#define FWCore_ParameterSet_ThreadsInfo_h | ||
|
||
namespace edm { | ||
|
||
class ParameterSet; | ||
class ParameterSetDescription; | ||
|
||
constexpr unsigned int s_defaultNumberOfThreads = 1; | ||
constexpr unsigned int s_defaultSizeOfStackForThreadsInKB = 10 * 1024; //10MB | ||
|
||
struct ThreadsInfo { | ||
unsigned int nThreads_ = s_defaultNumberOfThreads; | ||
unsigned int stackSize_ = s_defaultSizeOfStackForThreadsInKB; | ||
}; | ||
|
||
ThreadsInfo threadOptions(edm::ParameterSet const& pset); | ||
void setThreadOptions(ThreadsInfo const& threadsInfo, edm::ParameterSet& pset); | ||
|
||
} // namespace edm | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// | ||
// ThreadsInfo.cc | ||
// CMSSW | ||
// | ||
// Created by Chris Jones on 7/24/20. | ||
// | ||
#include "FWCore/ParameterSet/interface/ThreadsInfo.h" | ||
#include "FWCore/ParameterSet/interface/ParameterSet.h" | ||
|
||
namespace edm { | ||
ThreadsInfo threadOptions(edm::ParameterSet const& pset) { | ||
// default values | ||
ThreadsInfo threadsInfo; | ||
|
||
if (pset.existsAs<edm::ParameterSet>("options", false)) { | ||
auto const& ops = pset.getUntrackedParameterSet("options"); | ||
if (ops.existsAs<unsigned int>("numberOfThreads", false)) { | ||
threadsInfo.nThreads_ = ops.getUntrackedParameter<unsigned int>("numberOfThreads"); | ||
} | ||
if (ops.existsAs<unsigned int>("sizeOfStackForThreadsInKB", false)) { | ||
threadsInfo.stackSize_ = ops.getUntrackedParameter<unsigned int>("sizeOfStackForThreadsInKB"); | ||
} | ||
} | ||
return threadsInfo; | ||
} | ||
|
||
void setThreadOptions(ThreadsInfo const& threadsInfo, edm::ParameterSet& pset) { | ||
edm::ParameterSet newOp; | ||
if (pset.existsAs<edm::ParameterSet>("options", false)) { | ||
newOp = pset.getUntrackedParameterSet("options"); | ||
} | ||
newOp.addUntrackedParameter<unsigned int>("numberOfThreads", threadsInfo.nThreads_); | ||
newOp.addUntrackedParameter<unsigned int>("sizeOfStackForThreadsInKB", threadsInfo.stackSize_); | ||
pset.insertParameterSet(true, "options", edm::ParameterSetEntry(newOp, false)); | ||
} | ||
} // namespace edm |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.