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