pfor/rtbenchmarks/plot_imgpro
2021-05-10 18:11:23 +02:00

148 lines
3.1 KiB
Python
Executable File

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os, sys
sys.path.append(os.path.abspath(os.path.dirname(os.path.abspath(__file__))+"/../scripts"))
import fileinput
import numpy as np
import matplotlib as mpl
show = len(sys.argv) > 1 and sys.argv[1] == 'show'
if not show:
mpl.use('pgf')
import matplotlib.pyplot as plt
import matplotlib.lines as lines
from common import set_size, config_plt, get_colors
config_plt()
def loadData(fn):
content = []
with open(fn) as f:
content = f.readlines()
values = {}
for line in content:
method, ncores, strtime = [x for x in line.split(':')]
time = float(strtime)
if method != "seq":
time = time/float(ncores)
if not ncores in values:
values[ncores] = []
values[ncores].append(time);
return values
def figCores(title, xlabel, xticks, output, datasrcs, error=False):
fig = plt.figure()
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(u"temps (s)")
plt.xticks(xticks)
nd = len(datasrcs)
width = .4
pos = .5-.5*nd
for f, label in datasrcs:
values = loadData(f)
barcolor, errcolor = get_colors(['seq', 'omp', 'gen_omp', 'gen_thread'], label)
if "1" in values:
values.pop("1")
for k, a in values.items():
x = int(k)
m = np.mean(a)
s = 2.5758 * np.std(a) / np.sqrt(len(a)) # confiance 99 %
x = x + pos*width
plt.bar(x, m, width=width, color=barcolor, label=label)
if error:
plt.errorbar(x, m, s, elinewidth=.8, capsize=1, ecolor=errcolor)
label=''
pos = pos + 1
plt.legend(bbox_to_anchor=(1, 1))
fig.set_size_inches(set_size(455.24408, .8))
if not show:
plt.savefig(output, format='pdf', bbox_inches='tight')
return plt
def figSpeedUp(title, xlabel, xticks, output, basetime, datasrcs):
fig = plt.figure()
plt.title(title)
plt.xlabel(xlabel)
plt.ylabel(u"accélération")
plt.xticks(xticks)
nd = len(datasrcs)
width = .4
pos = .5-.5*nd
for f, label in datasrcs:
values = loadData(f)
barcolor, errcolor = get_colors(['seq', 'omp', 'gen_omp', 'gen_thread'], label)
if "1" in values:
values.pop("1")
for k, a in values.items():
x = int(k)
m = basetime/np.mean(a)
x = x + pos*width
plt.bar(x, m, width=width, color=barcolor, label=label)
label=''
pos = pos + 1
plt.legend(bbox_to_anchor=(0.38, 1))
fig.set_size_inches(set_size(455.24408, .8))
if not show:
plt.savefig(output, format='pdf', bbox_inches='tight')
return plt
# script
values = loadData('data_imgpro/rt_cores_seq')
basetime = np.mean(values["1"])
plts = []
plt = figCores(u"", u"nombre de cœurs", [2, 4, 6, 8, 10, 12, 14, 16, 18],
"plots/rt_cores.pdf", [
# ['data_imgpro/rt_cores_seq', 'seq'],
['data_imgpro/rt_cores_gen_omp', 'omp'],
['data_imgpro/rt_cores_gen_omp', 'gen_omp'],
['data_imgpro/rt_cores_gen_thread', 'gen_thread'],
],
error=False
)
plts.append(plt)
plt = figSpeedUp(u"", u"nombre de cœurs", [2, 4, 6, 8, 10, 12, 14, 16, 18],
"plots/rt_speedup.pdf", basetime, [
['data_imgpro/rt_cores_gen_omp', 'omp'],
['data_imgpro/rt_cores_gen_omp', 'gen_omp'],
['data_imgpro/rt_cores_gen_thread', 'gen_thread'],
]
)
plts.append(plt)
if show:
for plt in plts:
plt.show()