Skip to content

Commit

Permalink
Support benchmarking and plotting on Mac OSX, where taskset and lscpu…
Browse files Browse the repository at this point in the history
… are not available
  • Loading branch information
neboat committed Jul 7, 2020
1 parent ecef213 commit 6e6a2af
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Cilkscale_vis/cilkscale.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
12 changes: 9 additions & 3 deletions Cilkscale_vis/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down

0 comments on commit 6e6a2af

Please sign in to comment.