Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83456025
plot_scalability.py
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Sep 17, 05:55
Size
9 KB
Mime Type
text/x-python
Expires
Thu, Sep 19, 05:55 (1 d, 23 h)
Engine
blob
Format
Raw Data
Handle
20841144
Attached To
R12526 perf-test-akantu
plot_scalability.py
View Options
#!/usr/bin/env python
# -*- py-which-shell: "python"; -*-
# -*- coding: utf-8 -*-
import
BlackDynamite
as
BD
import
os
import
re
import
math
import
numpy
as
np
import
matplotlib
as
mpl
import
matplotlib.pyplot
as
plt
import
matplotlib.patches
as
patches
from
scipy.optimize
import
curve_fit
## -- Setup --------------------------------------------------------------------
mpl
.
rc
(
'font'
,
family
=
'serif'
,
size
=
8
,
serif
=
'Computer Modern'
)
#'Times')
mpl
.
rc
(
'text'
,
usetex
=
True
)
mpl
.
rc
(
'text.latex'
,
unicode
=
True
)
#mpl.rc('legend', markerscale = .6)
#mpl.rc('legend', handlelength = 3)
mpl
.
rcParams
[
'text.latex.preamble'
]
=
[
r'\usepackage{amsmath}'
,
r'\usepackage{SIunits}'
,
r'\usepackage{xcolor}'
]
fig
,
(
axe0
)
=
plt
.
subplots
(
nrows
=
1
)
fig
.
set_size_inches
(
3.7
,
2.5
)
leg_fontsize
=
9
first_nproc
=
8
max_proc_to_consider
=
21
*
16
## -- BD stuff -----------------------------------------------------------------
parser
=
BD
.
BDParser
()
params
=
parser
.
parseBDParameters
()
if
(
"job_constraints"
not
in
params
):
params
[
"job_constraints"
]
=
[]
if
(
"run_constraints"
not
in
params
):
params
[
"run_constraints"
]
=
[]
mybase
=
BD
.
Base
(
**
params
)
myjobselector
=
BD
.
JobSelector
(
mybase
)
job_list
=
myjobselector
.
selectJobs
(
params
[
"job_constraints"
],
"jobs.nb_proc"
)
stats
=
BD
.
BDStat
(
mybase
)
myrunselector
=
BD
.
RunSelector
(
mybase
)
## -- Data treatment functions -------------------------------------------------
def
getRunInfos
(
run_list
,
first_proc
):
average
=
stats
.
average
(
"time"
,
run_list
,
[])
nproc
=
[]
times
=
[]
times_err
=
[]
nprocbis
=
[]
timesbis
=
[]
rt0
=
0.
t0
=
0.
t0_err
=
0.
max_proc
=
0
for
key
,
results
in
average
.
iteritems
():
t
=
results
[
"data"
]
n
=
key
[
0
]
if
n
>
max_proc_to_consider
:
continue
nproc
.
append
(
n
)
times
.
append
(
t
[
0
,
1
])
times_err
.
append
(
t
[
0
,
2
])
max_proc
=
max
(
max_proc
,
n
)
if
n
<
first_proc
:
continue
if
n
==
first_proc
:
t0
=
t
[
0
,
1
]
t0_err
=
t
[
0
,
2
]
nprocbis
.
append
(
n
)
timesbis
.
append
(
t
[
0
,
1
])
r
=
{
"rt0"
:
rt0
,
"t0"
:
t0
,
"t0_err"
:
t0_err
,
"max_proc"
:
max_proc
,
"nproc"
:
np
.
array
(
nproc
),
"times"
:
np
.
array
(
times
),
"times_err"
:
np
.
array
(
times_err
),
"nprocbis"
:
np
.
array
(
nprocbis
)
,
"timesbis"
:
np
.
array
(
timesbis
),
"marker"
:
"o"
,
"fitmarker"
:
"-"
}
return
r
;
def
getRunInfosNotAveraged
(
run_list
,
first_proc
):
nproc
=
[]
times
=
[]
times_err
=
[]
nprocbis
=
[]
timesbis
=
[]
rt0
=
0.
t0
=
0.
t0_err
=
0.
max_proc
=
0
for
r
,
j
in
run_list
:
t
=
r
.
getScalarQuantity
(
"time"
)[
0
,
1
]
n
=
r
[
"nproc"
]
if
n
>
max_proc_to_consider
:
continue
nproc
.
append
(
n
)
times
.
append
(
t
)
max_proc
=
max
(
max_proc
,
n
)
if
n
<
first_proc
:
continue
if
n
==
first_proc
:
t0
=
t
nprocbis
.
append
(
n
)
timesbis
.
append
(
t
)
r
=
{
"t0"
:
t0
,
"max_proc"
:
max_proc
,
"nproc"
:
np
.
array
(
nproc
),
"times"
:
np
.
array
(
times
),
"nprocbis"
:
np
.
array
(
nprocbis
),
"timesbis"
:
np
.
array
(
timesbis
),
"marker"
:
"o"
,
"fitmarker"
:
"-"
}
return
r
;
def
scal_func
(
x
,
a
,
b
):
return
b
/
x
**
a
def
scal_func_eff
(
x
,
a
,
b
):
return
-
x
*
a
+
b
def
plot_scalability
(
r
,
axe
):
legends
=
[]
plts
=
[]
if
len
(
r
[
"times"
])
>
2
:
popt
,
pcov
=
curve_fit
(
scal_func
,
r
[
"nprocbis"
],
r
[
"timesbis"
])
print
(
popt
)
print
(
pcov
)
p
,
=
axe
.
plot
(
r
[
"nproc"
],
scal_func
(
r
[
"nproc"
],
*
popt
),
r
[
"fitmarker"
])
plts
.
append
(
p
)
legend_text
=
r'$t = A / n^{\textcolor[rgb]{1,0,0}{B}}$'
;
legends
.
append
(
re
.
sub
(
r'B'
,
"{0:.3f}"
.
format
(
popt
[
0
]),
re
.
sub
(
r'A'
,
"{0:.3f}"
.
format
(
popt
[
1
]),
legend_text
)))
p
,
=
axe
.
plot
(
r
[
"nproc"
],
r
[
"times"
],
r
[
"marker"
])
plts
.
append
(
p
)
legends
.
append
(
r'simulations'
)
return
plts
,
legends
,
popt
def
plot_efficiency
(
r
,
axe
):
legends
=
[]
plts
=
[]
print
(
r
[
"t0"
])
p
,
=
axe
.
plot
(
r
[
"nproc"
],
r
[
"t0"
]
*
first_nproc
/
(
r
[
"nproc"
]
*
r
[
"times"
]),
"o"
)
plts
.
append
(
p
)
legends
.
append
(
r'simulations'
)
if
len
(
r
[
"times"
])
>
2
:
popt
,
pcov
=
curve_fit
(
scal_func
,
r
[
"nprocbis"
],
r
[
"timesbis"
])
print
(
popt
)
print
(
pcov
)
p
,
=
axe
.
plot
(
r
[
"nproc"
],
scal_func
(
first_nproc
,
*
popt
)
*
first_nproc
/
(
scal_func
(
r
[
"nproc"
],
*
popt
)
*
r
[
"nproc"
]),
r
[
"fitmarker"
])
plts
.
append
(
p
)
legend_text
=
r'$t = A / n^{\textcolor[rgb]{1,0,0}{B}}$'
;
legends
.
append
(
re
.
sub
(
r'B'
,
"{0:.2f}"
.
format
(
popt
[
0
]),
re
.
sub
(
r'A'
,
"{0:.2f}"
.
format
(
popt
[
1
]),
legend_text
)))
return
plts
,
legends
,
popt
## -- Get informations ---------------------------------------------------------
run_list_local
=
myrunselector
.
selectRuns
(
params
[
"run_constraints"
]
+
[
"run_name = wcleanup"
]
+
[
"material_file = ./material_local.dat"
]
+
[
"state = finished"
],
params
[
"job_constraints"
]
+
[
"nb_proc < {0}"
.
format
(
max_proc_to_consider
)
],
[
"jobs.nb_proc"
])
r_local
=
getRunInfosNotAveraged
(
run_list_local
,
first_nproc
)
run_list_nlocal
=
myrunselector
.
selectRuns
(
params
[
"run_constraints"
]
+
[
"run_name = wcleanup"
]
+
[
"material_file = ./material.dat"
]
+
[
"state = finished"
],
params
[
"job_constraints"
]
+
[
"nb_proc < {0}"
.
format
(
max_proc_to_consider
)
],
[
"jobs.nb_proc"
])
r_nlocal
=
getRunInfosNotAveraged
(
run_list_nlocal
,
first_nproc
)
r_local
[
"marker"
]
=
"ro"
r_local
[
"fitmarker"
]
=
"g-"
r_nlocal
[
"marker"
]
=
"mD"
r_nlocal
[
"fitmarker"
]
=
"c-"
## -- Plots --------------------------------------------------------------------
# t0 = np.max(r_local["times"])
# perfect, = axe0.plot(r_local["nproc"],
# scal_func(r_local["nproc"], 1, t0),
# "-")
#perfect, = axe0.plot(r_local["nproc"],
# t0 / (scal_func(r_local["nproc"], 1, t0)*r_local["nproc"]),
# "-")
extra1
=
patches
.
Rectangle
((
0
,
0
),
1
,
1
,
fc
=
"w"
,
fill
=
False
,
edgecolor
=
'none'
,
linewidth
=
0
)
extra2
=
patches
.
Rectangle
((
0
,
0
),
1
,
1
,
fc
=
"w"
,
fill
=
False
,
edgecolor
=
'none'
,
linewidth
=
0
)
plts_local
,
leg_local
,
popt_local
=
plot_scalability
(
r_local
,
axe0
)
plts_nlocal
,
leg_nlocal
,
popt_nlocal
=
plot_scalability
(
r_nlocal
,
axe0
)
#plts_local, leg_local, popt_local = plot_efficiency(r_local, axe0)
#plts_nlocal, leg_nlocal, popt_nlocal = plot_efficiency(r_nlocal, axe0)
## -- Legends ------------------------------------------------------------------
# lp = plt.legend([perfect], [r'perfect scalability'],
# loc="lower center", numpoints=1, ncol = 2,
# bbox_to_anchor = (0, 1.0, 1., .102), mode = None,
# borderaxespad = 0., fontsize = leg_fontsize, markerscale=1,
# frameon = False)
lr0
=
plt
.
legend
([
extra1
],
[
r'$\boldsymbol{R = 0 \milli\meter}$'
],
loc
=
"lower center"
,
numpoints
=
1
,
ncol
=
2
,
bbox_to_anchor
=
(
0
,
1.2
,
.
25
,
.
102
),
mode
=
None
,
borderaxespad
=
0.
,
fontsize
=
leg_fontsize
,
markerscale
=
1
,
frameon
=
False
)
lr0_1
=
plt
.
legend
([
extra1
],
[
r'$\boldsymbol{R = 0.1 \milli\meter}$'
],
loc
=
"lower center"
,
numpoints
=
1
,
ncol
=
2
,
bbox_to_anchor
=
(
0
,
1.2
,
1.25
,
.
102
),
mode
=
None
,
borderaxespad
=
0.
,
fontsize
=
leg_fontsize
,
markerscale
=
1
,
frameon
=
False
)
l
=
plt
.
legend
([
plts_local
[
1
],
plts_local
[
0
],
plts_nlocal
[
1
],
plts_nlocal
[
0
]
],
[
leg_local
[
1
],
leg_local
[
0
],
leg_nlocal
[
1
],
leg_nlocal
[
0
]
],
loc
=
"lower center"
,
numpoints
=
1
,
ncol
=
2
,
bbox_to_anchor
=
(
0
,
1.
,
1.
,
.
102
),
mode
=
None
,
borderaxespad
=
0.
,
fontsize
=
leg_fontsize
,
markerscale
=
1
,
frameon
=
False
)
#plt.gca().add_artist(lp)
plt
.
gca
()
.
add_artist
(
lr0
)
plt
.
gca
()
.
add_artist
(
lr0_1
)
## -- Decorations --------------------------------------------------------------
axe0
.
set_yscale
(
"log"
)
axe0
.
set_xscale
(
"log"
,
basex
=
2
)
#axe0.set_title("Scalability")
axe0
.
set_xlabel
(
r'Number of processors $n$ [-]'
)
axe0
.
set_ylabel
(
r'Time $t$ [\second]'
,
labelpad
=-
5
)
max_proc
=
max
(
r_local
[
"max_proc"
],
r_nlocal
[
"max_proc"
])
axe0
.
set_xlim
([
0.6
,
2
**
(
math
.
log
(
max_proc
)
/
math
.
log
(
2
)
+
1
)])
axe0
.
set_ylim
([
0.005
,
3
])
def
format_x
(
x
,
pos
=
None
):
i
=
int
(
x
)
if
i
<
first_nproc
:
return
str
(
i
)
else
:
return
r'\textbf{'
+
str
(
i
)
+
r'}'
axe0
.
xaxis
.
set_major_formatter
(
mpl
.
ticker
.
FuncFormatter
(
format_x
))
ylabels
=
[
str
(
item
)
for
item
in
axe0
.
get_yticks
()]
axe0
.
set_yticklabels
(
ylabels
)
fig
.
savefig
(
"scalability_paper.pdf"
,
bbox_extra_artists
=
(
l
,
lr0
,
lr0_1
,),
bbox_inches
=
'tight'
,
pad_inches
=
0.2
)
plt
.
show
()
Event Timeline
Log In to Comment