13428b40fSMatthew G Knepley#!/usr/bin/env python 2eda8839fSMatthew G Knepleyimport os,sys 3683aebbfSMatthew G Knepleysys.path.append(os.path.join(os.environ['PETSC_DIR'], 'config')) 4683aebbfSMatthew G Knepleyfrom builder2 import buildExample 519d5f70aSMatthew G Knepleyfrom benchmarkBatch import generateBatchScript 63428b40fSMatthew G Knepley 73428b40fSMatthew G Knepleyclass PETSc(object): 83428b40fSMatthew G Knepley def __init__(self): 93428b40fSMatthew G Knepley return 103428b40fSMatthew G Knepley 113428b40fSMatthew G Knepley def dir(self): 123428b40fSMatthew G Knepley '''Return the root directory for the PETSc tree (usually $PETSC_DIR)''' 133428b40fSMatthew G Knepley # This should search for a valid PETSc 143428b40fSMatthew G Knepley return os.environ['PETSC_DIR'] 153428b40fSMatthew G Knepley 163428b40fSMatthew G Knepley def arch(self): 173428b40fSMatthew G Knepley '''Return the PETSc build label (usually $PETSC_ARCH)''' 183428b40fSMatthew G Knepley # This should be configurable 193428b40fSMatthew G Knepley return os.environ['PETSC_ARCH'] 203428b40fSMatthew G Knepley 213428b40fSMatthew G Knepley def mpiexec(self): 223428b40fSMatthew G Knepley '''Return the path for the mpi launch executable''' 23e3da8a91SMatthew G Knepley mpiexec = os.path.join(self.dir(), self.arch(), 'bin', 'mpiexec') 246cbfa02cSMatthew G Knepley if not os.path.isfile(mpiexec): 25e3da8a91SMatthew G Knepley return None 26e3da8a91SMatthew G Knepley return mpiexec 273428b40fSMatthew G Knepley 283428b40fSMatthew G Knepley def example(self, num): 293428b40fSMatthew G Knepley '''Return the path to the executable for a given example number''' 303428b40fSMatthew G Knepley return os.path.join(self.dir(), self.arch(), 'lib', 'ex'+str(num)+'-obj', 'ex'+str(num)) 313428b40fSMatthew G Knepley 320790b1abSMatthew G Knepley def source(self, library, num): 330790b1abSMatthew G Knepley '''Return the path to the sources for a given example number''' 340790b1abSMatthew G Knepley d = os.path.join(self.dir(), 'src', library.lower(), 'examples', 'tutorials') 350790b1abSMatthew G Knepley name = 'ex'+str(num) 360790b1abSMatthew G Knepley sources = [] 370790b1abSMatthew G Knepley for f in os.listdir(d): 380790b1abSMatthew G Knepley if f == name+'.c': 392642ea08SMatthew G Knepley sources.insert(0, f) 400790b1abSMatthew G Knepley elif f.startswith(name) and f.endswith('.cu'): 410790b1abSMatthew G Knepley sources.append(f) 420790b1abSMatthew G Knepley return map(lambda f: os.path.join(d, f), sources) 430790b1abSMatthew G Knepley 443428b40fSMatthew G Knepleyclass PETScExample(object): 453428b40fSMatthew G Knepley def __init__(self, library, num, **defaultOptions): 463428b40fSMatthew G Knepley self.petsc = PETSc() 473428b40fSMatthew G Knepley self.library = library 483428b40fSMatthew G Knepley self.num = num 493428b40fSMatthew G Knepley self.opts = defaultOptions 503428b40fSMatthew G Knepley return 513428b40fSMatthew G Knepley 523428b40fSMatthew G Knepley @staticmethod 53d006b754SMatthew G Knepley def runShellCommand(command, cwd = None, log = True): 543428b40fSMatthew G Knepley import subprocess 553428b40fSMatthew G Knepley 563428b40fSMatthew G Knepley Popen = subprocess.Popen 573428b40fSMatthew G Knepley PIPE = subprocess.PIPE 58d006b754SMatthew G Knepley if log: print 'Executing: %s\n' % (command,) 593428b40fSMatthew G Knepley pipe = Popen(command, cwd=cwd, stdin=None, stdout=PIPE, stderr=PIPE, bufsize=-1, shell=True, universal_newlines=True) 603428b40fSMatthew G Knepley (out, err) = pipe.communicate() 613428b40fSMatthew G Knepley ret = pipe.returncode 623428b40fSMatthew G Knepley return (out, err, ret) 633428b40fSMatthew G Knepley 643428b40fSMatthew G Knepley def optionsToString(self, **opts): 653428b40fSMatthew G Knepley '''Convert a dictionary of options to a command line argument string''' 663428b40fSMatthew G Knepley a = [] 673428b40fSMatthew G Knepley for key,value in opts.iteritems(): 683428b40fSMatthew G Knepley if value is None: 693428b40fSMatthew G Knepley a.append('-'+key) 703428b40fSMatthew G Knepley else: 713428b40fSMatthew G Knepley a.append('-'+key+' '+str(value)) 723428b40fSMatthew G Knepley return ' '.join(a) 733428b40fSMatthew G Knepley 74d006b754SMatthew G Knepley def run(self, numProcs = 1, log = True, **opts): 75e3da8a91SMatthew G Knepley if self.petsc.mpiexec() is None: 76e3da8a91SMatthew G Knepley cmd = self.petsc.example(self.num) 77e3da8a91SMatthew G Knepley else: 7819d5f70aSMatthew G Knepley cmd = ' '.join([self.petsc.mpiexec(), '-n', str(numProcs), self.petsc.example(self.num)]) 79e3da8a91SMatthew G Knepley cmd += ' '+self.optionsToString(**self.opts)+' '+self.optionsToString(**opts) 8019d5f70aSMatthew G Knepley if 'batch' in opts and opts['batch']: 8119d5f70aSMatthew G Knepley del opts['batch'] 823849a283SMatthew G Knepley filename = generateBatchScript(self.num, numProcs, 120, ' '+self.optionsToString(**self.opts)+' '+self.optionsToString(**opts)) 833849a283SMatthew G Knepley # Submit job 84d006b754SMatthew G Knepley out, err, ret = self.runShellCommand('qsub -q gpu '+filename, log = log) 853849a283SMatthew G Knepley if ret: 863849a283SMatthew G Knepley print err 873849a283SMatthew G Knepley print out 8819d5f70aSMatthew G Knepley else: 89d006b754SMatthew G Knepley out, err, ret = self.runShellCommand(cmd, log = log) 903428b40fSMatthew G Knepley if ret: 913428b40fSMatthew G Knepley print err 923428b40fSMatthew G Knepley print out 930790b1abSMatthew G Knepley return out 943428b40fSMatthew G Knepley 95eda8839fSMatthew G Knepleydef processSummary(moduleName, defaultStage, eventNames, times, events): 963428b40fSMatthew G Knepley '''Process the Python log summary into plot data''' 973428b40fSMatthew G Knepley m = __import__(moduleName) 983428b40fSMatthew G Knepley reload(m) 993428b40fSMatthew G Knepley # Total Time 1003428b40fSMatthew G Knepley times.append(m.Time[0]) 1013428b40fSMatthew G Knepley # Particular events 102eda8839fSMatthew G Knepley for name in eventNames: 103eda8839fSMatthew G Knepley if name.find(':') >= 0: 104eda8839fSMatthew G Knepley stageName, name = name.split(':', 1) 105eda8839fSMatthew G Knepley stage = getattr(m, stageName) 106eda8839fSMatthew G Knepley else: 107eda8839fSMatthew G Knepley stage = getattr(m, defaultStage) 108eda8839fSMatthew G Knepley if name in stage.event: 1093428b40fSMatthew G Knepley if not name in events: 1103428b40fSMatthew G Knepley events[name] = [] 111df494a56SMatthew G Knepley try: 112eda8839fSMatthew G Knepley events[name].append((stage.event[name].Time[0], stage.event[name].Flops[0]/(stage.event[name].Time[0] * 1e6))) 113df494a56SMatthew G Knepley except ZeroDivisionError: 114df494a56SMatthew G Knepley events[name].append((stage.event[name].Time[0], 0)) 1153428b40fSMatthew G Knepley return 1163428b40fSMatthew G Knepley 1176e25a272SMatthew G Knepleydef plotTime(library, num, eventNames, sizes, times, events): 1186e25a272SMatthew G Knepley from pylab import legend, plot, show, title, xlabel, ylabel 1196e25a272SMatthew G Knepley import numpy as np 1206e25a272SMatthew G Knepley 1216e25a272SMatthew G Knepley arches = sizes.keys() 1226e25a272SMatthew G Knepley data = [] 1236e25a272SMatthew G Knepley for arch in arches: 1246e25a272SMatthew G Knepley data.append(sizes[arch]) 1256e25a272SMatthew G Knepley data.append(times[arch]) 1266e25a272SMatthew G Knepley plot(*data) 1276e25a272SMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 1286e25a272SMatthew G Knepley xlabel('Number of Dof') 1296e25a272SMatthew G Knepley ylabel('Time (s)') 1306e25a272SMatthew G Knepley legend(arches, 'upper left', shadow = True) 1316e25a272SMatthew G Knepley show() 1326e25a272SMatthew G Knepley return 1336e25a272SMatthew G Knepley 1346e25a272SMatthew G Knepleydef plotEventTime(library, num, eventNames, sizes, times, events, filename = None): 1356e25a272SMatthew G Knepley from pylab import close, legend, plot, savefig, show, title, xlabel, ylabel 1366e25a272SMatthew G Knepley import numpy as np 1376e25a272SMatthew G Knepley 1386e25a272SMatthew G Knepley close() 1396e25a272SMatthew G Knepley arches = sizes.keys() 1406e25a272SMatthew G Knepley bs = events[arches[0]].keys()[0] 1416e25a272SMatthew G Knepley data = [] 1426e25a272SMatthew G Knepley names = [] 1436e25a272SMatthew G Knepley for event, color in zip(eventNames, ['b', 'g', 'r', 'y']): 1446e25a272SMatthew G Knepley for arch, style in zip(arches, ['-', ':']): 1456e25a272SMatthew G Knepley if event in events[arch][bs]: 1466e25a272SMatthew G Knepley names.append(arch+'-'+str(bs)+' '+event) 1476e25a272SMatthew G Knepley data.append(sizes[arch][bs]) 1486e25a272SMatthew G Knepley data.append(np.array(events[arch][bs][event])[:,0]) 1496e25a272SMatthew G Knepley data.append(color+style) 1506e25a272SMatthew G Knepley else: 1516e25a272SMatthew G Knepley print 'Could not find %s in %s-%d events' % (event, arch, bs) 1526e25a272SMatthew G Knepley print data 1536e25a272SMatthew G Knepley plot(*data) 1546e25a272SMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 1556e25a272SMatthew G Knepley xlabel('Number of Dof') 1566e25a272SMatthew G Knepley ylabel('Time (s)') 1576e25a272SMatthew G Knepley legend(names, 'upper left', shadow = True) 1586e25a272SMatthew G Knepley if filename is None: 1596e25a272SMatthew G Knepley show() 1606e25a272SMatthew G Knepley else: 1616e25a272SMatthew G Knepley savefig(filename) 1626e25a272SMatthew G Knepley return 1636e25a272SMatthew G Knepley 1646e25a272SMatthew G Knepleydef plotEventFlop(library, num, eventNames, sizes, times, events, filename = None): 1656e25a272SMatthew G Knepley from pylab import legend, plot, savefig, semilogy, show, title, xlabel, ylabel 1666e25a272SMatthew G Knepley import numpy as np 1676e25a272SMatthew G Knepley 1686e25a272SMatthew G Knepley arches = sizes.keys() 1696e25a272SMatthew G Knepley bs = events[arches[0]].keys()[0] 1706e25a272SMatthew G Knepley data = [] 1716e25a272SMatthew G Knepley names = [] 1726e25a272SMatthew G Knepley for event, color in zip(eventNames, ['b', 'g', 'r', 'y']): 1736e25a272SMatthew G Knepley for arch, style in zip(arches, ['-', ':']): 1746e25a272SMatthew G Knepley if event in events[arch][bs]: 1756e25a272SMatthew G Knepley names.append(arch+'-'+str(bs)+' '+event) 1766e25a272SMatthew G Knepley data.append(sizes[arch][bs]) 1776e25a272SMatthew G Knepley data.append(1e-3*np.array(events[arch][bs][event])[:,1]) 1786e25a272SMatthew G Knepley data.append(color+style) 1796e25a272SMatthew G Knepley else: 1806e25a272SMatthew G Knepley print 'Could not find %s in %s-%d events' % (event, arch, bs) 1816e25a272SMatthew G Knepley semilogy(*data) 1826e25a272SMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 1836e25a272SMatthew G Knepley xlabel('Number of Dof') 1846e25a272SMatthew G Knepley ylabel('Computation Rate (GF/s)') 1856e25a272SMatthew G Knepley legend(names, 'upper left', shadow = True) 1866e25a272SMatthew G Knepley if filename is None: 1876e25a272SMatthew G Knepley show() 1886e25a272SMatthew G Knepley else: 1896e25a272SMatthew G Knepley savefig(filename) 1906e25a272SMatthew G Knepley return 1916e25a272SMatthew G Knepley 192*929aa6beSMatthew G. Knepleydef plotEventScaling(library, num, eventNames, procs, events, filename = None): 193*929aa6beSMatthew G. Knepley from pylab import legend, plot, savefig, semilogy, show, title, xlabel, ylabel 194*929aa6beSMatthew G. Knepley import numpy as np 195*929aa6beSMatthew G. Knepley 196*929aa6beSMatthew G. Knepley arches = procs.keys() 197*929aa6beSMatthew G. Knepley bs = events[arches[0]].keys()[0] 198*929aa6beSMatthew G. Knepley data = [] 199*929aa6beSMatthew G. Knepley names = [] 200*929aa6beSMatthew G. Knepley for arch, style in zip(arches, ['-', ':']): 201*929aa6beSMatthew G. Knepley for event, color in zip(eventNames, ['b', 'g', 'r', 'y']): 202*929aa6beSMatthew G. Knepley if event in events[arch][bs]: 203*929aa6beSMatthew G. Knepley names.append(arch+'-'+str(bs)+' '+event) 204*929aa6beSMatthew G. Knepley data.append(procs[arch][bs]) 205*929aa6beSMatthew G. Knepley data.append(1e-3*np.array(events[arch][bs][event])[:,1]) 206*929aa6beSMatthew G. Knepley data.append(color+style) 207*929aa6beSMatthew G. Knepley else: 208*929aa6beSMatthew G. Knepley print 'Could not find %s in %s-%d events' % (event, arch, bs) 209*929aa6beSMatthew G. Knepley plot(*data) 210*929aa6beSMatthew G. Knepley title('Performance on '+library+' Example '+str(num)) 211*929aa6beSMatthew G. Knepley xlabel('Number of Processors') 212*929aa6beSMatthew G. Knepley ylabel('Computation Rate (GF/s)') 213*929aa6beSMatthew G. Knepley legend(names, 'upper left', shadow = True) 214*929aa6beSMatthew G. Knepley if filename is None: 215*929aa6beSMatthew G. Knepley show() 216*929aa6beSMatthew G. Knepley else: 217*929aa6beSMatthew G. Knepley savefig(filename) 218*929aa6beSMatthew G. Knepley return 219*929aa6beSMatthew G. Knepley 220303b7b21SMatthew G Knepleydef plotSummaryLine(library, num, eventNames, sizes, times, events): 2213428b40fSMatthew G Knepley from pylab import legend, plot, show, title, xlabel, ylabel 2223428b40fSMatthew G Knepley import numpy as np 2233428b40fSMatthew G Knepley showTime = False 2243428b40fSMatthew G Knepley showEventTime = True 2253428b40fSMatthew G Knepley showEventFlops = True 2263428b40fSMatthew G Knepley arches = sizes.keys() 2273428b40fSMatthew G Knepley # Time 2283428b40fSMatthew G Knepley if showTime: 2293428b40fSMatthew G Knepley data = [] 2303428b40fSMatthew G Knepley for arch in arches: 2313428b40fSMatthew G Knepley data.append(sizes[arch]) 2323428b40fSMatthew G Knepley data.append(times[arch]) 2333428b40fSMatthew G Knepley plot(*data) 2343428b40fSMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 2353428b40fSMatthew G Knepley xlabel('Number of Dof') 2363428b40fSMatthew G Knepley ylabel('Time (s)') 2373428b40fSMatthew G Knepley legend(arches, 'upper left', shadow = True) 2383428b40fSMatthew G Knepley show() 2393428b40fSMatthew G Knepley # Common event time 2403428b40fSMatthew G Knepley # We could make a stacked plot like Rio uses here 2413428b40fSMatthew G Knepley if showEventTime: 242df494a56SMatthew G Knepley bs = events[arches[0]].keys()[0] 2433428b40fSMatthew G Knepley data = [] 2443428b40fSMatthew G Knepley names = [] 245df494a56SMatthew G Knepley for event, color in zip(eventNames, ['b', 'g', 'r', 'y']): 2463428b40fSMatthew G Knepley for arch, style in zip(arches, ['-', ':']): 247df494a56SMatthew G Knepley if event in events[arch][bs]: 248df494a56SMatthew G Knepley names.append(arch+'-'+str(bs)+' '+event) 249df494a56SMatthew G Knepley data.append(sizes[arch][bs]) 250df494a56SMatthew G Knepley data.append(np.array(events[arch][bs][event])[:,0]) 2513428b40fSMatthew G Knepley data.append(color+style) 252df494a56SMatthew G Knepley else: 253df494a56SMatthew G Knepley print 'Could not find %s in %s-%d events' % (event, arch, bs) 254df494a56SMatthew G Knepley print data 2553428b40fSMatthew G Knepley plot(*data) 2563428b40fSMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 2573428b40fSMatthew G Knepley xlabel('Number of Dof') 2583428b40fSMatthew G Knepley ylabel('Time (s)') 2593428b40fSMatthew G Knepley legend(names, 'upper left', shadow = True) 2603428b40fSMatthew G Knepley show() 2613428b40fSMatthew G Knepley # Common event flops 2623428b40fSMatthew G Knepley # We could make a stacked plot like Rio uses here 2633428b40fSMatthew G Knepley if showEventFlops: 264df494a56SMatthew G Knepley bs = events[arches[0]].keys()[0] 2653428b40fSMatthew G Knepley data = [] 2663428b40fSMatthew G Knepley names = [] 267df494a56SMatthew G Knepley for event, color in zip(eventNames, ['b', 'g', 'r', 'y']): 2683428b40fSMatthew G Knepley for arch, style in zip(arches, ['-', ':']): 269df494a56SMatthew G Knepley if event in events[arch][bs]: 270df494a56SMatthew G Knepley names.append(arch+'-'+str(bs)+' '+event) 271df494a56SMatthew G Knepley data.append(sizes[arch][bs]) 272df494a56SMatthew G Knepley data.append(np.array(events[arch][bs][event])[:,1]) 2733428b40fSMatthew G Knepley data.append(color+style) 274df494a56SMatthew G Knepley else: 275df494a56SMatthew G Knepley print 'Could not find %s in %s-%d events' % (event, arch, bs) 2763428b40fSMatthew G Knepley plot(*data) 2773428b40fSMatthew G Knepley title('Performance on '+library+' Example '+str(num)) 2783428b40fSMatthew G Knepley xlabel('Number of Dof') 2793428b40fSMatthew G Knepley ylabel('Computation Rate (MF/s)') 2803428b40fSMatthew G Knepley legend(names, 'upper left', shadow = True) 2813428b40fSMatthew G Knepley show() 2823428b40fSMatthew G Knepley return 2833428b40fSMatthew G Knepley 284303b7b21SMatthew G Knepleydef plotSummaryBar(library, num, eventNames, sizes, times, events): 285e3da8a91SMatthew G Knepley import numpy as np 286e3da8a91SMatthew G Knepley import matplotlib.pyplot as plt 287e3da8a91SMatthew G Knepley 288303b7b21SMatthew G Knepley eventColors = ['b', 'g', 'r', 'y'] 289e3da8a91SMatthew G Knepley arches = sizes.keys() 290e3da8a91SMatthew G Knepley names = [] 291e3da8a91SMatthew G Knepley N = len(sizes[arches[0]]) 292e3da8a91SMatthew G Knepley width = 0.2 293e3da8a91SMatthew G Knepley ind = np.arange(N) - 0.25 294e3da8a91SMatthew G Knepley bars = {} 295e3da8a91SMatthew G Knepley for arch in arches: 296e3da8a91SMatthew G Knepley bars[arch] = [] 297e3da8a91SMatthew G Knepley bottom = np.zeros(N) 298e3da8a91SMatthew G Knepley for event, color in zip(eventNames, eventColors): 299e3da8a91SMatthew G Knepley names.append(arch+' '+event) 300e3da8a91SMatthew G Knepley times = np.array(events[arch][event])[:,0] 301e3da8a91SMatthew G Knepley bars[arch].append(plt.bar(ind, times, width, color=color, bottom=bottom)) 302e3da8a91SMatthew G Knepley bottom += times 303e3da8a91SMatthew G Knepley ind += 0.3 304e3da8a91SMatthew G Knepley 305e3da8a91SMatthew G Knepley plt.xlabel('Number of Dof') 306e3da8a91SMatthew G Knepley plt.ylabel('Time (s)') 307e3da8a91SMatthew G Knepley plt.title('GPU vs. CPU Performance on '+library+' Example '+str(num)) 308e3da8a91SMatthew G Knepley plt.xticks(np.arange(N), map(str, sizes[arches[0]])) 309e3da8a91SMatthew G Knepley #plt.yticks(np.arange(0,81,10)) 310e3da8a91SMatthew G Knepley #plt.legend( (p1[0], p2[0]), ('Men', 'Women') ) 311e3da8a91SMatthew G Knepley plt.legend([bar[0] for bar in bars[arches[0]]], eventNames, 'upper right', shadow = True) 312e3da8a91SMatthew G Knepley 313e3da8a91SMatthew G Knepley plt.show() 314e3da8a91SMatthew G Knepley return 315e3da8a91SMatthew G Knepley 316df494a56SMatthew G Knepleydef getDMComplexSize(dim, out): 317683aebbfSMatthew G Knepley '''Retrieves the number of cells from ''' 318683aebbfSMatthew G Knepley size = 0 319683aebbfSMatthew G Knepley for line in out.split('\n'): 320683aebbfSMatthew G Knepley if line.strip().startswith(str(dim)+'-cells: '): 321683aebbfSMatthew G Knepley size = int(line.strip()[9:]) 322683aebbfSMatthew G Knepley break 323683aebbfSMatthew G Knepley return size 324683aebbfSMatthew G Knepley 325d006b754SMatthew G Knepleydef run_DMDA(ex, name, opts, args, sizes, times, events, log=True): 326683aebbfSMatthew G Knepley for n in map(int, args.size): 327d006b754SMatthew G Knepley ex.run(log=log, da_grid_x=n, da_grid_y=n, **opts) 328683aebbfSMatthew G Knepley sizes[name].append(n*n * args.comp) 329683aebbfSMatthew G Knepley processSummary('summary', args.stage, args.events, times[name], events[name]) 330683aebbfSMatthew G Knepley return 331683aebbfSMatthew G Knepley 332d006b754SMatthew G Knepleydef run_DMComplex(ex, name, opts, args, sizes, times, events, log=True): 333683aebbfSMatthew G Knepley # This should eventually be replaced by a direct FFC/Ignition interface 334683aebbfSMatthew G Knepley if args.operator == 'laplacian': 335683aebbfSMatthew G Knepley numComp = 1 336683aebbfSMatthew G Knepley elif args.operator == 'elasticity': 337683aebbfSMatthew G Knepley numComp = args.dim 338683aebbfSMatthew G Knepley else: 339683aebbfSMatthew G Knepley raise RuntimeError('Unknown operator: %s' % args.operator) 340683aebbfSMatthew G Knepley 341683aebbfSMatthew G Knepley for numBlock in [2**i for i in map(int, args.blockExp)]: 342683aebbfSMatthew G Knepley opts['gpu_blocks'] = numBlock 343683aebbfSMatthew G Knepley # Generate new block size 344683aebbfSMatthew G Knepley cmd = './bin/pythonscripts/PetscGenerateFEMQuadrature.py %d %d %d %d %s %s.h' % (args.dim, args.order, numComp, numBlock, args.operator, os.path.splitext(source[0])[0]) 345683aebbfSMatthew G Knepley print(cmd) 346683aebbfSMatthew G Knepley ret = os.system('python '+cmd) 347683aebbfSMatthew G Knepley args.files = ['['+','.join(source)+']'] 348683aebbfSMatthew G Knepley buildExample(args) 349683aebbfSMatthew G Knepley sizes[name][numBlock] = [] 350683aebbfSMatthew G Knepley times[name][numBlock] = [] 351683aebbfSMatthew G Knepley events[name][numBlock] = {} 352683aebbfSMatthew G Knepley for r in map(float, args.refine): 353d006b754SMatthew G Knepley out = ex.run(log=log, refinement_limit=r, **opts) 354df494a56SMatthew G Knepley sizes[name][numBlock].append(getDMComplexSize(args.dim, out)) 355683aebbfSMatthew G Knepley processSummary('summary', args.stage, args.events, times[name][numBlock], events[name][numBlock]) 356683aebbfSMatthew G Knepley return 357683aebbfSMatthew G Knepley 358d006b754SMatthew G Knepleydef outputData(sizes, times, events, name = 'output.py'): 359d006b754SMatthew G Knepley if os.path.exists(name): 360d006b754SMatthew G Knepley base, ext = os.path.splitext(name) 361d006b754SMatthew G Knepley num = 1 362d006b754SMatthew G Knepley while os.path.exists(base+str(num)+ext): 363d006b754SMatthew G Knepley num += 1 364d006b754SMatthew G Knepley name = base+str(num)+ext 365d006b754SMatthew G Knepley with file(name, 'w') as f: 366d006b754SMatthew G Knepley f.write('#PETSC_ARCH='+os.environ['PETSC_ARCH']+' '+' '.join(sys.argv)+'\n') 367d006b754SMatthew G Knepley f.write('sizes = '+repr(sizes)+'\n') 368d006b754SMatthew G Knepley f.write('times = '+repr(times)+'\n') 369d006b754SMatthew G Knepley f.write('events = '+repr(events)+'\n') 370d006b754SMatthew G Knepley return 371d006b754SMatthew G Knepley 3723428b40fSMatthew G Knepleyif __name__ == '__main__': 373eda8839fSMatthew G Knepley import argparse 374eda8839fSMatthew G Knepley 375eda8839fSMatthew G Knepley parser = argparse.ArgumentParser(description = 'PETSc Benchmarking', 376eda8839fSMatthew G Knepley epilog = 'This script runs src/<library>/examples/tutorials/ex<num>, For more information, visit http://www.mcs.anl.gov/petsc', 377eda8839fSMatthew G Knepley formatter_class = argparse.ArgumentDefaultsHelpFormatter) 378eda8839fSMatthew G Knepley parser.add_argument('--library', default='SNES', help='The PETSc library used in this example') 379eda8839fSMatthew G Knepley parser.add_argument('--num', type = int, default='5', help='The example number') 380eda8839fSMatthew G Knepley parser.add_argument('--module', default='summary', help='The module for timing output') 381eda8839fSMatthew G Knepley parser.add_argument('--stage', default='Main_Stage', help='The default logging stage') 382eda8839fSMatthew G Knepley parser.add_argument('--events', nargs='+', help='Events to process') 383eda8839fSMatthew G Knepley parser.add_argument('--batch', action='store_true', default=False, help='Generate batch files for the runs instead') 384d006b754SMatthew G Knepley parser.add_argument('--daemon', action='store_true', default=False, help='Run as a daemon') 385683aebbfSMatthew G Knepley subparsers = parser.add_subparsers(help='DM types') 386eda8839fSMatthew G Knepley 387683aebbfSMatthew G Knepley parser_dmda = subparsers.add_parser('DMDA', help='Use a DMDA for the problem geometry') 388683aebbfSMatthew G Knepley parser_dmda.add_argument('--size', nargs='+', default=['10'], help='Grid size (implementation dependent)') 389683aebbfSMatthew G Knepley parser_dmda.add_argument('--comp', type = int, default='1', help='Number of field components') 390683aebbfSMatthew G Knepley parser_dmda.add_argument('runs', nargs='*', help='Run descriptions: <name>=<args>') 391683aebbfSMatthew G Knepley 392df494a56SMatthew G Knepley parser_dmmesh = subparsers.add_parser('DMComplex', help='Use a DMComplex for the problem geometry') 393683aebbfSMatthew G Knepley parser_dmmesh.add_argument('--dim', type = int, default='2', help='Spatial dimension') 394683aebbfSMatthew G Knepley parser_dmmesh.add_argument('--refine', nargs='+', default=['0.0'], help='List of refinement limits') 395683aebbfSMatthew G Knepley parser_dmmesh.add_argument('--order', type = int, default='1', help='Order of the finite element') 396683aebbfSMatthew G Knepley parser_dmmesh.add_argument('--operator', default='laplacian', help='The operator name') 397683aebbfSMatthew G Knepley parser_dmmesh.add_argument('--blockExp', nargs='+', default=range(0, 5), help='List of block exponents j, block size is 2^j') 398683aebbfSMatthew G Knepley parser_dmmesh.add_argument('runs', nargs='*', help='Run descriptions: <name>=<args>') 399eda8839fSMatthew G Knepley 400eda8839fSMatthew G Knepley args = parser.parse_args() 401eda8839fSMatthew G Knepley print(args) 402683aebbfSMatthew G Knepley if hasattr(args, 'comp'): 403683aebbfSMatthew G Knepley args.dmType = 'DMDA' 404683aebbfSMatthew G Knepley else: 405df494a56SMatthew G Knepley args.dmType = 'DMComplex' 406683aebbfSMatthew G Knepley 407eda8839fSMatthew G Knepley ex = PETScExample(args.library, args.num, log_summary='summary.dat', log_summary_python = None if args.batch else args.module+'.py', preload='off') 408683aebbfSMatthew G Knepley source = ex.petsc.source(args.library, args.num) 4093428b40fSMatthew G Knepley sizes = {} 4103428b40fSMatthew G Knepley times = {} 4113428b40fSMatthew G Knepley events = {} 412d006b754SMatthew G Knepley log = not args.daemon 413d006b754SMatthew G Knepley 414d006b754SMatthew G Knepley if args.daemon: 415d006b754SMatthew G Knepley import daemon 416d006b754SMatthew G Knepley print 'Starting daemon' 417d006b754SMatthew G Knepley daemon.createDaemon('.') 418683aebbfSMatthew G Knepley 419eda8839fSMatthew G Knepley for run in args.runs: 420eda8839fSMatthew G Knepley name, stropts = run.split('=', 1) 421eda8839fSMatthew G Knepley opts = dict([t if len(t) == 2 else (t[0], None) for t in [arg.split('=', 1) for arg in stropts.split(' ')]]) 422683aebbfSMatthew G Knepley if args.dmType == 'DMDA': 4233428b40fSMatthew G Knepley sizes[name] = [] 4243428b40fSMatthew G Knepley times[name] = [] 4253428b40fSMatthew G Knepley events[name] = {} 426d006b754SMatthew G Knepley run_DMDA(ex, name, opts, args, sizes, times, events, log=log) 427df494a56SMatthew G Knepley elif args.dmType == 'DMComplex': 428683aebbfSMatthew G Knepley sizes[name] = {} 429683aebbfSMatthew G Knepley times[name] = {} 430683aebbfSMatthew G Knepley events[name] = {} 431d006b754SMatthew G Knepley run_DMComplex(ex, name, opts, args, sizes, times, events, log=log) 432d006b754SMatthew G Knepley outputData(sizes, times, events) 433d006b754SMatthew G Knepley if not args.batch and log: plotSummaryLine(args.library, args.num, args.events, sizes, times, events) 434683aebbfSMatthew G Knepley# Benchmark for ex50 435683aebbfSMatthew G Knepley# ./src/benchmarks/benchmarkExample.py --events VecMDot VecMAXPY KSPGMRESOrthog MatMult VecCUSPCopyTo VecCUSPCopyFrom MatCUSPCopyTo --num 50 DMDA --size 10 20 50 100 --comp 4 CPU='pc_type=none mat_no_inode dm_vec_type=seq dm_mat_type=seqaij' GPU='pc_type=none mat_no_inode dm_vec_type=seqcusp dm_mat_type=seqaijcusp cusp_synchronize' 436683aebbfSMatthew G Knepley# Benchmark for ex52 437fd49fd63SMatthew G Knepley# ./src/benchmarks/benchmarkExample.py --events IntegBatchCPU IntegBatchGPU IntegGPUOnly --num 52 DMComplex --refine 0.0625 0.00625 0.000625 0.0000625 --blockExp 4 --order=1 CPU='dm_view show_residual=0 compute_function batch' GPU='dm_view show_residual=0 compute_function batch gpu gpu_batches=8' 438fd49fd63SMatthew G Knepley# ./src/benchmarks/benchmarkExample.py --events IntegBatchCPU IntegBatchGPU IntegGPUOnly --num 52 DMComplex --refine 0.0625 0.00625 0.000625 0.0000625 --blockExp 4 --order=1 --operator=elasticity CPU='dm_view op_type=elasticity show_residual=0 compute_function batch' GPU='dm_view op_type=elasticity show_residual=0 compute_function batch gpu gpu_batches=8' 439fd49fd63SMatthew G Knepley# ./src/benchmarks/benchmarkExample.py --events IntegBatchCPU IntegBatchGPU IntegGPUOnly --num 52 DMComplex --dim=3 --refine 0.0625 0.00625 0.000625 0.0000625 --blockExp 4 --order=1 CPU='dim=3 dm_view show_residual=0 compute_function batch' GPU='dim=3 dm_view show_residual=0 compute_function batch gpu gpu_batches=8' 440