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