about summary refs log tree commit diff stats
path: root/archive/2024/winter/bsc_dichler/scripts/plot/parallel_non_contiguous.py
blob: f766fcedc742abd9dd5e8bead32d5f97bb62dd47 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt


def run(csv_files: list[Path], output: Path, format):
    _, ax1 = plt.subplots(figsize=(10, 6))
    labels = ["MTE disabled", "MTE enabled"]

    data = []
    unique_threads = set()
    tick_positions = None
    for file in csv_files:
        df = pd.read_csv(file, sep=";")
        df["duration"] = df["duration"] // 1_000
        g = (
            df.groupby(["len", "threads"])["duration"]
            .agg(["mean", "std"])
            .reset_index()
        )
        g["kb"] = (g["len"] * 16) / 1024
        data.append(g)
        unique_threads.update(g["threads"].unique())
        tick_positions = g["kb"].unique()

    unique_threads = sorted(unique_threads)

    thread_colors = {1: "tomato", 2: "#56B4E9", 3: "#009E73", 4: "#E69F00"}

    line_styles = ["-", "--"]

    handles = []
    labels_legend = []

    for thread in unique_threads:
        for idx, g in enumerate(data):
            subset = g[g["threads"] == thread]
            if subset.empty:
                continue

            line = ax1.errorbar(
                subset["kb"],
                subset["mean"],
                yerr=subset["std"],
                fmt="o",
                linestyle=line_styles[idx],
                capsize=5,
                color=thread_colors.get(thread, "black"),
            )

            label = (
                f"1 Thread - {labels[idx]}"
                if thread == 1
                else f"{thread} Threads - {labels[idx]}"
            )
            handles.append(line[0])
            labels_legend.append(label)

    ax1.legend(
        handles=handles,
        labels=labels_legend,
        ncol=2,
        loc="upper left",
        fancybox=True,
        shadow=False,
    )

    ax1.set_xscale("log", base=2)
    ax1.set_yscale("log", base=2)

    ax1.grid(True, which="both", linestyle="--", linewidth=0.5)
    tick_labels = []
    xticks_filtered = [x for i, x in enumerate(tick_positions) if i % 2 == 0]
    for idx, v in enumerate(xticks_filtered):
        l = ""
        if v < 1024:
            if v < 1:
                l = "1 KiB"
            else:
                l = f"{v} KiB"
        else:
            l = f"{v // 1024} MiB"

        tick_labels.append(l)

    ax1.set_xticks(xticks_filtered)
    ax1.set_xticklabels(tick_labels, rotation=45, ha="right")
    ax1.set_ylabel("Time (ns - logarithmic scale)")
    ax1.set_xlabel("Memory size (logarithmic scale)")

    ax1.spines["top"].set_visible(False)
    ax1.spines["right"].set_visible(False)

    plt.title("Lower is better ↓", color="navy")
    plt.tight_layout()
    plt.savefig(output, format=format)


def plot(output_root: Path, format):
    output_root = output_root / Path("parallel_non_contiguous")

    run(
        [
            output_root / Path("write.csv"),
            output_root / Path("write_mte.csv"),
        ],
        output_root / Path(f"result-write.{format}"),
        format,
    )
    run(
        [
            output_root / Path("load.csv"),
            output_root / Path("load_mte.csv"),
        ],
        output_root / Path(f"result-read.{format}"),
        format,
    )