aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFlorian Fischer <florian.fl.fischer@fau.de>2019-10-21 19:11:50 +0200
committerFlorian Fischer <florian.fl.fischer@fau.de>2019-10-21 19:11:50 +0200
commit7a520f09cd6709840ef8f13d17503e8e1102a62d (patch)
tree71091ac54ae695b0d34de30a79d3db307e5fb8b2
parent2aad3bdf4beceb6388e21bf73c015d1393846dba (diff)
downloadallocbench-7a520f09cd6709840ef8f13d17503e8e1102a62d.tar.gz
allocbench-7a520f09cd6709840ef8f13d17503e8e1102a62d.zip
improve scale_thread_for_cpus
Thread numbers are now a factor of two. Allow creation of Benchmark objects when src.globalvars.result_dir is not set.
-rw-r--r--TODO4
-rw-r--r--src/benchmark.py42
2 files changed, 21 insertions, 25 deletions
diff --git a/TODO b/TODO
index 0c5bf01..ea5a2c1 100644
--- a/TODO
+++ b/TODO
@@ -3,10 +3,6 @@
- rethink colors
-- rethink scale_thread_for_cpus
- - hit interesting thread_counts: numa domains
- - scale equaly
-
- check dependencies
- log facilities
diff --git a/src/benchmark.py b/src/benchmark.py
index 69a8d37..fd99fc4 100644
--- a/src/benchmark.py
+++ b/src/benchmark.py
@@ -55,26 +55,26 @@ class Benchmark:
print_debug("Server Err:", errs)
@staticmethod
- def scale_threads_for_cpus(factor, steps=None):
- """Simple helper to scale thread count to execution units"""
- cpus = multiprocessing.cpu_count()
- max_threads = cpus * factor
- if not steps:
- steps = 1
- if max_threads >= 20 and max_threads < 50:
- steps = 2
- if max_threads >= 50 and max_threads < 100:
- steps = 5
- if max_threads >= 100:
- steps = 10
-
- # Special thread counts
- nthreads = set([1, int(cpus/2), cpus, cpus*factor])
- nthreads.update(range(steps, cpus * factor + 1, steps))
- nthreads = list(nthreads)
- nthreads.sort()
-
- return nthreads
+ def scale_threads_for_cpus(factor=1, min_threads=1, steps=10):
+ """Helper to scale thread count to execution units
+
+ Return a list of numbers between start and multiprocessing.cpu_count() * factor
+ with len <= steps."""
+ max_threads = multiprocessing.cpu_count() * factor
+
+ if steps > max_threads - min_threads + 1:
+ return list(range(min_threads, max_threads + 1))
+
+ nthreads = []
+ divider = 2
+ while True:
+ factor = max_threads // divider
+ entries = max_threads // factor
+ if entries > steps - 1:
+ return sorted(list(set([min_threads] + nthreads + [max_threads])))
+
+ nthreads = [(i + 1) * factor for i in range(entries)]
+ divider *= 2
def __str__(self):
return self.name
@@ -90,7 +90,7 @@ class Benchmark:
# Set result_dir
if not hasattr(self, "result_dir"):
- self.result_dir = os.path.abspath(os.path.join(src.globalvars.resdir,
+ self.result_dir = os.path.abspath(os.path.join(src.globalvars.resdir or "",
self.name))
# Set build_dir
if not hasattr(self, "build_dir"):