1 | #!/dsk/l1/misc/meunier/tools/bin/python3 |
---|
2 | # -*- coding: utf-8 -*- |
---|
3 | |
---|
4 | # Note: |
---|
5 | # This code requires python 3, and I haven't found |
---|
6 | # a proper way of mixing python 2 and 3 without using |
---|
7 | # the she/bang line at the top, which includes a local |
---|
8 | # path... |
---|
9 | |
---|
10 | from __future__ import print_function |
---|
11 | import os |
---|
12 | import sys |
---|
13 | import re |
---|
14 | import subprocess |
---|
15 | import shutil |
---|
16 | import filecmp |
---|
17 | import random |
---|
18 | import math |
---|
19 | |
---|
20 | from stack import Stack |
---|
21 | |
---|
22 | from common import * |
---|
23 | |
---|
24 | |
---|
25 | use_rand_images = True |
---|
26 | with_features = False |
---|
27 | |
---|
28 | threads = [1, 2, 4, 8, 16, 32, 64] |
---|
29 | use_dsk = True |
---|
30 | img_size = 2048 |
---|
31 | granularity = 1 |
---|
32 | rand_seed = 7 |
---|
33 | |
---|
34 | top_path = os.path.abspath(os.path.join(os.path.dirname(os.path.realpath(__file__)), "..")) |
---|
35 | scripts_path = os.path.join(top_path, 'scripts') |
---|
36 | pyconf_file = os.path.join(scripts_path, "config.py") |
---|
37 | |
---|
38 | base_data_dir = "data" # For timing information extracted |
---|
39 | base_graph_dir = "graphes" # For storing generated graphes |
---|
40 | |
---|
41 | |
---|
42 | # Each of these configuration must have been run with both features activated and deactivated |
---|
43 | configs = [ |
---|
44 | #{'SLOW':'1', 'FAST':'0', 'PARMERGE':'0', 'ARSP':'0'}, |
---|
45 | #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'0', 'ARSP':'0'}, |
---|
46 | #{'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'0'}, |
---|
47 | {'SLOW':'0', 'FAST':'1', 'PARMERGE':'1', 'ARSP':'1'}, |
---|
48 | ] |
---|
49 | |
---|
50 | |
---|
51 | # Loading config file |
---|
52 | with open(pyconf_file) as f: |
---|
53 | code = compile(f.read(), pyconf_file, 'exec') |
---|
54 | exec(code) |
---|
55 | |
---|
56 | nb_step = 0 |
---|
57 | |
---|
58 | if use_dsk: |
---|
59 | try: |
---|
60 | dsk_dir |
---|
61 | if not os.path.exists(dsk_dir): |
---|
62 | print("*** Warning: variable dsk_dir is not defined in %s file; using current directory for reading data files" % (short_path(pyconf_file))) |
---|
63 | use_dsk = False |
---|
64 | except OSError: |
---|
65 | print("*** Warning: directory %s does not exist; using current directory for reading data files" % (dsk_dir)) |
---|
66 | use_dsk = False |
---|
67 | |
---|
68 | # Updating output directories |
---|
69 | if use_dsk: |
---|
70 | data_dir = os.path.join(dsk_dir, base_data_dir) |
---|
71 | graph_dir = os.path.join(dsk_dir, base_graph_dir) |
---|
72 | else: |
---|
73 | data_dir = os.path.join(scripts_path, base_data_dir) |
---|
74 | graph_dir = os.path.join(scripts_path, base_graph_dir) |
---|
75 | |
---|
76 | |
---|
77 | |
---|
78 | if not os.path.exists(graph_dir): |
---|
79 | my_mkdir(graph_dir) |
---|
80 | |
---|
81 | |
---|
82 | |
---|
83 | if with_features: |
---|
84 | features = ["FT", "NF"] # Features and No-Features |
---|
85 | else: |
---|
86 | features = ["NF"] # No features only |
---|
87 | |
---|
88 | |
---|
89 | exec_time = {} |
---|
90 | for config in configs: |
---|
91 | fconfig = frozenset(config.items()) |
---|
92 | exec_time[fconfig] = {} |
---|
93 | for thread in threads: |
---|
94 | exec_time[fconfig][thread] = {} |
---|
95 | for ftrs in features: # Features or No features |
---|
96 | exec_time[fconfig][thread][ftrs] = {} |
---|
97 | for density in range(0, 101): |
---|
98 | exec_time[fconfig][thread][ftrs][density] = {} |
---|
99 | random_img_file = get_random_img_file(density, img_size, img_size, granularity, rand_seed) |
---|
100 | img_basename = os.path.splitext(random_img_file)[0] |
---|
101 | log_file = get_filename(data_dir, thread, config, ftrs == "FT", img_basename) |
---|
102 | lines = open(log_file, 'r') |
---|
103 | for line in lines: |
---|
104 | tokens = line.split() |
---|
105 | if len(tokens) == 0: |
---|
106 | continue |
---|
107 | tag = tokens[0] |
---|
108 | pattern = re.compile('\[STEP_([0-9]+)\]') |
---|
109 | match = pattern.match(tag) |
---|
110 | if match: |
---|
111 | step = int(match.group(1)) |
---|
112 | nb_step = max(int(step) + 1, nb_step) |
---|
113 | value = tokens[len(tokens) - 1] |
---|
114 | exec_time[fconfig][thread][ftrs][density][step] = value |
---|
115 | #print("exec_time[fconfig][%d][%s][%d][%s] = %s" % (thread, ftrs, density, step, exec_time[fconfig][thread][ftrs][density][step])) |
---|
116 | |
---|
117 | |
---|
118 | |
---|
119 | |
---|
120 | for config in configs: |
---|
121 | fconfig = frozenset(config.items()) |
---|
122 | for thread in threads: |
---|
123 | plotter = Stack(["red", "blue", "#CAFE01", "#CA01FE", "#01CAFE"], "Légende", "X", "Y") |
---|
124 | X = [x for x in range(0, 101)] |
---|
125 | plotter.add_x(X) |
---|
126 | assert(nb_step == 4) |
---|
127 | YPAR1 = [float(int(exec_time[fconfig][thread]["NF"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling |
---|
128 | YPAR2 = [float(int(exec_time[fconfig][thread]["NF"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal) |
---|
129 | YPTC2 = [float(int(exec_time[fconfig][thread]["NF"][density][2]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Transitive Closure |
---|
130 | YPAR3 = [float(int(exec_time[fconfig][thread]["NF"][density][3]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Relabeling |
---|
131 | |
---|
132 | plotter.add_y(YPAR1) |
---|
133 | plotter.add_y(YPAR2) |
---|
134 | plotter.add_y(YPTC2) |
---|
135 | # Not displaying PAR3 |
---|
136 | |
---|
137 | if with_features: |
---|
138 | YPAR1f = [float(int(exec_time[fconfig][thread]["FT"][density][0]) / math.pow(img_size, 2)) for density in range(0, 101)] # Parallel Labeling |
---|
139 | YPAR2f = [float(int(exec_time[fconfig][thread]["FT"][density][1]) / math.pow(img_size, 2)) for density in range(0, 101)] # Merging (Parallel or Pyramidal) |
---|
140 | deltaYPAR1 = [max(0, x - y) for x, y in zip (YPAR1f, YPAR1)] |
---|
141 | deltaYPAR2 = [max(0, x - y) for x, y in zip (YPAR2f, YPAR2)] |
---|
142 | YFTC = [x + y for x, y in zip (deltaYPAR1, deltaYPAR2)] # Features Computation |
---|
143 | plotter.add_y(YFTC) |
---|
144 | |
---|
145 | plotter.plot() |
---|
146 | graph_name = get_graph_filename(graph_dir, thread, config, ".pdf") |
---|
147 | print("# Creating graph %s" % short_path(graph_name)) |
---|
148 | plotter.save(graph_name) |
---|
149 | |
---|
150 | |
---|
151 | |
---|
152 | |
---|
153 | |
---|
154 | |
---|