#!/usr/bin/env python3 import matplotlib.pyplot as plt import numpy as np import subprocess import os RESULT_FILENAME = "result.png" RESULT_SPEEDUP_FILENAME = "result_speedup.png" RESULT_APPEND_FILENAME = "result_and_speedup.png" def plot(title1, xs1, ys1, title2, xs2, ys2): fig, ax = plt.subplots() ax.plot(xs1, ys1, label=title1) ax.plot(xs2, ys2, label=title2) ax.set(xlabel="Number of tasks", ylabel='Time (in seconds)', title=f"Simple Cellular Automaton\nCompute 100 generations with 300'000'000 cells") ax.grid() plt.tight_layout() plt.legend() fig.savefig(RESULT_FILENAME) plt.show() def plot_speedup(title1, xs1, ys1, title2, xs2, ys2): fig, ax = plt.subplots() ax.plot(xs1, ys1, label=title1) ax.plot(xs2, ys2, label=title2) ax.plot(xs1, xs1, label="Ideal Speedup") ax.set(xlabel="Number of tasks", ylabel='Speedup', title=f"Simple Cellular Automaton\nSpeedup of computing 100 generations\n with 300'000'000 cells") ax.grid() plt.tight_layout() plt.legend() fig.savefig(RESULT_SPEEDUP_FILENAME) plt.show() def get_data(filename): results = np.genfromtxt(filename, delimiter=';') results_ordered = {} for result in results: key = int(result[0]) if key in results_ordered: results_ordered[key].append(result[-1]) else: results_ordered[int(result[0])] = [result[-1]] xs = [] ys = [] stds = [] speedups = [] for key in results_ordered.keys(): xs.append(key) ys.append(sum(results_ordered[key]) / len(results_ordered[key])) stds.append(np.std(results_ordered[key])) speedups.append(ys[0] / ys[-1]) return xs, ys, stds, speedups def to_md_array(filename, xs, ys, stds, speedups, gpu): with open(filename, "w") as fh: if gpu: fh.write( "| Number of tasks | Number of GPUs | Average [s] | Standard Derivation [s] | Speedup | Number of measures |\n") fh.write("|:---:|:---:|:---:|:---:|:---:|:---:|\n") else: fh.write("| Number of tasks | Average [s] | Standard Derivation [s] | Speedup | Number of measures |\n") fh.write("|:---:|:---:|:---:|:---:|:---:|\n") for i in range(len(xs)): if gpu: fh.write( f"| {xs[i]} | {min(xs[i], 8)} | {round(ys[i], 3)} [s] | ± {round(stds[i], 3)} [s] | x{round(speedups[i], 1)} | 15 |\n") else: fh.write( f"| {xs[i]} | {round(ys[i], 3)} [s] | ± {round(stds[i], 3)} [s] | x{round(speedups[i], 1)} | 15 |\n") def main(): xs1, ys1, stds1, speedups1 = get_data("game_of_life/benchmark/results/gol-seq-2021-07-14.csv") xs2, ys2, stds2, speedups2 = get_data("game_of_life/benchmark/results/gol-mc-2021-07-14.csv") plot("Sequential", xs1, ys1, "Multicore", xs2, ys2) plot_speedup("Sequential Speedup", xs1, speedups1, "Multicore Speedup", xs2, speedups2) # to_md_array("results_seq.md", xs1, ys1, stds1, speedups1, gpu=False) # to_md_array("results_mc.md", xs2, ys2, stds2, speedups2, gpu=False) # Need ImageMagick subprocess.run(["docker", "run", "-v", f"{os.getcwd()}:/imgs", "dpokidov/imagemagick", "+append", f"/imgs/{RESULT_FILENAME}", f"/imgs/{RESULT_SPEEDUP_FILENAME}", f"/imgs/{RESULT_APPEND_FILENAME}"], capture_output=False) if __name__ == '__main__': main()