aboutsummaryrefslogtreecommitdiffstats
path: root/parse_exps.py
diff options
context:
space:
mode:
authorJonathan Herman <hermanjl@cs.unc.edu>2013-02-21 18:32:24 -0500
committerJonathan Herman <hermanjl@cs.unc.edu>2013-02-21 18:32:24 -0500
commit6e2b99a0870e467e35c8b4b95aeb1e665dded413 (patch)
tree1e4b4d000c6b53b93a35b5446dc774d4799c987c /parse_exps.py
parent9bcbb4048cd82ea11ed469731eae95d808b99449 (diff)
Many bugfixes motivated by some end-to-end testing.
Diffstat (limited to 'parse_exps.py')
-rwxr-xr-xparse_exps.py58
1 files changed, 39 insertions, 19 deletions
diff --git a/parse_exps.py b/parse_exps.py
index f27021a..4cdc0a1 100755
--- a/parse_exps.py
+++ b/parse_exps.py
@@ -8,13 +8,13 @@ import parse.sched as st
8import pickle 8import pickle
9import shutil as sh 9import shutil as sh
10import sys 10import sys
11import traceback
11 12
12from collections import namedtuple 13from collections import namedtuple
13from common import load_params 14from common import load_params
14from optparse import OptionParser 15from optparse import OptionParser
15from parse.dir_map import DirMap
16from parse.point import ExpPoint 16from parse.point import ExpPoint
17from parse.tuple_table import TupleTable,ReducedTupleTable 17from parse.tuple_table import TupleTable
18from parse.col_map import ColMapBuilder 18from parse.col_map import ColMapBuilder
19from multiprocessing import Pool, cpu_count 19from multiprocessing import Pool, cpu_count
20 20
@@ -23,7 +23,6 @@ def parse_args():
23 parser = OptionParser("usage: %prog [options] [data_dir]...") 23 parser = OptionParser("usage: %prog [options] [data_dir]...")
24 24
25 print("default to no params.py") 25 print("default to no params.py")
26 print("save measurements in temp directory for faster reloading")
27 26
28 parser.add_option('-o', '--out', dest='out', 27 parser.add_option('-o', '--out', dest='out',
29 help='file or directory for data output', default='parse-data') 28 help='file or directory for data output', default='parse-data')
@@ -85,16 +84,24 @@ def load_exps(exp_dirs, cm_builder, clean):
85 84
86 return exps 85 return exps
87 86
88def parse_exp(exp, force): 87def parse_exp(exp_force):
88 # Tupled for multiprocessing
89 exp, force = exp_force
90
89 result_file = exp.work_dir + "/exp_point.pkl" 91 result_file = exp.work_dir + "/exp_point.pkl"
90 should_load = not force and os.path.exists(result_file) 92 should_load = not force and os.path.exists(result_file)
91 mode = 'r' if should_load else 'w'
92 93
93 with open(result_file, mode + 'b') as f: 94 result = None
94 if should_load: 95 if should_load:
95 # No need to go through this work twice 96 with open(result_file, 'rb') as f:
96 result = pickle.load(f) 97 try:
97 else: 98 # No need to go through this work twice
99 result = pickle.load(f)
100 except:
101 pass
102
103 if not result:
104 try:
98 result = ExpPoint(exp.path) 105 result = ExpPoint(exp.path)
99 cycles = exp.params[conf.PARAMS['cycles']] 106 cycles = exp.params[conf.PARAMS['cycles']]
100 107
@@ -104,7 +111,10 @@ def parse_exp(exp, force):
104 # Write scheduling statistics into result 111 # Write scheduling statistics into result
105 st.extract_sched_data(result, exp.path, exp.work_dir) 112 st.extract_sched_data(result, exp.path, exp.work_dir)
106 113
107 pickle.dump(result, f) 114 with open(result_file, 'wb') as f:
115 pickle.dump(result, f)
116 except:
117 traceback.print_exc()
108 118
109 return (exp, result) 119 return (exp, result)
110 120
@@ -128,14 +138,24 @@ def main():
128 sys.stderr.write("Parsing data...\n") 138 sys.stderr.write("Parsing data...\n")
129 139
130 procs = min(len(exps), cpu_count()/2) 140 procs = min(len(exps), cpu_count()/2)
131 pool = Pool(processes=procs) 141 pool = Pool(processes=procs)
132 enum = pool.imap_unordered(parse_exp, exps, [opts.force]*len(exps)) 142 pool_args = zip(exps, [opts.force]*len(exps))
133 for i, (exp, result) in enumerate(enum): 143 enum = pool.imap_unordered(parse_exp, pool_args, 1)
134 if opts.verbose: 144
135 print(result) 145 try:
136 else: 146 for i, (exp, result) in enumerate(enum):
137 sys.stderr.write('\r {0:.2%}'.format(float(i)/len(exps))) 147 if opts.verbose:
138 result_table[exp.params] += [result] 148 print(result)
149 else:
150 sys.stderr.write('\r {0:.2%}'.format(float(i)/len(exps)))
151 result_table[exp.params] += [result]
152 pool.close()
153 except:
154 pool.terminate()
155 traceback.print_exc()
156 raise Exception("Failed parsing!")
157 finally:
158 pool.join()
139 159
140 sys.stderr.write('\n') 160 sys.stderr.write('\n')
141 161