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