]> git.somenet.org - pub/astra/parallel.git/blob - scan/parseDat.py
mpiscan abgabe erweitert und cleaned repo
[pub/astra/parallel.git] / scan / parseDat.py
1 #!/usr/bin/env python2
2
3 import os, subprocess
4
5 def listtofile(listing, file):
6         fd = open(file, 'r')
7         for i in listing:
8                 fd.write(i+"\n")
9         fd.close()
10
11 def makeGraphs(graphs, graphtitle = "Title", xlabel = "Numbers calculated", ylabel = "Time needed for calculation"):
12         gendir = "stats/generated/"
13         subprocess.call(["mkdir", "-p", gendir])
14         p = subprocess.Popen(['gnuplot'],stdout=subprocess.PIPE,stdin=subprocess.PIPE)
15         # now do the plots
16         for graphfile in graphs:
17                 # set output 'filename'
18                 p.stdin.write("set terminal png font arial 8 #size 600,300\n")
19                 p.stdin.write("set grid\n")
20                 p.stdin.write("set datafile separator ';'\n")
21                 p.stdin.write("set title 'Timing of each "+graphtitle+"'\n")
22                 p.stdin.write("set xlabel '"+xlabel+"'\n")
23                 p.stdin.write("set ylabel '"+ylabel+"'\n")
24                 p.stdin.write("set output '"+gendir+graphfile+"'\n")
25                 # plot 'filename' using 1:2 title 'algorithm' with lines, 'filename2' using 1:2 title 'algo2' with lines
26                 plots = []
27                 for title, file, cols in graphs[graphfile]:
28                         plots.append("'"+gendir+file+"' using "+str(cols)+" title '"+str(title)+"' with lines")
29                 plotcommand = ", ".join(plots)
30                 #print gendir+graphfile
31                 p.stdin.write("plot "+plotcommand+"\n")
32         p.communicate()[0]
33         p.stdin.close()
34
35 statsdir = 'stats/raw/'
36 runs = os.listdir(statsdir)
37 #print runs
38
39 bigrunlist = []
40 for i in runs:
41         runfiles = os.listdir(statsdir+i)
42 #       print runfiles
43         for file in runfiles:
44 #               print "File: %s%s/%s" % (statsdir, i, file)
45                 splitfilename = file.split('_')
46                 dict = {}
47                 dict['no'] = int(splitfilename[0].lstrip('no'))
48                 dict['nnp'] = int(splitfilename[1].lstrip('nnp'))
49                 dict['n'] = int(splitfilename[2].lstrip('n'))
50                 fd = open(statsdir+i+'/'+file, "r")
51                 fd_text = fd.read()
52                 fd.close()
53                 fd_lines = fd_text.split("\n")
54                 for line in fd_lines:
55                         if line == "":
56                                 continue
57                         elements = line.split(" ")
58                         if len(elements) < 2:
59                                 continue
60                         if elements[1] != "timings:":
61                                 continue
62                         for elem in elements:
63                                 (key, value) = elem.split(":", 1)
64                                 if key == 'prep':
65                                         dict['prep'] = float(value)
66                                 elif key == 'algo':
67                                         dict['algo'] = float(value)
68                                 elif key == 'postp':
69                                         dict['postp'] = float(value)
70                                 elif key == 'end':
71                                         dict['end'] = float(value)
72                         bigrunlist.append(dict)
73 nos = {}
74 nnps = {}
75 ns = {}
76 foolist = {}
77 for i in bigrunlist:
78         if not (i['no'], i['nnp'], i['n']) in foolist:
79                 foolist[(i['no'], i['nnp'], i['n'])] = [i['end']]
80         else:
81                 foolist[(i['no'], i['nnp'], i['n'])].append(i['end'])
82         if not i['no'] in nos:
83                 nos[i['no']] = {}
84         if not i['nnp'] in nnps:
85                 nnps[i['nnp']] = {}
86         if not i['n'] in ns:
87                 ns[i['n']] = {}
88 #print "NOs: %s" % nos
89 #print "NNPs: %s" % nnps
90 #print "Ns: %s" % ns
91 uniquelist = []
92 for key in foolist:
93         minval = min(foolist[key])
94         uniquelist.append((key[0], key[1], key[2], minval))
95 uniquelist.sort()
96 alg_dict = {}
97 sched_dict = {}
98 for i in uniquelist:
99         if i[0] not in alg_dict:
100                 alg_dict[i[0]] = {}
101         if i[1] not in alg_dict[i[0]]:
102                 alg_dict[i[0]][i[1]] = []
103         alg_dict[i[0]][i[1]].append(str(i[2])+";"+str(i[3]))
104         if i[1] not in sched_dict:
105                 sched_dict[i[1]] = {}
106         if i[0] not in sched_dict[i[1]]:
107                 sched_dict[i[1]][i[0]] = []
108         sched_dict[i[1]][i[0]].append(str(i[2])+";"+str(i[3]))
109         #print "od["+i[0]+"]["+i[1]+"] = "+str(i[2])+":"+str(i[3])
110
111 graphs_alg = {}
112 graphs_sched = {}
113 gendir = "stats/generated/"
114 subprocess.call(["mkdir", "-p", gendir])
115 for alg in alg_dict:
116         pngfile = 'no.'+str(alg)+'.png'
117         graphs_alg[pngfile] = []
118         for sched in alg_dict[alg]:
119                 datfile = 'data.no'+str(alg)+'.nnp'+str(sched)+'.dat'
120                 subprocess.call(["rm", "-f", gendir+datfile])
121                 fh = open(gendir+datfile, 'a+')
122                 graphs_alg[pngfile].append((sched, datfile, '1:2'))
123                 for dot in alg_dict[alg][sched]:
124                         fh.write(dot+"\n")
125                 fh.close()
126 for sched in sched_dict:
127         pngfile = 'nnp.'+str(sched)+'.png'
128         graphs_sched[pngfile] = []
129         for alg in sched_dict[sched]:
130                 datfile = 'data.no'+str(alg)+'.nnp'+str(sched)+'.dat'
131                 graphs_sched[pngfile].append((alg, datfile, '1:2'))
132
133 #graphs['test1.png'] = [('linetitle1', 'prefix.hillis.dat', '1:2')]
134
135 makeGraphs(graphs_alg, "no")
136 makeGraphs(graphs_sched, "nnp")