2
2
import sys
3
3
4
4
import click
5
- import numpy as np
6
5
import matplotlib .pyplot as plt
6
+ import numpy as np
7
+ from scipy .interpolate import spline
7
8
8
9
from abstract_experiment import AbstractExperiment
9
10
from utils import get_netz_username , parse_into_dict , conf_95_mean
10
11
11
12
sys .path .append (os .path .dirname (os .path .dirname (os .path .abspath (__file__ ))))
12
13
from euler import EulerTester
13
14
15
+ NAME_MAP = {'parallel' : 'Parallel' , 'stealing' : 'Work Stealing' }
16
+
14
17
15
18
class DpllScaling (AbstractExperiment ):
16
19
def __init__ (self ):
@@ -20,7 +23,7 @@ def __init__(self):
20
23
def run_experiment (self ):
21
24
test_folder = 'benchmark_formulas'
22
25
# number of cores
23
- num_nodes = [2 , 3 , 4 , 5 , 6 , 8 , 10 , 12 , 14 , 16 , 20 , 24 , 32 , 40 , 48 ]
26
+ num_nodes = [2 , 3 , 4 , 5 , 6 , 8 , 10 , 12 , 14 , 16 , 20 , 24 , 28 , 32 , 36 , 40 , 44 , 48 ]
24
27
# number of runs per formula
25
28
num_runs = 10
26
29
# timeout per formula in seconds
@@ -36,70 +39,162 @@ def process_euler_experiment(self):
36
39
self .data = parse_into_dict ('measurements.tar' )
37
40
38
41
def plot (self ):
39
- self ._runtime_plot ()
40
- self ._speedup_plot ()
42
+ for p in ['parallel' , 'stealing' ]:
43
+ self ._runtime_plot (p )
44
+ self ._speedup_plot (p )
45
+ files = ['uf50-01' , 'par8-1-c' , 'ais6' , 'flat75-4' , 'par8-4-' , 'anomaly' ]
46
+ colors = ['teal' , 'firebrick' , 'darkorange' , 'royalblue' ,
47
+ 'palevioletred' , 'slateblue' ]
48
+ offsets = [- 0.25 , 0.25 , 0 , 0.125 , - 0.125 ,
49
+ - 0.25 , 0.25 , 0 , 0.125 , - 0.125 ,
50
+ - 0.25 , 0.25 , 0 , 0.125 , - 0.125 ]
51
+ markers = ['o' , 'd' , 's' , '^' , 'x' , 'D' ]
52
+ figure = plt .figure ()
53
+ ax = figure .add_subplot (1 , 1 , 1 )
54
+ for f in range (len (files )):
55
+ self ._plot_runtime (self .data [files [f ]], 'parallel' , ax ,
56
+ color = colors [f ], offset = offsets [f ])
57
+ #plt.show()
58
+ for p in ['parallel' , 'stealing' ]:
59
+ figure = plt .figure ()
60
+ ax = figure .add_subplot (1 , 1 , 1 )
61
+ for f in range (len (files )):
62
+ self ._plot_speedup (self .data [files [f ]], p , ax ,
63
+ color = colors [f ], marker = markers [f ],
64
+ offset = offsets [f ], plotline = (f == 0 ),
65
+ legend = files [f ])
66
+ plt .title ('Speedup with {} Version' .format (NAME_MAP [p ]))
67
+ plt .xlabel ('# cores' )
68
+ plt .ylabel ('speedup' )
69
+ handles , labels = ax .get_legend_handles_labels ()
70
+ h = handles .pop (0 )
71
+ handles .append (h )
72
+ l = labels .pop (0 )
73
+ labels .append (l )
74
+ plt .legend (handles , labels )
75
+ plt .tight_layout (pad = 0 )
76
+ plt .savefig ('../../report/figures/dpll_scaling_{}.pdf' .format (p ),
77
+ format = 'pdf' )
78
+ #plt.show()
79
+ figure = plt .figure ()
80
+ ax = figure .add_subplot (1 , 1 , 1 )
81
+ for f in range (len (files )):
82
+ self ._plot_waiting (self .data [files [f ]], p , ax ,
83
+ color = colors [f ], marker = markers [f ],
84
+ offset = offsets [f ], label = files [f ])
85
+ plt .title ('Overall waiting time per cnf {} Version' .format (
86
+ NAME_MAP [p ]))
87
+ plt .xlabel ('# cores' )
88
+ plt .ylabel ('overall waiting time [ms]' )
89
+ plt .legend ()
90
+ plt .tight_layout (pad = 0 )
91
+ plt .savefig ('../../report/figures/dpll_waiting_{}.pdf' .format (p ),
92
+ format = 'pdf' )
93
+ #plt.show()
41
94
42
- def _runtime_plot (self ):
95
+ def _runtime_plot (self , parallel_key ):
43
96
for f , v in self .data .items ():
44
- xs = []
45
- ys = []
46
- lowers = []
47
- uppers = []
48
- if 'seq' in v :
49
- xs .append (1 )
50
- mean = np .mean (np .array (v ['seq' ]['time' ]).flatten ())
51
- ys .append (mean )
52
- lower , upper = conf_95_mean (np .array (v ['seq' ]['time' ]).flatten ())
53
- lowers .append (mean - lower )
54
- uppers .append (upper - mean )
55
- for cores , v_ in v ['parallel' ].items ():
56
- xs .append (int (cores ))
57
- mean = np .mean (np .array (v_ ['time' ]).flatten ())
58
- ys .append (mean )
59
- lower , upper = conf_95_mean (np .array (v_ ['time' ]).flatten ())
60
- lowers .append (mean - lower )
61
- uppers .append (upper - mean )
62
- ys = [y for _ , y in sorted (zip (xs , ys ))]
63
- xs = sorted (xs )
64
- plt .figure ()
65
- plt .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = 'o' ,
66
- markerfacecolor = 'none' )
97
+ figure = plt .figure ().add_subplot (1 , 1 , 1 )
98
+ self ._plot_runtime (v , parallel_key , figure )
67
99
plt .title ('{}.cnf' .format (f ))
68
- plt .ylim (0 , max (ys ) + 500 )
69
100
plt .xlabel ('# cores' )
70
- plt .ylabel ('avg runtime [ms]' )
71
- plt .savefig ('figures/{}.png' .format (f ))
101
+ plt .ylabel ('avg total waiting time [ms]' )
102
+ plt .savefig ('figures/{}_{} .png' .format (f , parallel_key ))
72
103
73
- def _speedup_plot (self ):
104
+ def _plot_runtime (self , data , parallel_key , figure , color = 'teal' , offset = 0.0 ):
105
+ if parallel_key not in data :
106
+ return
107
+ xs , ys , lowers , uppers = [], [], [], []
108
+ if 'seq' in data :
109
+ xs .append (1 + offset )
110
+ mean = np .mean (np .array (data ['seq' ]['time' ]).flatten ())
111
+ ys .append (mean )
112
+ lower , upper = conf_95_mean (np .array (data ['seq' ]['time' ]).flatten ())
113
+ lowers .append (mean - lower )
114
+ uppers .append (upper - mean )
115
+ for cores , v_ in data [parallel_key ].items ():
116
+ xs .append (int (cores ))
117
+ mean = np .mean (np .array (v_ ['time' ]).flatten ())
118
+ ys .append (mean )
119
+ lower , upper = conf_95_mean (np .array (v_ ['time' ]).flatten ())
120
+ lowers .append (mean - lower )
121
+ uppers .append (upper - mean )
122
+ ys = [y for _ , y in sorted (zip (xs , ys ))]
123
+ xs = sorted (xs )
124
+ figure .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = 'o' ,
125
+ markerfacecolor = 'none' , color = color )
126
+ xinter = np .linspace (min (xs ), max (xs ), 300 )
127
+ yinter = spline (xs , ys , xinter )
128
+ plt .plot (xinter , yinter , '-' , alpha = 0.5 , linewidth = 0.5 ,
129
+ color = color )
130
+
131
+ def _speedup_plot (self , parallel_key ):
74
132
for f , v in self .data .items ():
75
- xs = []
76
- ys = []
77
- lowers = []
78
- uppers = []
79
- if 'seq' in v :
80
- sequential = np .array (v ['seq' ]['time' ]).flatten ()
81
- for cores , v_ in v ['parallel' ].items ():
82
- xs .append (int (cores ))
83
- parallel = []
84
- for times in v_ ['time' ]:
85
- parallel .append (np .mean (times ))
86
- speedup = sequential / parallel
87
- mean_speedup = np .mean (speedup )
88
- ys .append (mean_speedup )
89
- lower , upper = conf_95_mean (speedup )
90
- lowers .append (mean_speedup - lower )
91
- uppers .append (upper - mean_speedup )
92
- ys = [y for _ , y in sorted (zip (xs , ys ))]
93
- xs = sorted (xs )
94
- plt .figure ()
95
- plt .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = 'o' ,
96
- markerfacecolor = 'none' )
97
- plt .plot ([0 , max (xs )], [0 , max (xs )], '--' )
98
- plt .title ('{}.cnf' .format (f ))
99
- plt .xlabel ('# cores' )
100
- plt .ylabel ('speedup' )
101
- plt .savefig ('figures/{}_speedup.png' .format (f ))
133
+ figure = plt .figure ().add_subplot (1 , 1 , 1 )
134
+ self ._plot_speedup (v , parallel_key , figure )
135
+ plt .title ('{}.cnf' .format (f ))
136
+ plt .xlabel ('# cores' )
137
+ plt .ylabel ('speedup' )
138
+ plt .savefig ('figures/{}_speedup_{}.png' .format (f , parallel_key ))
139
+
140
+ def _plot_speedup (self , data , parallel_key , figure , color = 'teal' ,
141
+ marker = 'o' , offset = 0.0 , plotline = True , legend = '' ):
142
+ if parallel_key not in data :
143
+ return
144
+ xs , ys , lowers , uppers = [], [], [], []
145
+ if 'seq' in data :
146
+ sequential = np .array (data ['seq' ]['time' ]).flatten ()
147
+ for cores , v_ in data [parallel_key ].items ():
148
+ xs .append (int (cores ))
149
+ parallel = []
150
+ for times in v_ ['time' ]:
151
+ parallel .append (np .mean (times ))
152
+ speedup = sequential / parallel
153
+ mean_speedup = np .mean (speedup )
154
+ ys .append (mean_speedup )
155
+ lower , upper = conf_95_mean (speedup )
156
+ lowers .append (mean_speedup - lower )
157
+ uppers .append (upper - mean_speedup )
158
+ ys = [y for _ , y in sorted (zip (xs , ys ))]
159
+ xs = sorted (xs )
160
+ xs = list (map (lambda x : float (x ) + offset , xs ))
161
+ if legend == '' :
162
+ figure .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = marker ,
163
+ markerfacecolor = 'none' , color = color )
164
+ else :
165
+ figure .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = marker ,
166
+ markerfacecolor = 'none' , color = color ,
167
+ label = legend )
168
+ #xinter = np.linspace(min(xs), max(xs), 300)
169
+ #yinter = spline(xs, ys, xinter)
170
+ #plt.plot(xinter, yinter, '-', alpha=0.5, linewidth=0.5,
171
+ # color=color)
172
+ plt .plot (xs , ys , '-' , alpha = 0.5 , linewidth = 0.5 , color = color )
173
+ if plotline :
174
+ plt .plot ([0 , max (xs )], [0 , max (xs )], '-' , color = 'black' ,
175
+ label = 'Linear Speedup' )
102
176
177
+ def _plot_waiting (self , data , parallel_key , figure , color = 'teal' ,
178
+ offset = 0.0 , label = '' , marker = 'o' ):
179
+ if parallel_key not in data :
180
+ return
181
+ xs , ys , lowers , uppers = [], [], [], []
182
+ for cores , v_ in data [parallel_key ].items ():
183
+ xs .append (int (cores ) + offset )
184
+ sums = list (map (lambda wt : np .sum (np .array (wt [1 :])),
185
+ v_ ['wait' ]))
186
+ mean = np .mean (sums )
187
+ ys .append (mean )
188
+ lower , upper = conf_95_mean (sums )
189
+ lowers .append (mean - lower )
190
+ uppers .append (upper - mean )
191
+ ys = [y for _ , y in sorted (zip (xs , ys ))]
192
+ lowers = [l for _ , l in sorted (zip (xs , lowers ))]
193
+ uppers = [u for _ , u in sorted (zip (xs , uppers ))]
194
+ xs = sorted (xs )
195
+ figure .errorbar (xs , ys , yerr = [lowers , uppers ], fmt = marker ,
196
+ markerfacecolor = 'none' , color = color , label = label )
197
+ plt .plot (xs , ys , '-' , alpha = 0.5 , linewidth = 0.5 , color = color )
103
198
104
199
@click .command ()
105
200
@click .option ('--rerun/--no-rerun' , default = False ,
@@ -110,7 +205,7 @@ def main(rerun, process):
110
205
e = DpllScaling ()
111
206
if rerun :
112
207
e .run_experiment ()
113
- if process :
208
+ elif process :
114
209
e .process_euler_experiment ()
115
210
e .results_to_json ()
116
211
else :
0 commit comments