xref: /petsc/lib/petsc/bin/petsclogformat.py (revision f04eb4ed2b5986080c6ede07d79a31d99dfbe477)
1#!/usr/bin/env python
2
3Sorted = ["PetscBarrier",
4
5         "ThreadCommRunKer",
6         "ThreadCommBarrie",
7
8         "TSSetUp",
9         "TSStep",
10         "TSFunctionEval",
11         "TSJacobianEval",
12
13         "SNESSolve",
14         "SNESFunctionEval",
15         "SNESJacobianEval",
16         "MatFDColorCreate",
17         "MatFDColorSetUp",
18         "MatFDColorApply",
19         "MatFDColorFunc",
20         "MatAssemblyBegin",
21         "MatAssemblyEnd",
22
23         "SNESNGSEval",
24         "SNESNGSFuncEval",
25         "SNESLineSearch",
26         "SNESNPCSolve",
27
28         "KSPSetUp",
29         "PCSetUp",
30         "MatLUFactor",
31         "MatLUFactorSym",
32         "MatLUFactorNum",
33         "MatCholeskyFctr",
34         "MatCholFctrSym",
35         "MatCholFctrNum",
36         "MatILUFactor",
37         "MatILUFactorSym",
38         "MatICCFactorSym",
39
40         "KSPSolve",
41         "MatMult",
42         "MatMult MF",
43         "KSPGMRESOrthog",
44         "VecMDot",
45         "VecMAXPY",
46         "VecNormalize",
47
48         "PCSetUpOnBlocks",
49         "PCApplyOnBlocks",
50         "PCApply",
51         "MatSolve",
52         "MatSOR",
53
54         "PCApplyCoarse",
55         "PCApplyMultiple",
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         "DMPlexDistribCones",
78         "DMPlexDistribLabels",
79         "DMPlexDistribSF",
80         "DMPlexDistribField",
81         "DMPlexDistribData",
82         "DMPlexStratify",
83         "DMPlexPreallocate",
84         "DMPlexResidualFEM",
85         "DMPlexJacobianFEM",
86
87
88         "MatMults",
89         "MatMultConstr",
90         "MatMultAdd",
91         "MatMultTranspose",
92         "MatMultTrConstr",
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         "MatCUSPCopyTo",
157         "MatCUSPARSECopyTo",
158         "MatViennaCLCopyTo",
159         "MatSetValBatch",
160         "MatSetValBatch1",
161         "MatSetValBatch2",
162         "MatSetValBatch3",
163         "MatSetValBatch4",
164         "MatColoringApply",
165         "MatColoringComm",
166         "MatColoringLocal",
167         "MatColoringIS",
168         "MatColoringSetUp",
169
170         "VecView",
171         "VecMax",
172         "VecMin",
173         "VecDotBarrier",
174         "VecDot",
175         "VecDotNormBarr",
176         "VecDotNorm2",
177         "VecMDotBarrier",
178         "VecTDot",
179         "VecMTDot",
180         "VecNormBarrier",
181         "VecNorm",
182         "VecScale",
183         "VecCopy",
184         "VecSet",
185         "VecAXPY",
186         "VecAYPX",
187         "VecAXPBYCZ",
188         "VecWAXPY",
189         "VecSwap",
190         "VecOps",
191         "VecAssemblyBegin",
192         "VecAssemblyEnd",
193         "VecPointwiseMult",
194         "VecSetValues",
195         "VecLoad",
196         "VecScatterBarrie",
197         "VecScatterBegin",
198         "VecScatterEnd",
199         "VecSetRandom",
200         "VecReduceArith",
201         "VecReduceBarrier",
202         "VecReduceComm",
203         "VecReduceBegin",
204         "VecReduceEnd",
205
206
207         "PetscSFSetGraph",
208         "PetscSFBcastBegin",
209         "PetscSFBcastEnd",
210         "PetscSFReduceBegin",
211         "PetscSFReduceEnd",
212         "PetscSFFetchOpBegin",
213         "PetscSFFetchOpEnd"]
214
215
216def ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions):
217  '''Computes time spent by all processes'''
218  time  = 0
219  flops = 0
220  for t in localTimes:
221    time += localTimes[t]
222  flops = 0
223  for t in localFlops:
224    flops += localFlops[t]
225  messages = 0
226  for t in localMessages:
227    messages += localMessages[t]
228  messagelens = 0
229  for t in localMessageLens:
230    messagelens += localMessageLens[t]
231  reductions = 0
232  for t in localReductions:
233    reductions += localReductions[t]
234  return time,flops,messages,messagelens,reductions
235
236def ComputeSums(Stages):
237  ''' Computes the sum over all processes for each event; removes events with zero count and summaries'''
238  sumStages = {}
239  for stages in Stages:
240    sumStages[stages] = {}
241    for events in Stages[stages]:
242      sumStages[stages][events] = {}
243      for t in Stages[stages][events][0]:
244        sumStages[stages][events][t] = 0
245        for s in Stages[stages][events]:
246          sumStages[stages][events][t] += Stages[stages][events][s][t]
247
248  for stages in Stages:
249    for events in Stages[stages]:
250      if events == "summary" or not sumStages[stages][events]["count"] or events.startswith('Thread') or events == 'TSFunctionEval' or events == 'TSJacobianEval':
251        sumStages[stages].pop(events,None)
252  return sumStages
253
254def ObjectsCompare(a,b):
255  return Sorted.index(a) - Sorted.index(b)
256
257def PrintPercentTable(localTimes,localFlops,localMessages,localMessageLens,localReductions,Stages,Latex = False):
258  ''' Prints a simple table that displays the percent of time, flops, etc for each event in each stage'''
259  if Latex:
260    print "\documentclass{article}"
261    print "\\begin{document}"
262    print "\\begin{table}[!htbp]"
263    print "\centering"
264    if len(localTimes) > 1:
265      print "\\begin{tabular}{lcccccc}"
266      print " &  & \multicolumn{4}{c}{--------------- Percent of -------------} &  \\\\"
267      print "Event & Count & Time & Flops & Messages & Reductions & Flop rate \\\\"
268      print "\hline"
269  else:
270    if len(localTimes) > 1:
271       print "                                       ---------  Percent of  ------"
272       print "Event                       Count     Time  Flops Messages Reductions     Flop rate"
273       print "============================================================================"
274    else:
275       print "                                      Percent of"
276       print "Event                       Count     Time  Flops      Flop rate"
277       print "========================================================="
278
279  time,flops,numMessages,numMessageLen,numReductions  = ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions)
280  if not numMessages: numMessages = 1
281  if not numReductions: numReductions = 1
282  sumStages = ComputeSums(Stages)
283  for stage in sumStages:
284    if len(sumStages) > 1:
285      if Latex:
286        pass
287      else:
288        print("Stage: "+stage)
289    L = sumStages[stage].keys()
290    L.sort(cmp=ObjectsCompare)
291    seperatoradded = False
292    for i in xrange(len(L)):
293      event  = L[i]
294      space  = 0
295      if event.startswith("SNESSolve"):        space = 1
296      elif event.startswith("SNES"):           space = 2
297      elif event.startswith("KSPGMRESOrthog"): space = 3
298      elif event.startswith("KSP"):            space = 2
299      elif event.startswith("PC"):             space = 3
300      elif event.startswith("MatMult"):        space = 3
301      elif event.startswith("Mat"):            space = 4
302      elif event.startswith("Vec"):            space = 5
303      if Sorted.index(event) > Sorted.index("PCGAMGPOpt_AGG"):
304        space = 2
305        if not seperatoradded:
306          if Latex:
307            print "--Overlapping events---\\\\"
308          else:
309            print "--Overlapping events---"
310          seperatoradded = True
311
312      if len(localTimes) > 1:
313        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]
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],"&",'%5.0f' % values[2],"&",'%5.0f' % values[3],"&",'%8.0f' % ((sumStages[stage][event]["flops"]/sumStages[stage][event]["time"])/1000000.0),"\\\\"
317          else:
318            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)
319      else:
320        values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops]
321        if max(values) > .5:
322          if Latex:
323            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),"\\\\"
324          else:
325            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)
326
327  if Latex:
328    print "\end{tabular}"
329    print "\end{table}"
330    print "\end{document}"
331
332if __name__ == '__main__':
333  import sys
334  import os
335  sys.path.append(os.getcwd())
336  datafile = sys.argv[1]
337  if datafile.endswith('.py'): datafile = datafile[0:-3]
338  exec('import '+datafile+' as data')
339  latex = False
340  if len(sys.argv) > 2: latex = True
341
342  PrintPercentTable(data.LocalTimes,data.LocalFlops,data.LocalMessages,data.LocalMessageLens,data.LocalReductions,data.Stages,Latex = latex)