-
Notifications
You must be signed in to change notification settings - Fork 2
/
scaling_plots.py
139 lines (123 loc) · 4.15 KB
/
scaling_plots.py
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
import numpy as np
import matplotlib.pyplot as plt
import argparse
import os
import sys
def readfile(f):
data = []
with open(f, "r") as timedata:
for t in timedata:
data.append(t.split())
return np.array(data)
parser = argparse.ArgumentParser()
parser.add_argument("-t", "--tag" , nargs="+", \
help = "Tag value" , required = True)
parser.add_argument("-d", "--directory", nargs="?", type = str,\
help = "Benchmark directory", required = True)
parser.add_argument("-f", "--datafile", nargs="?", type = str, \
help = "Data file to read" , required = True)
# Parse the arguements
args = parser.parse_args()
directory = args.directory
tags = args.tag
datafile = args.datafile
# Decide x and y axis:
# machine name, case name and ppn never go on x axis or y axis
# Candidates for y-axis: time (in a scaling study)
machine_name_in_title=False
lelt_in_title=False
lx_in_title=False
case_name_in_title=False
np_in_title=False
ppn_in_title=False
# Read data + Metadata
data = readfile(os.path.join(directory, tags[0], datafile))
for t in tags[1:]:
time_data = readfile(os.path.join(directory, t, datafile))
data = np.concatenate((data, time_data), axis=0)
# Read other Metadata
machines = np.unique(data[:, 1])
lelts = np.unique(data[:, 2])
lxs = np.unique(data[:, 3])
cases = np.unique(data[:, 4])
nps = np.unique(data[:, 5])
ppns = np.unique(data[:, 6])
title = "Scaling study"
ylabel = "Time (s)"
xlabel = ""
pdfname =""
xvar=""
if machines.size == 1:
machine_name_in_title = True
title = title + ", machine=" + str(machines[0])
pdfname = pdfname + "_machine_" + str(machines[0])
if lelts.size == 1:
lelt_in_title = True
title = title + ", lelt=" + str(lelts[0])
pdfname = pdfname + "_lelt_" + str(lelts[0])
if lxs.size == 1:
lx_in_title = True
title = title + ", lx=" + str(lxs[0])
pdfname = pdfname + "_lx_" + str(lxs[0])
if cases.size == 1:
case_name_in_title = True
title = title + ", case=" + str(cases[0])
pdfname = pdfname + "_case_" + str(cases[0])
if nps.size == 1:
np_in_title = True
title = title + ", np=" + str(nps[0])
pdfname = pdfname + "_np_" + str(nps[0])
if ppns.size == 1:
ppn_in_title = True
title = title + ", ppn=" + str(ppns[0])
pdfname = pdfname + "_ppn_" + str(ppns[0])
# Candidates for x-axis: np, lx, lelt
# if len(lelts) = len(lxs) = 1 ==> scaling study
# if len(lelts) = len(nps) = 1 ==> lx variation study
# if len(lxs) = len(nps) = 1 ==> lelt variation study ?
if lelt_in_title and lx_in_title:
xvar = "np"
xlabel = "Number of MPI ranks"
pdfname = "time_vs_np" + pdfname
elif lelt_in_title and np_in_title:
xvar = "lx"
xlabel = "Degrees of freedom (lx1)"
pdfname = "time_vs_dof" + pdfname
elif lx_in_title and np_in_title:
xvar = "lelt"
xlabel = "Maximum element per rank (lelt)"
pdfname = "time_vs_lelt" + pdfname
else:
print("Too many variants !, Exitting ...")
sys.exit()
## Anatomy of a figure: https://matplotlib.org/faq/usage_faq.html
fig = plt.figure()
fig, ax_list = plt.subplots(1, 1)
ax_list = [ax_list]
ax_list[0].set_xlabel(xlabel)
ax_list[0].set_ylabel(ylabel)
fig.suptitle(title)
for m in machines:
m_data = data[data[:, 1] == m]
for c in cases:
c_data = m_data[m_data[:, 4] == c]
for p in ppns:
p_data = c_data[c_data[:, 6] == p]
label = ""
if not machine_name_in_title:
label = label + str(m) + " "
if not case_name_in_title:
label = label + str(c) + " "
if not ppn_in_title:
label = label + "ppn=" + str(p) + " "
if xvar == "np":
ax_list[0].loglog(p_data[:, 5], p_data[:, 7], 'o-', label = label)
elif xvar == "lx":
ax_list[0].loglog(p_data[:, 3], p_data[:, 7], 'o-', label = label)
else:
ax_list[0].loglog(p_data[:, 2], p_data[:, 7], 'o-', label = label)
if label is not "":
ax_list[0].legend()
pdfname = pdfname + ".pdf"
fig.savefig(pdfname)
print("Scaling figure saved in: " + pdfname)