xref: /petsc/lib/petsc/bin/petsclogformat.py (revision 66b4e0ff87130d21ea0c4cd227822a4cde92a51c)
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         "DMPlexDistribCones",
79         "DMPlexDistribLabels",
80         "DMPlexDistribSF",
81         "DMPlexDistribField",
82         "DMPlexDistribData",
83         "DMPlexStratify",
84         "DMPlexPreallocate",
85         "DMPlexResidualFEM",
86         "DMPlexJacobianFEM",
87
88
89         "MatMults",
90         "MatMultConstr",
91         "MatMultAdd",
92         "MatMultTranspose",
93         "MatMultTrConstr",
94         "MatMultTrAdd",
95         "MatSolves",
96         "MatSolveAdd",
97         "MatSolveTranspos",
98         "MatSolveTrAdd",
99         "MatForwardSolve",
100         "MatBackwardSolve",
101         "MatCopy",
102         "MatConvert",
103         "MatScale",
104         "MatResidual",
105         "MatSetValues",
106         "MatGetValues",
107         "MatGetRow",
108         "MatGetRowIJ",
109         "MatGetSubMatrice",
110         "MatGetOrdering",
111         "MatIncreaseOvrlp",
112         "MatPartitioning",
113         "MatCoarsen",
114         "MatZeroEntries",
115         "MatLoad",
116         "MatView",
117         "MatAXPY",
118
119         "MatTranspose",
120         "MatMatMult",
121         "MatMatSolve",
122         "MatMatMultSym",
123         "MatMatMultNum",
124         "MatMatMatMult",
125         "MatMatMatMultSym",
126         "MatMatMatMultNum",
127         "MatPtAP",
128         "MatPtAPSymbolic",
129         "MatPtAPNumeric",
130         "MatRARt",
131         "MatRARtSym",
132         "MatRARtNum",
133         "MatMatTransMult",
134         "MatMatTrnMultSym",
135         "MatMatTrnMultNum",
136         "MatTrnMatMult",
137         "MatTrnMatMultSym",
138         "MatTrnMatMultNum",
139         "MatTrnColorCreate",
140         "MatGetRedundant",
141         "MatGetSeqNZStrct",
142         "MatGetMultiProcBlock",
143         "MatMPISumSeqNumeric",
144         "MatMPISumSeqSymbolic",
145         "MatMPISumSeq",
146         "MatMPIConcateSeq",
147         "MatGetLocalMat",
148         "MatGetLocalMatCondensed",
149         "MatGetBrowsOfAcols",
150         "MatGetBrAoCol",
151         "MatApplyPAPt_Symbolic",
152         "MatApplyPAPt_Numeric",
153         "MatApplyPAPt",
154         "MatGetSymTrans",
155         "MatGetSymTransR",
156         "MatTranspose_SeqAIJ_FAST",
157         "MatCUSPCopyTo",
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         "VecDotBarrier",
175         "VecDot",
176         "VecDotNormBarr",
177         "VecDotNorm2",
178         "VecMDotBarrier",
179         "VecTDot",
180         "VecMTDot",
181         "VecNormBarrier",
182         "VecNorm",
183         "VecScale",
184         "VecCopy",
185         "VecSet",
186         "VecAXPY",
187         "VecAYPX",
188         "VecAXPBYCZ",
189         "VecWAXPY",
190         "VecSwap",
191         "VecOps",
192         "VecAssemblyBegin",
193         "VecAssemblyEnd",
194         "VecPointwiseMult",
195         "VecSetValues",
196         "VecLoad",
197         "VecScatterBarrie",
198         "VecScatterBegin",
199         "VecScatterEnd",
200         "VecSetRandom",
201         "VecReduceArith",
202         "VecReduceBarrier",
203         "VecReduceComm",
204         "VecReduceBegin",
205         "VecReduceEnd",
206
207
208         "PetscSFSetGraph",
209         "PetscSFBcastBegin",
210         "PetscSFBcastEnd",
211         "PetscSFReduceBegin",
212         "PetscSFReduceEnd",
213         "PetscSFFetchOpBegin",
214         "PetscSFFetchOpEnd"]
215
216
217def ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions):
218  '''Computes time spent by all processes'''
219  time  = 0
220  flops = 0
221  for t in localTimes:
222    time += localTimes[t]
223  flops = 0
224  for t in localFlops:
225    flops += localFlops[t]
226  messages = 0
227  for t in localMessages:
228    messages += localMessages[t]
229  messagelens = 0
230  for t in localMessageLens:
231    messagelens += localMessageLens[t]
232  reductions = 0
233  for t in localReductions:
234    reductions += localReductions[t]
235  return time,flops,messages,messagelens,reductions
236
237def ComputeSums(Stages):
238  ''' Computes the sum over all processes for each event; removes events with zero count and summaries'''
239  sumStages = {}
240  for stages in Stages:
241    sumStages[stages] = {}
242    for events in Stages[stages]:
243      sumStages[stages][events] = {}
244      for t in Stages[stages][events][0]:
245        sumStages[stages][events][t] = 0
246        for s in Stages[stages][events]:
247          sumStages[stages][events][t] += Stages[stages][events][s][t]
248
249  for stages in Stages:
250    for events in Stages[stages]:
251      if events == "summary" or not sumStages[stages][events]["count"] or events.startswith('Thread') or events == 'TSFunctionEval' or events == 'TSJacobianEval':
252        sumStages[stages].pop(events,None)
253  return sumStages
254
255def ObjectsCompare(a,b):
256  return Sorted.index(a) - Sorted.index(b)
257
258def PrintPercentTable(localTimes,localFlops,localMessages,localMessageLens,localReductions,Stages,Latex = False):
259  ''' Prints a simple table that displays the percent of time, flops, etc for each event in each stage'''
260  if Latex:
261    print("\documentclass{article}")
262    print("\\begin{document}")
263    print("\\begin{table}[!htbp]")
264    print("\centering")
265    if len(localTimes) > 1:
266      print("\\begin{tabular}{lcccccc}")
267      print(" &  & \multicolumn{4}{c}{--------------- Percent of -------------} &  \\\\")
268      print("Event & Count & Time & Flops & Messages & Reductions & Flop rate \\\\")
269      print("\hline")
270  else:
271    if len(localTimes) > 1:
272       print("                                       ---------  Percent of  ------")
273       print("Event                       Count     Time  Flops Messages Reductions     Flop rate")
274       print("============================================================================")
275    else:
276       print("                                      Percent of")
277       print("Event                       Count     Time  Flops      Flop rate")
278       print("=========================================================")
279
280  time,flops,numMessages,numMessageLen,numReductions  = ComputeTotals(localTimes,localFlops,localMessages,localMessageLens,localReductions)
281  if not numMessages: numMessages = 1
282  if not numReductions: numReductions = 1
283  sumStages = ComputeSums(Stages)
284  for stage in sumStages:
285    if len(sumStages) > 1:
286      if Latex:
287        pass
288      else:
289        print("Stage: "+stage)
290    L = sumStages[stage].keys()
291    L.sort(cmp=ObjectsCompare)
292    seperatoradded = False
293    for i in xrange(len(L)):
294      event  = L[i]
295      space  = 0
296      if event.startswith("SNESSolve"):        space = 1
297      elif event.startswith("SNES"):           space = 2
298      elif event.startswith("KSPGMRESOrthog"): space = 3
299      elif event.startswith("KSP"):            space = 2
300      elif event.startswith("PC"):             space = 3
301      elif event.startswith("MatMult"):        space = 3
302      elif event.startswith("Mat"):            space = 4
303      elif event.startswith("Vec"):            space = 5
304      if Sorted.index(event) > Sorted.index("PCGAMGPOpt_AGG"):
305        space = 2
306        if not seperatoradded:
307          if Latex:
308            print("--Overlapping events---\\\\")
309          else:
310            print("--Overlapping events---")
311          seperatoradded = True
312
313      if len(localTimes) > 1:
314        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]
315        if max(values) > .5:
316          if Latex:
317            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),"\\\\")
318          else:
319            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))
320      else:
321        values = [100*sumStages[stage][event]["time"]/time,100*sumStages[stage][event]["flops"]/flops]
322        if max(values) > .5:
323          if Latex:
324            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),"\\\\")
325          else:
326            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))
327
328  if Latex:
329    print("\end{tabular}")
330    print("\end{table}")
331    print("\end{document}")
332
333if __name__ == '__main__':
334  import sys
335  import os
336  sys.path.append(os.getcwd())
337  datafile = sys.argv[1]
338  if datafile.endswith('.py'): datafile = datafile[0:-3]
339  exec('import '+datafile+' as data')
340  latex = False
341  if len(sys.argv) > 2: latex = True
342
343  PrintPercentTable(data.LocalTimes,data.LocalFlops,data.LocalMessages,data.LocalMessageLens,data.LocalReductions,data.Stages,Latex = latex)