-
Notifications
You must be signed in to change notification settings - Fork 0
/
perfplots.py
658 lines (628 loc) · 25.4 KB
/
perfplots.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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
""" usefull to generate plot about performance scaling/ iterations """
import copy
import pylab as pl
import extractor as ex
from plotting_constants import COLORS, MARKERS, MARKERC, LINES, LINEC
def plot_nonlinears(paths=None, filename='nonlinear', refs=0, labels=None,
save=False):
""" plots residual ... over iterations """
legend_yes = True
if labels is None:
labels = paths
legend_yes = False
if paths is None:
paths = ['./']
labels = paths
if len(paths) == 1:
LINES[0] = '-'
legend_yes = False
if refs == 0:
ref_strs = ['']
else:
ref_strs = []
for ref in range(refs):
ref_strs.append(str(ref))
for i, path in enumerate(paths):
offset = 0
for ref_str in ref_strs:
file_str = path+filename+ref_str+'.txt'
iter_count = pl.array(
ex.extract(file_str, ex.NOXIterPattern))+offset
offset = iter_count[-1]
res = ex.extract(file_str, ex.NOXResPattern)
print(iter_count)
print(res)
# --- residual ---
pl.figure(1)
pl.semilogy(iter_count, res[:, 0], marker='.', color=COLORS[i],
ls=LINES[i])
# if refs == 0:
# pl.semilogy(iter_count, res[:, 0], marker='.', color=COLORS[i],
# ls=LINES[i], label=labels[i])
# else:
# pl.semilogy(iter_count, res[:, 0], marker='.', color=COLORS[i],
# ls=LINES[i])
pl.semilogy(iter_count, res[:, 0], marker='.', color=COLORS[i],
linestyle=LINES[i], label=labels[i])
if legend_yes:
# pl.legend(loc=0)
pl.legend(loc=0, handletextpad=0.1)
pl.xlabel('Picard iteration')
pl.ylabel(r'$\|\mathbf{r}\|$', ha='right', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(0.0, 1.02)
pl.gca().get_xaxis().set_major_locator(
pl.MaxNLocator(integer=True))
# --- update ---
if save:
pl.savefig('F.pdf', bbox_inches='tight')
# --- step width ---
pl.figure(2)
pl.semilogy(iter_count[1:], res[1:, 1], basey=2, marker='.',
color=COLORS[i], linestyle=LINES[i],
label=labels[i])
if legend_yes:
# pl.legend(loc=0)
pl.legend(loc=0, handletextpad=0.1)
pl.xlabel('Picard step')
pl.ylabel(r'step width', ha='right', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(0.0, 1.02)
pl.gca().get_xaxis().set_major_locator(
pl.MaxNLocator(integer=True))
if save:
pl.savefig('lam.pdf', bbox_inches='tight')
#
pl.figure(3)
pl.semilogy(iter_count[1:], res[1:, 2], marker='.',
color=COLORS[i], linestyle=LINES[i],
label=labels[i])
if legend_yes:
# pl.legend(loc=0)
pl.legend(loc=0, handletextpad=0.1)
pl.xlabel('Picard step')
pl.ylabel(r'$||\delta\mathbf{q}||$', ha='right', va='bottom',
rotation=0)
pl.gca().yaxis.set_label_coords(0.0, 1.03)
pl.gca().get_xaxis().set_major_locator(
pl.MaxNLocator(integer=True))
if save:
pl.savefig('du.pdf', bbox_inches='tight')
# def plot_linear(paths=None, filename='Picard', leg=None, refs=1):
# """ plots linear iteration and tolerance """
# if paths is None:
# paths = ['./']
# for i, pre_str in enumerate(paths):
# offset = 0
# for ref in range(refs):
# file_str = pre_str + filename + str(ref) + '.txt'
# lin_iter = ex.extract(file_str, ex.BelosMaxItPattern)
# linatol = ex.extract(file_str, ex.BelosArTolPattern)
# print(linatol)
# pl.figure()
# if isinstance(lin_iter, float): # wtf
# lin_iter = [lin_iter]
# pl.plot(pl.arange(1, len(lin_iter)+1) + offset, lin_iter,
# marker='.', color=COLORS[i], ls=LINES[i])
# pl.xlabel('Picard iteration')
# pl.ylabel(r'linear iterations', ha='left', va='bottom', rotation=0)
# pl.gca().yaxis.set_label_coords(-0.08, 1.02)
# pl.gca().get_xaxis().set_major_locator(
# pl.MaxNLocator(integer=True))
# if leg is not None:
# pl.legend(leg, loc=0)
# pl.savefig('liniter.pdf', bbox_inches='tight')
# #
# pl.figure()
# pl.semilogy(pl.arange(1, len(linatol)+1) + offset, linatol,
# marker='.', color=COLORS[i], ls=LINES[i])
# pl.xlabel('Picard iteration')
# pl.ylabel(r'archieved tolerance of the linear solver', ha='left',
# va='bottom', rotation=0)
# pl.gca().yaxis.set_label_coords(-0.08, 1.02)
# pl.gca().get_xaxis().set_major_locator(
# pl.MaxNLocator(integer=True))
# if leg is not None:
# # legend(leg,bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# pl.legend(leg, loc=0)
# pl.savefig('lintol.pdf', bbox_inches='tight')
# offset += len(linatol)
def plotNOX(paths=None, filename='output', run='', newton=False, save=False):
""" plots residual ... over iterations (deprecated) """
if paths is None:
paths = ['./']
for path in paths:
iter_count = ex.extract(path+filename+str(run), ex.NOXIterPattern)
res = ex.extract(path+filename+str(run), ex.NOXResPattern)
# dof = ex.extract(path+filename+str(run), ex.PimpDofPattern)[0][0]
# print('dof: ', dof)
print(iter_count)
print(res)
pl.figure(1)
# pl.semilogy(iter_count, res[:, 0]/pl.sqrt(dof))
# pl.semilogy(res[:, 0]/pl.sqrt(dof), marker='.')
pl.semilogy(res[:, 0], marker='.')
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard iteration')
pl.ylabel(r'$||\mathbf{r}||_2/\sqrt{N}$')
# pl.ylabel(r'$||\mathbf{r}||_2/\sqrt{N}$', ha='left', va='bottom',
# rotation=0)
# pl.gca().yaxis.set_label_coords(-0.08, 1.02)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('F.pdf', bbox_inches='tight')
pl.figure(2)
pl.semilogy(iter_count[1:], res[1:, 1], basey=2, marker='.')
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard iteration')
pl.ylabel(r'step width')
# pl.ylabel(r'step width', ha='left', va='bottom', rotation=0)
# pl.gca().yaxis.set_label_coords(-0.08, 1.02)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('lam.pdf', bbox_inches='tight')
#
pl.figure(3)
# pl.semilogy(iter_count[1:], res[1:, 2]/pl.sqrt(dof), marker='.')
pl.semilogy(iter_count[1:], res[1:, 2], marker='.')
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard step')
pl.ylabel(r'$||\delta\mathbf{q}||_2/\sqrt{N}$')
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('du.pdf', bbox_inches='tight')
def plotNOX2(paths=['./'], leg=[], run='', newton=False, save=False):
for path in paths:
iters = ex.extract(path+'output'+str(run), ex.NOXIterPattern)
res = ex.extract(path+'output'+str(run), ex.NOXResPattern)
dof = ex.extract(path+'output'+str(run), ex.PimpDofPattern)
print('dof: ', dof)
# if isinstance(dof,float) :
# dof=[dof]
#
cumsum = 0
iterres = [0]
iter_belos = []
for j, iter_temp in enumerate(iters):
if j > 0 and iter_temp == 0:
cumsum = iters[j-1]
iterres.append(j)
else:
iter_belos.append(iter_temp+cumsum)
iters[j] = iter_temp+cumsum
#
if len(iterres) > 1:
for j in range(max(len(iterres)-1, 1)):
# print(iterres[j],iterres[j+1])
res[iterres[j]:iterres[j+1], [0, 2]] = \
res[iterres[j]:iterres[j+1], [0, 2]]/pl.sqrt(dof[j])
res[iterres[j+1]:, [0, 2]] = res[iterres[j+1]:,
[0, 2]]/pl.sqrt(dof[j])
else:
res[:, [0, 2]] = res[:, [0, 2]]/pl.sqrt(dof)
#
linestyle = LINEC.next()
m = MARKERC.next()
pl.figure(1)
# pl.semilogy(iters[:],res[:,0], label=lab,linestyle=linestyle)
pl.semilogy(iters, res[:, 0], linestyle=linestyle)
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard step')
pl.ylabel(r'$||\mathbf{r}||_2/\sqrt{N}$', ha='left', va='bottom',
rotation=0)
pl.gca().yaxis.set_label_coords(-0.09, 1.075)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
#legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
#xlim((0,9))
# legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# xlim((0,9))
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('F.pdf', bbox_inches='tight')
#
pl.figure(2)
# semilogy(iters[:],res[:,1],basey=2,
# label=lab,linestyle=linestyle,marker=m)
pl.semilogy(iters[1:], res[1:, 1], basey=2, linestyle=linestyle,
marker=m)
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard iteration')
pl.ylabel(r'step width')
pl.ylabel(r'step width', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
#legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
pl.ylabel(r'step width', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
# legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('lam.pdf', bbox_inches='tight')
#
pl.figure(3)
# semilogy(iters[:],res[:,2],label=lab,linestyle=linestyle ,marker=m)
pl.semilogy(iters[1:], res[1:, 2], linestyle=linestyle, marker=m)
if newton:
pl.xlabel('Newton step')
else:
pl.xlabel('Picard iteration')
pl.ylabel(r'$||\delta\mathbf{q}||_2/\sqrt{N}$')
pl.ylabel(r'$||\delta\mathbf{q}||_2/\sqrt{N}$', ha='left', va='bottom',
rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
#legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
pl.xlabel('Picard step')
pl.ylabel(r'$||\delta\mathbf{q}||_2/\sqrt{N}$', ha='left', va='bottom',
rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
# legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('du.pdf', bbox_inches='tight')
#
# figure(4)
# #if(len(iter_belos)==len(lin_iter)):
# #plot(itersBelos[:],lin_iter[:],label=lab,linestyle=linestyle)
# #elif(len(iter_belos)-1==len(lin_iter)):
# #plot(iter_belos[1:],lin_iter[:],marker=m,
# lw=0.5,label=lab,linestyle=linestyle) #else:
# if isinstance(lin_iter,float) :
# lin_iter=[lin_iter]
# plot(range(1,len(lin_iter)+1),lin_iter,marker=m,lw=0.5,linestyle=linestyle)
# xlabel('Newton iteration')
# ylabel(r'linear iterations')
# #legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# gca().get_xaxis().set_major_locator(MaxNLocator(integer=True))
# savefig('liniter.pdf',bbox_inches='tight')
# #
# figure(5)
# #semilogy(iter_belos[1:],linatol[:],marker=m,lw=0.5,label=lab,linestyle=linestyle)
# semilogy(range(1,len(linatol)+1),linatol[:],marker=m,lw=0.5,linestyle=linestyle)
# xlabel('Newton iteration')
# ylabel(r'archieved tolerance of the linear solver')
# #legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
# gca().get_xaxis().set_major_locator(MaxNLocator(integer=True))
# savefig('lintol.pdf',bbox_inches='tight')
# i += 1
# show()
def plotBelos(files=None, leg=None):
if files is None:
files = ['./Picard.txt']
i = 0
for file_str in files:
lin_iter = ex.extract(file_str, ex.BelosMaxItPattern)
linatol = ex.extract(file_str, ex.BelosArTolPattern)
print(linatol)
pl.figure(4)
if isinstance(lin_iter, float): # wtf
lin_iter = [lin_iter]
pl.plot(range(1, len(lin_iter)+1), lin_iter, marker='.')
pl.xlabel('Picard iteration')
pl.ylabel(r'linear iterations')
pl.ylabel(r'linear iterations', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
if leg is not None:
pl.legend(leg, loc=0)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
pl.savefig('liniter.pdf', bbox_inches='tight')
#
pl.figure(5)
pl.semilogy(range(1, len(linatol)+1), linatol, marker='.')
pl.xlabel('Picard iteration')
pl.ylabel(r'archieved tolerance of the linear solver')
pl.ylabel(r'archieved tolerance of the linear solver', ha='left',
va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
# legend(leg,bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0.)
if leg is not None:
pl.legend(leg, loc=0)
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
def plot_linear(file_str='./Picard.txt', label=None, save=False, fig=1,
offset=0, linestyle='-'):
""" plots the linear iteration and achieved tolerance """
lin_iter = ex.extract(file_str, ex.BelosMaxItPattern)
linatol = ex.extract(file_str, ex.BelosArTolPattern)
print(linatol)
pl.figure(fig)
if isinstance(lin_iter, float): # wtf
lin_iter = [lin_iter]
pl.plot(pl.arange(1, len(lin_iter)+1)+offset, lin_iter, marker='.',
label=label, linestyle=linestyle)
pl.xlabel('Picard step')
pl.ylabel(r'linear iteration steps', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
pl.gca().get_yaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('liniter.pdf', bbox_inches='tight')
#
pl.figure(fig+1)
pl.semilogy(pl.arange(1, len(linatol)+1)+offset, linatol, marker='.',
label=label, linestyle=linestyle)
pl.xlabel('Picard step')
# pl.ylabel(r'achieved tolerance of the linear solver', ha='left',
# va='bottom', rotation=0)
# pl.gca().yaxis.set_label_coords(-0.08, 1.02)
pl.ylabel(r'achieved tolerance of the linear solver')
pl.gca().get_xaxis().set_major_locator(pl.MaxNLocator(integer=True))
if save:
pl.savefig('lintol.pdf', bbox_inches='tight')
offset += len(linatol)
return offset
def plot_linears(path='./', filenames=None, leg=None, refs=0, save=False):
""" plots linear iteration and tolerance """
if filenames is None:
filenames = [r'Picard', r'ConvectionDiffusionVOp',
r'ModeNonlinearOp_ConvectionDiffusionVOp', r'DivGrad']
if refs == 0:
refs_str = ['']
else:
refs_str = []
for i in range(refs):
refs_str.append(str(i))
for i, file_pre in enumerate(filenames):
offset = 0
for ref in refs_str:
file_str = path + file_pre + ref + '.txt'
if file_pre == r'Picard':
linestyle = '-'
else:
linestyle = ''
offset = plot_linear(file_str=file_str, fig=2*i, offset=offset,
linestyle=linestyle, save=False)
pl.figure(2*i)
if file_pre == r'Picard':
pl.title('Picard problem')
pl.xlabel('Picard step')
elif file_pre == r'ConvectionDiffusionVOp':
pl.title(r'Convection-diffusion problem')
pl.xlabel('')
elif file_pre == r'ModeNonlinearOp_ConvectionDiffusionVOp':
pl.title(r'Harmonic convection-diffusion problem')
pl.xlabel('')
elif file_pre == r'DivGrad':
pl.title(r'Poisson problem')
pl.xlabel('')
pl.figure(2*i+1)
if file_pre == r'Picard':
pl.title('Picard problem')
pl.xlabel('Picard step')
elif file_pre == r'ConvectionDiffusionVOp':
pl.title(r'Convection-diffusion problem')
pl.xlabel('')
elif file_pre == r'ModeNonlinearOp_ConvectionDiffusionVOp':
pl.title(r'Harmonic convection-diffusion problem')
pl.xlabel('')
elif file_pre == r'DivGrad':
pl.title(r'Poisson problem')
pl.xlabel('')
if save:
pl.figure(2*i)
pl.savefig(path+file_pre+'_liniter.pdf', bbox_inches='tight')
pl.figure(2*i+1)
pl.savefig(path+file_pre+'_lintol.pdf', bbox_inches='tight')
def __my_cumsum(iters):
cumsum = 0
iterres = pl.copy(iters)
for j, iter_temp in enumerate(iters):
if j > 0 and iter_temp == 0:
cumsum = iterres[j-1]
iterres[j-1] -= 0.00
iterres[j] += cumsum + 0.00
else:
iterres[j] += cumsum
return iterres
def plot_refinement(path='./', save=False, r_min=None, nf_max=None):
""" plots residual refinement ... over iterations """
file_str = path+'refinementTest.txt'
res = pl.loadtxt(file_str)
print(res)
pl.figure(1)
ax1 = pl.subplot(211)
pl.subplots_adjust(hspace=0)
iters = __my_cumsum(res[:, 0])
Markersize = 3
pl.semilogy(iters, res[:, 2]/(2.*res[:, 1] + 1), marker=MARKERS[0],
markersize=Markersize,
color=COLORS[0], linestyle=LINES[0], label=r'$\|\mathbf{r}\|$')
pl.semilogy(iters, res[:, 3]/res[:, 4]/2., marker=MARKERS[1], color=COLORS[1],
linestyle=LINES[1], markersize=Markersize,
label=r'$\Delta r$') # , nonposy='clip'
# pl.ylabel(r'$\|\mathbf{r}\|$')
pl.legend(loc=0, handletextpad=0.1)
pl.setp(ax1.get_xticklabels(), visible=False)
ax2 = pl.subplot(212, sharex=ax1)
for i in range(len(res[:, 1])):
if res[i, 3] == 0.:
res[i, 4] = 0
pl.plot(iters, res[:, 1], marker=MARKERS[3], color=COLORS[0],
markersize=Markersize,
linestyle=LINES[3], label=r'$N_f$',)
pl.plot(iters, res[:, 4], marker=MARKERS[4], color=COLORS[1],
markersize=Markersize,
linestyle=LINES[4], label=r'$N_f^{\mathrm{inc}}$')
pl.legend(loc=0, handletextpad=0.1)
# pl.ylabel(r'$N_f$')
pl.xlabel('Picard step')
pl.gca().get_xaxis().set_major_locator(
pl.MaxNLocator(integer=True))
pl.gca().get_yaxis().set_major_locator(
pl.MaxNLocator(integer=True))
# setting limits if necessary
if r_min is not None:
ax1.set_ylim(ymin=r_min)
if r_min is not None:
ax2.set_ylim(ymax=nf_max)
if save:
pl.savefig(path+'refF.pdf', bbox_inches='tight')
def polt_speedup(paths, nps, lab=None, runs=None):
""" plots speedup """
if lab is None:
lab = []
if runs is None:
runs = ['']
time = []
for path in paths:
temptime = 1e99
for run in runs:
tempnew = ex.extract(path+'output'+str(run),
ex.PimpSolveTimePattern, isarray=False)
print('tempnew: ', tempnew)
tempnew = tempnew
temptime = min(temptime, tempnew)
time.append(temptime)
#
print('nps: ', nps)
print('time: ', time)
if not lab:
pl.plot(nps, time[0]/pl.array(time), '.-', ms=5)
else:
pl.plot(nps, time[0]/pl.array(time), '.-', ms=5, label=lab)
pl.plot(nps, pl.array(nps)/pl.array(nps[0]), ':', lw=2)
pl.ylim(ymin=1)
pl.gca().xaxis.set_ticks(nps)
pl.xlabel('number of cores')
pl.ylabel('speed-up', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.05, 1.075)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
def plot_strongscaling(paths, nps, lab=None, runs=None):
""" plots strong scaling """
if lab is None:
lab = []
if runs is None:
runs = ['']
time = []
for path in paths:
temptime = 1e99
for run in runs:
tempnew = ex.extract(path+'output'+str(run),
ex.PimpSolveTimePattern, isarray=False)
print('tempnew: ', tempnew)
tempnew = tempnew
temptime = min(temptime, tempnew)
time.append(temptime)
#
print('nps: ', nps)
print('time: ', time)
if not lab:
pl.loglog(nps, time, '.-', ms=5, basex=2)
else:
pl.loglog(nps, time, '.-', ms=5, label=lab, basex=2, basey=2)
pl.loglog(nps, time[0]*1./pl.array(nps), '--', color='k', ms=5, label=lab,
basex=2, basey=2)
# loglog(nps,array(nps)/array(nps[0]),':',lw=2)
# ylim(ymin=1)
pl.gca().xaxis.set_ticks(nps)
pl.xlabel('number of cores')
pl.ylabel('time[s]', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.05, 1.075)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
def plot_weakscaling(paths, nps, lab=None, runs=None):
""" plots weak scaling """
if lab is None:
lab = []
if runs is None:
runs = ['']
time = []
for path in paths:
temptime = 1e99
for run in runs:
tempnew = ex.extract(path+'output'+str(run),
ex.PimpSolveTimePattern, isarray=False)
print('tempnew: ', tempnew)
tempnew = tempnew
temptime = min(temptime, tempnew)
# print(temptime)
time.append(temptime)
#
print('nps: ', nps)
print('time: ', time)
if not lab:
pl.loglog(nps, time, '.-', ms=5, basex=2)
else:
pl.loglog(nps, time, '.-', ms=5, label=lab, basex=2, basey=2)
pl.loglog(nps, time[0]*pl.ones(len(nps)), '--', color='k', ms=5,
label=lab, basex=2, basey=2)
pl.gca().xaxis.set_ticks(nps)
pl.xlabel('number of cores')
pl.ylabel('time[s]', ha='left', va='bottom', rotation=0)
pl.gca().yaxis.set_label_coords(-0.05, 1.075)
pl.gca().yaxis.set_label_coords(-0.08, 1.02)
def get_times(paths, runs, pattern):
""" extracts times """
time_min = []
time_mean = []
time_std = []
fails = []
for path in paths:
temptime = []
fails.append(0.)
for run in runs:
tempnew = ex.extract(path+'output'+str(run), pattern,
isarray=False)
if isinstance(tempnew, pl.ndarray):
if tempnew:
temptime.append(tempnew[0])
else:
fails[-1] += 1.
else:
temptime.append(tempnew)
time_min.append(min(temptime))
time_mean.append(pl.mean(temptime))
time_std.append(pl.std(temptime))
fails[-1] /= len(runs)
return time_min, fails, time_mean, time_std
def plot_efficiency(paths, nps, label=None, runs=None,
pattern=ex.PimpSolveTimePattern,
marker='', linestyle='-', color='b'):
""" plots efficiency """
if runs is None:
runs = ['']
times, fails, times_mean, times_std = get_times(paths, runs, pattern)
print('')
print(label)
print('nps: ', nps)
print('times: ', times)
print('fails: ', fails)
efficency = copy.deepcopy(nps)
for i, time in enumerate(times):
efficency[i] = times[0]/time/nps[i]
if label is None:
pl.plot(nps, efficency, '.-', linestyle=linestyle, color=color)
else:
pl.semilogx(nps, efficency, '.-', label=label, marker=marker,
linestyle=linestyle, color=color)
return time
def add_time(paths, nps, label='', runs=None, pattern=ex.PimpSolveTimePattern,
scale=1, basex=10, basey=10, marker='', linestyle='-', color='',
legend=True):
""" adds time """
if runs is None:
runs = ['']
time, fails, time_mean, time_std = get_times(paths, runs, pattern)
print('')
print(label)
print('nps: ', nps)
print('time: ', time)
print('time_mean: ', time_mean)
print('time_std: ', time_std)
print('fails: ', fails)
# errorbar(log(nps), log(time_mean), log(time_std))
# errorbar(log(nps), log(time), log(time_std))
if color:
pl.loglog(nps, pl.array(time)*scale, label=label, basex=basex,
basey=basey, marker=marker, linestyle=linestyle,
color=color)
else:
pl.loglog(nps, pl.array(time)*scale, label=label, basex=basex,
basey=basey, marker=marker, linestyle=linestyle)
if legend:
pl.legend(loc=0)
return time