diff options
| author | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
|---|---|---|
| committer | Jonathan Herman <hermanjl@cs.unc.edu> | 2013-02-21 18:32:24 -0500 |
| commit | 6e2b99a0870e467e35c8b4b95aeb1e665dded413 (patch) | |
| tree | 1e4b4d000c6b53b93a35b5446dc774d4799c987c /parse_exps.py | |
| parent | 9bcbb4048cd82ea11ed469731eae95d808b99449 (diff) | |
Many bugfixes motivated by some end-to-end testing.
Diffstat (limited to 'parse_exps.py')
| -rwxr-xr-x | parse_exps.py | 58 |
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 | |||
| 8 | import pickle | 8 | import pickle |
| 9 | import shutil as sh | 9 | import shutil as sh |
| 10 | import sys | 10 | import sys |
| 11 | import traceback | ||
| 11 | 12 | ||
| 12 | from collections import namedtuple | 13 | from collections import namedtuple |
| 13 | from common import load_params | 14 | from common import load_params |
| 14 | from optparse import OptionParser | 15 | from optparse import OptionParser |
| 15 | from parse.dir_map import DirMap | ||
| 16 | from parse.point import ExpPoint | 16 | from parse.point import ExpPoint |
| 17 | from parse.tuple_table import TupleTable,ReducedTupleTable | 17 | from parse.tuple_table import TupleTable |
| 18 | from parse.col_map import ColMapBuilder | 18 | from parse.col_map import ColMapBuilder |
| 19 | from multiprocessing import Pool, cpu_count | 19 | from 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 | ||
| 88 | def parse_exp(exp, force): | 87 | def 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 | ||
