Peano
Loading...
Searching...
No Matches
plot_load_distribution.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3import argparse
4import os
5
6
7from OutputFile import OutputFile
8
9import matplotlib.pyplot as plt
10
11
12Colours = [ "#0000ff", "#00ff00", "#ff0000", "#00ffff", "#ff00ff", "#ffff00", "#aaaaaa" ]
13Symbols = [ "o", "s", "<", ">", "^", "v", "x" ]
14
15
16def flatten( input_data ):
17 """
18
19 y_data: [[Float]]
20 Multiple quantities per time stamp. There might be different numbers
21 of quantities per time stamp.
22
23 We return a tuple [Float],[Float].
24
25 """
26 x_data_flattened = []
27 y_data_flattened = []
28
29 for i in range(0,len(input_data)):
30 for data_point in input_data[i]:
31 x_data_flattened.append( i )
32 y_data_flattened.append( data_point )
33
34 return x_data_flattened, y_data_flattened
35
36
37def remove_duplicates(x_data,y_data):
38 assert len(x_data)==len(y_data)
39 zipped_input = zip(x_data, y_data)
40 zipped_output = []
41 for i in zipped_input:
42 if not i in zipped_output:
43 zipped_output.append(i)
44 return [x[0] for x in zipped_output], [x[1] for x in zipped_output]
45
46
47
48def plot_cells_per_rank( data: OutputFile,
49 plot_remote_cells,
50 show_optimum,
51 ):
52 Ranks = range(0,data.ranks)
53
54 symbol_counter = 0
55 colour_counter = 0
56 line_counter = 0
57 my_alpha = 0.1+(1.0-0.3)/len(Ranks)
58
59 final_number_of_cells = 0
60
61 for rank in Ranks:
62 local_cells = data.local_cells_per_snapshot( rank )
63
64 x_data_flattened, y_data_flattened = flatten( local_cells )
65 x_data_flattened, y_data_flattened = remove_duplicates( x_data_flattened, y_data_flattened )
66 plt.scatter(x_data_flattened,
67 y_data_flattened,
68 marker=Symbols[symbol_counter],
69 color=Colours[colour_counter],
70 alpha=my_alpha,
71 label="#cells per tree on rank " + str(rank) )
72
73 if plot_remote_cells:
74 remote_cells = data.remote_cells_per_snapshot( rank )
75 x_data_flattened, y_data_flattened = flatten( remote_cells )
76 x_data_flattened, y_data_flattened = remove_duplicates( x_data_flattened, y_data_flattened )
77 plt.scatter(x_data_flattened,
78 y_data_flattened, marker=Symbols[symbol_counter], color=Colours[colour_counter], alpha=my_alpha, facecolors='none', label="Remote #cells per tree")
79
80 if show_optimum:
81 optimum_cells = data.total_local_cells_per_snapshot( rank )
82 max_trees = max( data.trees_per_snapshot( rank ) )
83 y_data = [ x / max_trees for x in optimum_cells ]
84 x_data = range(0,len(y_data))
85 plt.plot(x_data, y_data, "-", color=Colours[colour_counter] )
86
87 symbol_counter += 1
88 colour_counter += 1
89 if symbol_counter>=len(Symbols):
90 symbol_counter = 0
91 if colour_counter>=len(Colours):
92 colour_counter = 0
93 line_counter += 1
94
95
96
97def plot_trees_per_rank( data: OutputFile ):
98 Ranks = range(0,data.ranks)
99
100 symbol_counter = 0
101 colour_counter = 0
102 my_alpha = 0.1
103 for rank in Ranks:
104 y_data = data.trees_per_snapshot( rank )
105 x_data = range(0,len(y_data))
106 plt.plot(x_data, y_data, marker=Symbols[symbol_counter], color=Colours[colour_counter], label="rank " + str(rank) )
107
108 symbol_counter += 1
109 colour_counter += 1
110 if symbol_counter>=len(Symbols):
111 symbol_counter = 0
112 colour_counter += 1
113
114 if colour_counter>=len(Colours):
115 colour_counter = 0
116
117
118
119if __name__ == "__main__":
120 parser = argparse.ArgumentParser(description='Peano 4 load balancing plotter')
121 parser.add_argument("file", help="filename of the file to parse (should be a text file)")
122 parser.add_argument("-v", "--verbose", action="store_true", help="increase output verbosity", default=False)
123 parser.add_argument("-rc", "--remote-cells", dest="plot_remote_cells", action="store_true", default=False, help="plot remote cells, too")
124 parser.add_argument("-opt", "--show-optimum", dest="show_optimum", action="store_false", default=True, help="display optimal number of cells per rank")
125 parser.add_argument("-yscale", "--yscale", dest="yscale", choices=["linear", "log-2", "log-10"], default="linear", help="select scaling of y-axis" )
126 parser.add_argument("-ncol", "--columns-in-legend", dest="columns_in_legend", type=int, default=1, help="number of columns within legend" )
127 args = parser.parse_args()
128
129 data = OutputFile( args.file, args.verbose )
130
131 plt.clf()
132 plot_trees_per_rank( data )
133 plt.xlabel( "time" )
134 plt.ylabel( "trees per rank" )
135
136 if args.yscale=="log-2":
137 plt.yscale( "log", base=2 )
138 if args.yscale=="log-10":
139 plt.yscale( "log", base=10 )
140
141 plt.legend(ncol=args.columns_in_legend)
142 plt.savefig( args.file + "-trees-per-rank.pdf" )
143 plt.savefig( args.file + "-trees-per-rank.png" )
144
145 plt.clf()
146 plot_cells_per_rank( data, args.plot_remote_cells, args.show_optimum )
147 plt.xlabel( "time" )
148 plt.ylabel( "cells per tree" )
149
150 if args.yscale=="log-2":
151 plt.yscale( "log", base=2 )
152 if args.yscale=="log-10":
153 plt.yscale( "log", base=10 )
154
155 plt.ylim( bottom=9 )
156 plt.legend(ncol=args.columns_in_legend)
157 output_filename = args.file + "-cells-per-rank"
158 plt.savefig( output_filename + ".pdf" )
159 plt.savefig( output_filename + ".png" )
160 print( "wrote output to " + output_filename + "[-cells-per-rank|-tree-per-rank].[png|pdf]")
161
Represents single output file dumped by Peano.
Definition OutputFile.py:4
flatten(input_data)
y_data: [[Float]] Multiple quantities per time stamp.
plot_trees_per_rank(OutputFile data)
plot_cells_per_rank(OutputFile data, plot_remote_cells, show_optimum)