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 "MatCUSPCopyTo", 159 "MatCUSPARSECopyTo", 160 "MatViennaCLCopyTo", 161 "MatSetValBatch", 162 "MatSetValBatch1", 163 "MatSetValBatch2", 164 "MatSetValBatch3", 165 "MatSetValBatch4", 166 "MatColoringApply", 167 "MatColoringComm", 168 "MatColoringLocal", 169 "MatColoringIS", 170 "MatColoringSetUp", 171 172 "VecView", 173 "VecMax", 174 "VecMin", 175 "VecDot", 176 "VecDotNorm2", 177 "VecTDot", 178 "VecMTDot", 179 "VecNorm", 180 "VecScale", 181 "VecCopy", 182 "VecSet", 183 "VecAXPY", 184 "VecAYPX", 185 "VecAXPBYCZ", 186 "VecWAXPY", 187 "VecSwap", 188 "VecOps", 189 "VecAssemblyBegin", 190 "VecAssemblyEnd", 191 "VecPointwiseMult", 192 "VecSetValues", 193 "VecLoad", 194 "VecScatterBegin", 195 "VecScatterEnd", 196 "VecSetRandom", 197 "VecReduceArith", 198 "VecReduceComm", 199 "VecReduceBegin", 200 "VecReduceEnd", 201 202 203 "PetscSFSetGraph", 204 "PetscSFBcastBegin", 205 "PetscSFBcastEnd", 206 "PetscSFReduceBegin", 207 "PetscSFReduceEnd", 208 "PetscSFFetchOpBegin", 209 "PetscSFFetchOpEnd"] 210 211 212def ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions): 213 '''Computes time spent by all processes''' 214 time = 0 215 flops = 0 216 for t in localTimes: 217 time += localTimes[t] 218 flops = 0 219 for t in localFlops: 220 flops += localFlops[t] 221 messages = 0 222 for t in localMessages: 223 messages += localMessages[t] 224 messagelens = 0 225 for t in localMessageLens: 226 messagelens += localMessageLens[t] 227 reductions = 0 228 for t in localReductions: 229 reductions += localReductions[t] 230 return time,flops,messages,messagelens,reductions 231 232def ComputeSums(Stages): 233 ''' Computes the sum over all processes for each event; removes events with zero count and summaries''' 234 sumStages = {} 235 for stages in Stages: 236 sumStages[stages] = {} 237 for events in Stages[stages]: 238 sumStages[stages][events] = {} 239 for t in Stages[stages][events][0]: 240 sumStages[stages][events][t] = 0 241 for s in Stages[stages][events]: 242 sumStages[stages][events][t] += Stages[stages][events][s][t] 243 244 for stages in Stages: 245 for events in Stages[stages]: 246 if events == "summary" or not sumStages[stages][events]["count"] or events.startswith('Thread') or events == 'TSFunctionEval' or events == 'TSJacobianEval': 247 sumStages[stages].pop(events,None) 248 return sumStages 249 250def ObjectsCompare(a,b): 251 return Sorted.index(a) - Sorted.index(b) 252 253def PrintPercentTable(localTimes,localFlops,localMessages,localMessageLens,localReductions,Stages,Latex = False): 254 ''' Prints a simple table that displays the percent of time, flops, etc for each event in each stage''' 255 if Latex: 256 print("\documentclass{article}") 257 print("\\begin{document}") 258 print("\\begin{table}[!htbp]") 259 print("\centering") 260 if len(localTimes) > 1: 261 print("\\begin{tabular}{lcccccc}") 262 print(" & & \multicolumn{4}{c}{--------------- Percent of -------------} & \\\\") 263 print("Event & Count & Time & Flops & Messages & Reductions & Flop rate \\\\") 264 print("\hline") 265 else: 266 if len(localTimes) > 1: 267 print(" --------- Percent of ------") 268 print("Event Count Time Flops Messages Reductions Flop rate") 269 print("============================================================================") 270 else: 271 print(" Percent of") 272 print("Event Count Time Flops Flop rate") 273 print("=========================================================") 274 275 time,flops,numMessages,numMessageLen,numReductions = ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions) 276 if not numMessages: numMessages = 1 277 if not numReductions: numReductions = 1 278 sumStages = ComputeSums(Stages) 279 for stage in sumStages: 280 if len(sumStages) > 1: 281 if Latex: 282 pass 283 else: 284 print("Stage: "+stage) 285 L = sumStages[stage].keys() 286 L.sort(cmp=ObjectsCompare) 287 seperatoradded = False 288 for i in xrange(len(L)): 289 event = L[i] 290 space = 0 291 if event.startswith("SNESSolve"): space = 1 292 elif event.startswith("SNES"): space = 2 293 elif event.startswith("KSPGMRESOrthog"): space = 3 294 elif event.startswith("KSP"): space = 2 295 elif event.startswith("PC"): space = 3 296 elif event.startswith("MatMult"): space = 3 297 elif event.startswith("Mat"): space = 4 298 elif event.startswith("Vec"): space = 5 299 if Sorted.index(event) > Sorted.index("PCGAMGPOpt_AGG"): 300 space = 2 301 if not seperatoradded: 302 if Latex: 303 print("--Overlapping events---\\\\") 304 else: 305 print("--Overlapping events---") 306 seperatoradded = True 307 308 if len(localTimes) > 1: 309 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] 310 if max(values) > .5: 311 if Latex: 312 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),"\\\\") 313 else: 314 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)) 315 else: 316 values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops] 317 if max(values) > .5: 318 if Latex: 319 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),"\\\\") 320 else: 321 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)) 322 323 if Latex: 324 print("\end{tabular}") 325 print("\end{table}") 326 print("\end{document}") 327 328if __name__ == '__main__': 329 import sys 330 import os 331 sys.path.append(os.getcwd()) 332 datafile = sys.argv[1] 333 if datafile.endswith('.py'): datafile = datafile[0:-3] 334 exec('import '+datafile+' as data') 335 latex = False 336 if len(sys.argv) > 2: latex = True 337 338 PrintPercentTable(data.LocalTimes,data.LocalFlops,data.LocalMessages,data.LocalMessageLens,data.LocalReductions,data.Stages,Latex = latex) 339