Skip to content
Snippets Groups Projects
plot_result.py 3.43 KiB
Newer Older
baptiste.coudray's avatar
baptiste.coudray committed
#!/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"


baptiste.coudray's avatar
baptiste.coudray committed
def plot(title1, xs1, ys1, title2, xs2, ys2):
baptiste.coudray's avatar
baptiste.coudray committed
    fig, ax = plt.subplots()
baptiste.coudray's avatar
baptiste.coudray committed
    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")
baptiste.coudray's avatar
baptiste.coudray committed
    ax.grid()
    plt.tight_layout()
    plt.legend()
    fig.savefig(RESULT_FILENAME)
    plt.show()


baptiste.coudray's avatar
baptiste.coudray committed
def plot_speedup(title1, xs1, ys1, title2, xs2, ys2):
baptiste.coudray's avatar
baptiste.coudray committed
    fig, ax = plt.subplots()
baptiste.coudray's avatar
baptiste.coudray committed
    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")
baptiste.coudray's avatar
baptiste.coudray committed
    ax.grid()
    plt.tight_layout()
    plt.legend()
    fig.savefig(RESULT_SPEEDUP_FILENAME)
    plt.show()


baptiste.coudray's avatar
baptiste.coudray committed
def get_data(filename):
    results = np.genfromtxt(filename, delimiter=';')
baptiste.coudray's avatar
baptiste.coudray committed
    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])
baptiste.coudray's avatar
baptiste.coudray committed
    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")


baptiste.coudray's avatar
baptiste.coudray committed
def main():
    xs1, ys1, stds1, speedups1 = get_data("elementary/benchmark/results/elementary-seq-2021-07-02.csv")
    xs2, ys2, stds2, speedups2 = get_data("elementary/benchmark/results/elementary-mc-2021-06-29.csv")
    # plot("Sequential", xs1, ys1, "Multicore", xs2, ys2)
    # plot_speedup("OpenCL Speedup", xs1[:4], speedups1[:4], "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)
baptiste.coudray's avatar
baptiste.coudray committed
    # 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)
baptiste.coudray's avatar
baptiste.coudray committed


if __name__ == '__main__':
    main()