1#!/usr/bin/env python 2 3from __future__ import print_function 4Sorted = ["PetscBarrier", 5 6 "ThreadCommRunKer", 7 "ThreadCommBarrie", 8 9 "TSSetUp", 10 "TSStep", 11 "TSFunctionEval", 12 "TSJacobianEval", 13 14 "SNESSolve", 15 "SNESFunctionEval", 16 "SNESJacobianEval", 17 "MatFDColorCreate", 18 "MatFDColorSetUp", 19 "MatFDColorApply", 20 "MatFDColorFunc", 21 "MatAssemblyBegin", 22 "MatAssemblyEnd", 23 24 "SNESNGSEval", 25 "SNESNGSFuncEval", 26 "SNESLineSearch", 27 "SNESNPCSolve", 28 29 "KSPSetUp", 30 "PCSetUp", 31 "MatLUFactor", 32 "MatLUFactorSym", 33 "MatLUFactorNum", 34 "MatCholeskyFctr", 35 "MatCholFctrSym", 36 "MatCholFctrNum", 37 "MatILUFactor", 38 "MatILUFactorSym", 39 "MatICCFactorSym", 40 41 "KSPSolve", 42 "MatMult", 43 "MatMult MF", 44 "KSPGMRESOrthog", 45 "VecMDot", 46 "VecMAXPY", 47 "VecNormalize", 48 49 "PCSetUpOnBlocks", 50 "PCApplyOnBlocks", 51 "PCApply", 52 "MatSolve", 53 "MatSOR", 54 55 "PCApplyCoarse", 56 "PCApplyMultiple", 57 "PCApplySymmLeft", 58 "PCApplySymmRight", 59 "", 60 "PCModifySubMatri", 61 62 "PCGAMGGraph_AGG", 63 "PCGAMGGraph_GEO", 64 "PCGAMGCoarse_AGG", 65 "PCGAMGCoarse_GEO", 66 "PCGAMGProl_AGG", 67 "PCGAMGProl_GEO", 68 "PCGAMGPOpt_AGG", 69 70 71 "DMConvert", 72 "DMGlobalToLocal", 73 "DMLocalToGlobal", 74 "DMDALocalADFunc", 75 "DMPlexInterpolate", 76 "DMPlexPartition", 77 "DMPlexDistribute", 78 "DMPlexDistCones", 79 "DMPlexDistLabels", 80 "DMPlexDistSF", 81 "DMPlexDistOvrlp", 82 "DMPlexDistField", 83 "DMPlexDistData", 84 "DMPlexStratify", 85 "DMPlexPreallocate", 86 "DMPlexResidualFEM", 87 "DMPlexJacobianFEM", 88 89 90 "MatMults", 91 "MatMultConstr", 92 "MatMultAdd", 93 "MatMultTranspose", 94 "MatMultTrConstr", 95 "MatMultTrAdd", 96 "MatSolves", 97 "MatSolveAdd", 98 "MatSolveTranspos", 99 "MatSolveTrAdd", 100 "MatForwardSolve", 101 "MatBackwardSolve", 102 "MatCopy", 103 "MatConvert", 104 "MatScale", 105 "MatResidual", 106 "MatSetValues", 107 "MatGetValues", 108 "MatGetRow", 109 "MatGetRowIJ", 110 "MatGetSubMatrice", 111 "MatGetOrdering", 112 "MatIncreaseOvrlp", 113 "MatPartitioning", 114 "MatCoarsen", 115 "MatZeroEntries", 116 "MatLoad", 117 "MatView", 118 "MatAXPY", 119 120 "MatTranspose", 121 "MatMatMult", 122 "MatMatSolve", 123 "MatMatMultSym", 124 "MatMatMultNum", 125 "MatMatMatMult", 126 "MatMatMatMultSym", 127 "MatMatMatMultNum", 128 "MatPtAP", 129 "MatPtAPSymbolic", 130 "MatPtAPNumeric", 131 "MatRARt", 132 "MatRARtSym", 133 "MatRARtNum", 134 "MatMatTransMult", 135 "MatMatTrnMultSym", 136 "MatMatTrnMultNum", 137 "MatTrnMatMult", 138 "MatTrnMatMultSym", 139 "MatTrnMatMultNum", 140 "MatTrnColorCreate", 141 "MatGetRedundant", 142 "MatGetSeqNZStrct", 143 "MatGetMultiProcBlock", 144 "MatMPISumSeqNumeric", 145 "MatMPISumSeqSymbolic", 146 "MatMPISumSeq", 147 "MatMPIConcateSeq", 148 "MatGetLocalMat", 149 "MatGetLocalMatCondensed", 150 "MatGetBrowsOfAcols", 151 "MatGetBrAoCol", 152 "MatApplyPAPt_Symbolic", 153 "MatApplyPAPt_Numeric", 154 "MatApplyPAPt", 155 "MatGetSymTrans", 156 "MatGetSymTransR", 157 "MatTranspose_SeqAIJ_FAST", 158 "MatCUSPARSECopyTo", 159 "MatViennaCLCopyTo", 160 "MatSetValBatch", 161 "MatSetValBatch1", 162 "MatSetValBatch2", 163 "MatSetValBatch3", 164 "MatSetValBatch4", 165 "MatColoringApply", 166 "MatColoringComm", 167 "MatColoringLocal", 168 "MatColoringIS", 169 "MatColoringSetUp", 170 171 "VecView", 172 "VecMax", 173 "VecMin", 174 "VecDot", 175 "VecDotNorm2", 176 "VecTDot", 177 "VecMTDot", 178 "VecNorm", 179 "VecScale", 180 "VecCopy", 181 "VecSet", 182 "VecAXPY", 183 "VecAYPX", 184 "VecAXPBYCZ", 185 "VecWAXPY", 186 "VecSwap", 187 "VecOps", 188 "VecAssemblyBegin", 189 "VecAssemblyEnd", 190 "VecPointwiseMult", 191 "VecSetValues", 192 "VecLoad", 193 "VecScatterBegin", 194 "VecScatterEnd", 195 "VecSetRandom", 196 "VecReduceArith", 197 "VecReduceComm", 198 "VecReduceBegin", 199 "VecReduceEnd", 200 201 202 "PetscSFSetGraph", 203 "PetscSFBcastBegin", 204 "PetscSFBcastEnd", 205 "PetscSFReduceBegin", 206 "PetscSFReduceEnd", 207 "PetscSFFetchOpBegin", 208 "PetscSFFetchOpEnd"] 209 210 211def ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions): 212 '''Computes time spent by all processes''' 213 time = 0 214 flops = 0 215 for t in localTimes: 216 time += localTimes[t] 217 flops = 0 218 for t in localFlops: 219 flops += localFlops[t] 220 messages = 0 221 for t in localMessages: 222 messages += localMessages[t] 223 messagelens = 0 224 for t in localMessageLens: 225 messagelens += localMessageLens[t] 226 reductions = 0 227 for t in localReductions: 228 reductions += localReductions[t] 229 return time,flops,messages,messagelens,reductions 230 231def ComputeSums(Stages): 232 ''' Computes the sum over all processes for each event; removes events with zero count and summaries''' 233 sumStages = {} 234 for stages in Stages: 235 sumStages[stages] = {} 236 for events in Stages[stages]: 237 sumStages[stages][events] = {} 238 for t in Stages[stages][events][0]: 239 sumStages[stages][events][t] = 0 240 for s in Stages[stages][events]: 241 sumStages[stages][events][t] += Stages[stages][events][s][t] 242 243 for stages in Stages: 244 for events in Stages[stages]: 245 if events == "summary" or not sumStages[stages][events]["count"] or events.startswith('Thread') or events == 'TSFunctionEval' or events == 'TSJacobianEval': 246 sumStages[stages].pop(events,None) 247 return sumStages 248 249def ObjectsCompare(a,b): 250 return Sorted.index(a) - Sorted.index(b) 251 252def PrintPercentTable(localTimes,localFlops,localMessages,localMessageLens,localReductions,Stages,Latex = False): 253 ''' Prints a simple table that displays the percent of time, flops, etc for each event in each stage''' 254 if Latex: 255 print("\documentclass{article}") 256 print("\\begin{document}") 257 print("\\begin{table}[!htbp]") 258 print("\centering") 259 if len(localTimes) > 1: 260 print("\\begin{tabular}{lcccccc}") 261 print(" & & \multicolumn{4}{c}{--------------- Percent of -------------} & \\\\") 262 print("Event & Count & Time & Flops & Messages & Reductions & Flop rate \\\\") 263 print("\hline") 264 else: 265 if len(localTimes) > 1: 266 print(" --------- Percent of ------") 267 print("Event Count Time Flops Messages Reductions Flop rate") 268 print("============================================================================") 269 else: 270 print(" Percent of") 271 print("Event Count Time Flops Flop rate") 272 print("=========================================================") 273 274 time,flops,numMessages,numMessageLen,numReductions = ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions) 275 if not numMessages: numMessages = 1 276 if not numReductions: numReductions = 1 277 sumStages = ComputeSums(Stages) 278 for stage in sumStages: 279 if len(sumStages) > 1: 280 if Latex: 281 pass 282 else: 283 print("Stage: "+stage) 284 L = sumStages[stage].keys() 285 L.sort(cmp=ObjectsCompare) 286 seperatoradded = False 287 for i in xrange(len(L)): 288 event = L[i] 289 space = 0 290 if event.startswith("SNESSolve"): space = 1 291 elif event.startswith("SNES"): space = 2 292 elif event.startswith("KSPGMRESOrthog"): space = 3 293 elif event.startswith("KSP"): space = 2 294 elif event.startswith("PC"): space = 3 295 elif event.startswith("MatMult"): space = 3 296 elif event.startswith("Mat"): space = 4 297 elif event.startswith("Vec"): space = 5 298 if Sorted.index(event) > Sorted.index("PCGAMGPOpt_AGG"): 299 space = 2 300 if not seperatoradded: 301 if Latex: 302 print("--Overlapping events---\\\\") 303 else: 304 print("--Overlapping events---") 305 seperatoradded = True 306 307 if len(localTimes) > 1: 308 values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops,100*sumStages[stage][event]["numMessages"]/numMessages,100*sumStages[stage][event]["numReductions"]/numReductions] 309 if max(values) > .5: 310 if Latex: 311 print('\\hspace{%1dem}' % space,event,"&",'%6.0f' % sumStages[stage][event]["count"],"&",'%5.0f' % values[0],"&",'%5.0f' % values[1],"&",'%5.0f' % values[2],"&",'%5.0f' % values[3],"&",'%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0),"\\\\") 312 else: 313 print(" "[0:space],event.ljust(26-space),'%6.0f' % sumStages[stage][event]["count"]," ",'%5.0f' % values[0],'%5.0f' % values[1],'%5.0f' % values[2],'%5.0f' % values[3]," ",'%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0)) 314 else: 315 values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops] 316 if max(values) > .5: 317 if Latex: 318 print('\\hspace{%1dem}' % space,event,"&",'%6.0f' % sumStages[stage][event]["count"],"&",'%5.0f' % values[0],"&",'%5.0f' % values[1],"&",'%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0),"\\\\") 319 else: 320 print(" ",event.ljust(24),'%6.0f' % sumStages[stage][event]["count"]," ",'%5.0f' % values[0],'%5.0f' % values[1]," ",'%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0)) 321 322 if Latex: 323 print("\end{tabular}") 324 print("\end{table}") 325 print("\end{document}") 326 327 328 329# def PrintPercentTable_CSV_Compress(localTimes,localFlops,localMessages,localMessageLens,localReductions,Stages,Latex = False): 330# ''' Prints a simple table that displays the percent of time, flops, etc for each event in each stage''' 331# 332# output = io.StringIO() 333# csv_writer = csv.writer(output, quoting=csv.QUOTE_NONNUMERIC) 334# csv_writer.writerow(['Stage','Event','Count','Time','Flops','Messages','Reductions','Flop rate') 335# 336# time,flops,numMessages,numMessageLen,numReductions = ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions) 337# if not numMessages: numMessages = 1 338# if not numReductions: numReductions = 1 339# sumStages = ComputeSums(Stages) 340# for stage in sumStages: 341# L = sumStages[stage].keys() 342# L.sort(cmp=ObjectsCompare) 343# seperatoradded = False 344# for i in xrange(len(L)): 345# event = L[i] 346# space = 0 347# if event.startswith("SNESSolve"): space = 1 348# elif event.startswith("SNES"): space = 2 349# elif event.startswith("KSPGMRESOrthog"): space = 3 350# elif event.startswith("KSP"): space = 2 351# elif event.startswith("PC"): space = 3 352# elif event.startswith("MatMult"): space = 3 353# elif event.startswith("Mat"): space = 4 354# elif event.startswith("Vec"): space = 5 355# if Sorted.index(event) > Sorted.index("PCGAMGPOpt_AGG"): 356# space = 2 357# if not seperatoradded: 358# seperatoradded = True 359# 360# if len(localTimes) > 1: 361# values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops,100*sumStages[stage][event]["numMessages"]/numMessages,100*sumStages[stage][event]["numReductions"]/numReductions] 362# if max(values) > .5: 363# csv_writer.writerow(stage, event, '%6.0f' % sumStages[stage][event]["count"], '%5.0f' % values[0], '%5.0f' % values[1], '%5.0f' % values[2], '%5.0f' % values[3], '%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0)) 364# else: 365# values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops] 366# if max(values) > .5: 367# csv_writer.writerow(stage, event, '%6.0f' % sumStages[stage][event]["count"], '%5.0f' % values[0], '%5.0f' % values[1], , , '%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0)) 368# 369# compress = zlib.compressobj(zlib.Z_DEFAULT_COMPRESSION, zlib.DEFLATED, -15) 370# compressed_data = compress.compress(output.getvalue()) 371# compressed_data += compress.flush() 372# 373# print(compressed_data) 374 375 376if __name__ == '__main__': 377 import sys 378 import os 379 # import io 380 # import csv 381 # import zlib 382 sys.path.append(os.getcwd()) 383 datafile = sys.argv[1] 384 if datafile.endswith('.py'): datafile = datafile[0:-3] 385 exec('import '+datafile+' as data') 386 latex = False 387 if len(sys.argv) > 2: latex = True 388 389 PrintPercentTable(data.LocalTimes,data.LocalFlops,data.LocalMessages,data.LocalMessageLens,data.LocalReductions,data.Stages,Latex = latex) 390