Skip to content

Commit f8e4fc5

Browse files
committed
nthread is max number of threads, and setting that on the examples to avoid using too many cores
1 parent 857b3f9 commit f8e4fc5

5 files changed

Lines changed: 10 additions & 9 deletions

File tree

examples/geant4_basic/b1/b1.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
experiment: examples
22
runno: 1
33
n: 300
4+
nthreads: 12
45

56
gparticle:
67
- name: gamma

examples/geant4_basic/b2/b2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
experiment: examples
22
runno: 1
33
n: 1
4+
nthreads: 12
45

56
gparticle:
67
- name: e-

examples/meson.build

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,6 @@ examples_map = {
1111
}
1212
}
1313

14-
15-
16-
1714
foreach branch : examples_map.keys()
1815
examples = examples_map[branch]
1916

goptions/examples/define_options.cc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ GOptions defineOptions() {
2222
goptions.defineOption(GVariable("runno", 1, "sets the run number"), help);
2323

2424
// nthreads: 8
25-
help = "If not set, use all available threads. 0: use all threads\n";
26-
help += "Example: -nthreads=12\n";
27-
goptions.defineOption(GVariable("nthreads", 0, "number of threads"), help);
25+
help = "Maximum number of threads to use.\n";
26+
help += "If the number of cores available ncores is less then nthreads, use ncores instead.\n";
27+
help += "If not set, use all available threads. 0: use all threads\n";
28+
help += "Example: -nthreads=12 : . \n";
29+
goptions.defineOption(GVariable("nthreads", 0, "maximum number of threads to use"), help);
2830

2931
vector <GVariable> gparticle = {
3032
{"name", goptions::NODFLT, "particle name"},

utilities/gemcUtilities.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ namespace gemc {
1616
int get_nthreads(const std::shared_ptr<GOptions>& gopts, const std::shared_ptr<GLogger>& log) {
1717
int useThreads = gopts->getScalarInt("nthreads");
1818

19-
int allThreads = G4Threading::G4GetNumberOfCores();
20-
if (useThreads == 0) useThreads = allThreads;
19+
int ncores = G4Threading::G4GetNumberOfCores();
20+
if (useThreads == 0 || useThreads > ncores) useThreads = ncores;
2121

22-
log->info(0, "Using ", useThreads, " threads out of ", allThreads, " available.");
22+
log->info(0, "Using ", useThreads, " threads out of ", ncores, " available cores.");
2323

2424
return useThreads;
2525
}

0 commit comments

Comments
 (0)