From 6e6a2aff34c77964a98e8f2e9f1c606513609f7c Mon Sep 17 00:00:00 2001 From: TB Schardl Date: Fri, 3 Jul 2020 14:33:05 -0400 Subject: [PATCH] Support benchmarking and plotting on Mac OSX, where taskset and lscpu are not available --- Cilkscale_vis/cilkscale.py | 5 +++-- Cilkscale_vis/runner.py | 12 +++++++++--- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/Cilkscale_vis/cilkscale.py b/Cilkscale_vis/cilkscale.py index 6ad859a..aa7295e 100644 --- a/Cilkscale_vis/cilkscale.py +++ b/Cilkscale_vis/cilkscale.py @@ -35,12 +35,13 @@ def main(): # generate data and save to out_csv (defaults to out.csv) run(bin_instrument, bin_bench, bin_args, out_csv, cpu_counts) - if can_plot: + cpus = get_cpu_ordering() + if can_plot and cpus: # generate plot # (out_plot defaults to plot.pdf) # (rows defaults to just the last row in the csv) rows_to_plot = list(map(int, args.rows_to_plot.split(","))) - plot(out_csv, out_plot, rows_to_plot, get_cpu_ordering()) + plot(out_csv, out_plot, rows_to_plot, cpus) if __name__ == '__main__': main() diff --git a/Cilkscale_vis/runner.py b/Cilkscale_vis/runner.py index 2b588a2..a65aeeb 100644 --- a/Cilkscale_vis/runner.py +++ b/Cilkscale_vis/runner.py @@ -31,15 +31,21 @@ def run_on_p_workers(P, rcommand): cpu_online = cpu_ordering[:P] time.sleep(0.1) - rcommand = "taskset -c " + ",".join([str(p) for (p,m) in cpu_online]) + " " + rcommand - logger.info(rcommand) + if sys.platform != "darwin": + rcommand = "taskset -c " + ",".join([str(p) for (p,m) in cpu_online]) + " " + rcommand + logger.info('CILK_NWORKERS=' + str(P) + ' ' + rcommand) bench_out_csv = benchmark_tmp_output(P) proc = subprocess.Popen(['CILK_NWORKERS=' + str(P) + ' ' + "CILKSCALE_OUT=" + bench_out_csv + " " + rcommand], shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out,err=proc.communicate() err = str(err, "utf-8") def get_cpu_ordering(): - out,err = run_command("lscpu --parse") + if sys.platform == "darwin": + # TODO: Replace with something that analyzes CPU configuration on Darwin + out,err = run_command("sysctl -n hw.physicalcpu_max") + return [(0, p) for p in range(0,int(str(out, 'utf-8')))] + else: + out,err = run_command("lscpu --parse") out = str(out, 'utf-8')