1 | # |
---|
2 | # $Id: Makefile.Workload 124 2009-06-17 12:11:25Z rosiere $ |
---|
3 | # |
---|
4 | # [ Description ] |
---|
5 | # |
---|
6 | # Makefile |
---|
7 | # |
---|
8 | |
---|
9 | ifeq ($(origin BENCHS), undefined) |
---|
10 | $(error "variable BENCHS is undefined") |
---|
11 | endif |
---|
12 | |
---|
13 | ifeq ($(origin NB_THREAD_MAX),, undefined) |
---|
14 | $(error "variable NB_THREAD_MAX is undefined") |
---|
15 | endif |
---|
16 | |
---|
17 | #-----[ Variables ]--------------------------------------------------------------- |
---|
18 | FILE_WORKLOAD_LOG = workload.txt |
---|
19 | FILE_WORKLOAD_SCRIPT = workload.sh |
---|
20 | FILE_BENCH = $(DIR_INC)/workload.h |
---|
21 | FILE_BENCH_SED = $(DIR_INC)/workload.h.sed |
---|
22 | |
---|
23 | #-----[ Rules ]------------------------------------------------------------------- |
---|
24 | |
---|
25 | list : |
---|
26 | @\ |
---|
27 | for bench in $(BENCHS); do \ |
---|
28 | $(ECHO) $${bench}; \ |
---|
29 | done; |
---|
30 | |
---|
31 | print : |
---|
32 | @$(CAT) $(FILE_BENCH); |
---|
33 | |
---|
34 | define : |
---|
35 | @ \ |
---|
36 | $(ECHO) "Give a Number of thread (1 by default, Max : $(NB_THREAD_MAX)) : "; \ |
---|
37 | declare -i NB_THREAD=0; \ |
---|
38 | $(READ) NB_THREAD; \ |
---|
39 | \ |
---|
40 | if $(TEST) "$$NB_THREAD" -ge "$(NB_THREAD_MAX)"; \ |
---|
41 | then \ |
---|
42 | NB_THREAD=$(NB_THREAD_MAX); \ |
---|
43 | else \ |
---|
44 | if $(TEST) "$$NB_THREAD" -eq 0; \ |
---|
45 | then \ |
---|
46 | NB_THREAD=1; \ |
---|
47 | fi; \ |
---|
48 | fi; \ |
---|
49 | \ |
---|
50 | $(ECHO) "You want $$NB_THREAD thread(s)"; \ |
---|
51 | $(ECHO) ""; \ |
---|
52 | declare -i NUM_THREAD=0; \ |
---|
53 | declare WORKLOAD=""; \ |
---|
54 | declare -i PREVIOUS=1; \ |
---|
55 | declare -i CPT=2; \ |
---|
56 | declare -a BENCHS; \ |
---|
57 | \ |
---|
58 | BENCHS[0]="previous choose"; \ |
---|
59 | BENCHS[1]="none"; \ |
---|
60 | for benchs in $(BENCHS); do \ |
---|
61 | BENCHS[$$CPT]=$${benchs/"."/"_"}; \ |
---|
62 | CPT=$$(($$CPT+1)); \ |
---|
63 | done; \ |
---|
64 | \ |
---|
65 | $(ECHO) "For each Thread, you must select a number of benchmark (0 by default)";\ |
---|
66 | $(ECHO) ""; \ |
---|
67 | \ |
---|
68 | while [ $$NUM_THREAD -lt $$NB_THREAD ]; \ |
---|
69 | do \ |
---|
70 | if $(TEST) $$NUM_THREAD -ne 0; \ |
---|
71 | then \ |
---|
72 | WORKLOAD=$$WORKLOAD",\n"; \ |
---|
73 | fi; \ |
---|
74 | \ |
---|
75 | $(ECHO) "For Thread[$$NUM_THREAD] ....."; \ |
---|
76 | declare -i NUM_BENCH; \ |
---|
77 | \ |
---|
78 | $(ECHO) "0) previous choose : $${BENCHS[$$PREVIOUS]}"; \ |
---|
79 | CPT=1; \ |
---|
80 | while [ $$CPT -lt $${#BENCHS[*]} ]; \ |
---|
81 | do \ |
---|
82 | $(ECHO) "$$CPT) $${BENCHS[$$CPT]}"; \ |
---|
83 | CPT=$$(($$CPT+1)); \ |
---|
84 | done; \ |
---|
85 | $(READ) NUM_BENCH; \ |
---|
86 | \ |
---|
87 | if $(TEST) "$$NUM_BENCH" -ge "$$CPT"; \ |
---|
88 | then \ |
---|
89 | NUM_BENCH=0; \ |
---|
90 | fi; \ |
---|
91 | \ |
---|
92 | if $(TEST) "$$NUM_BENCH" -eq "0"; \ |
---|
93 | then \ |
---|
94 | NUM_BENCH=$$PREVIOUS; \ |
---|
95 | else \ |
---|
96 | PREVIOUS=$$NUM_BENCH; \ |
---|
97 | fi; \ |
---|
98 | \ |
---|
99 | $(ECHO) "Benchmark selected : $${BENCHS[$$NUM_BENCH]}"; \ |
---|
100 | $(ECHO) ""; \ |
---|
101 | \ |
---|
102 | WORKLOAD=$$WORKLOAD"\t(void *) run_$${BENCHS[$$NUM_BENCH]}"; \ |
---|
103 | NUM_THREAD=$$(($$NUM_THREAD+1)); \ |
---|
104 | done; \ |
---|
105 | $(ECHO) ""; \ |
---|
106 | $(ECHO) "Generate the file : $(FILE_BENCH)"; \ |
---|
107 | $(CAT) $(FILE_BENCH_SED) |$(SED) "s/@WORKLOAD/$$WORKLOAD/" > $(FILE_BENCH); \ |
---|
108 | $(RM) $$$$; \ |
---|
109 | $(ECHO) ""; |
---|
110 | |
---|
111 | |
---|
112 | workload : |
---|
113 | @ \ |
---|
114 | $(ECHO) "Give a Number of thread (1 by default, Max : $(NB_THREAD_MAX)) : "; \ |
---|
115 | declare -i NB_THREAD=0; \ |
---|
116 | $(READ) NB_THREAD; \ |
---|
117 | \ |
---|
118 | if $(TEST) "$$NB_THREAD" -ge "$(NB_THREAD_MAX)"; \ |
---|
119 | then \ |
---|
120 | NB_THREAD=$(NB_THREAD_MAX); \ |
---|
121 | else \ |
---|
122 | if $(TEST) "$$NB_THREAD" -eq 0; \ |
---|
123 | then \ |
---|
124 | NB_THREAD=1; \ |
---|
125 | fi; \ |
---|
126 | fi; \ |
---|
127 | \ |
---|
128 | $(ECHO) " * You want $$NB_THREAD thread(s)"; \ |
---|
129 | $(ECHO) ""; \ |
---|
130 | $(ECHO) "List of all Benchmark"; \ |
---|
131 | declare -i CPT=1; \ |
---|
132 | declare -a BENCHS; \ |
---|
133 | \ |
---|
134 | for benchs in $(BENCHS); do \ |
---|
135 | $(ECHO) " $$CPT) $$benchs"; \ |
---|
136 | BENCHS[$$CPT]=$${benchs/"."/"_"}; \ |
---|
137 | CPT=$$(($$CPT+1)); \ |
---|
138 | done; \ |
---|
139 | $(ECHO) ""; \ |
---|
140 | $(ECHO) "Enter the list benchmark (0 to stop)"; \ |
---|
141 | declare -i NUM_BENCH; \ |
---|
142 | CPT=1; \ |
---|
143 | declare -a -i WORKLOAD; \ |
---|
144 | \ |
---|
145 | rm -f $(FILE_WORKLOAD_SCRIPT); \ |
---|
146 | $(ECHO) -n "$(ECHO) -e \"$$NB_THREAD\n" > $(FILE_WORKLOAD_SCRIPT); \ |
---|
147 | \ |
---|
148 | while $(TEST) 1; do \ |
---|
149 | $(READ) NUM_BENCH; \ |
---|
150 | \ |
---|
151 | $(ECHO) -n "$$NUM_BENCH\n" >> $(FILE_WORKLOAD_SCRIPT); \ |
---|
152 | \ |
---|
153 | if $(TEST) $$NUM_BENCH -eq 0; then \ |
---|
154 | break; \ |
---|
155 | fi; \ |
---|
156 | \ |
---|
157 | if $(TEST) $$NUM_BENCH -gt $${#BENCHS[*]}; then \ |
---|
158 | $(ECHO) " * Out of limit, retry ..."; \ |
---|
159 | else \ |
---|
160 | echo " * $${BENCHS[$$NUM_BENCH]}"; \ |
---|
161 | WORKLOAD[$$CPT]=$$NUM_BENCH; \ |
---|
162 | CPT=$$(($$CPT+1)); \ |
---|
163 | fi; \ |
---|
164 | done; \ |
---|
165 | \ |
---|
166 | $(ECHO) "\" | $(MAKE) $@" >> $(FILE_WORKLOAD_SCRIPT); \ |
---|
167 | $(CHMOD) +x $(FILE_WORKLOAD_SCRIPT); \ |
---|
168 | \ |
---|
169 | if $(TEST) $$NB_THREAD -gt $${#WORKLOAD[*]}; then \ |
---|
170 | $(ECHO) "Error : The number of bench in the workload ($${#WORKLOAD[*]}) is < at the number of thread ($$NB_THREAD)"; \ |
---|
171 | exit; \ |
---|
172 | fi; \ |
---|
173 | $(ECHO) ""; \ |
---|
174 | $(ECHO) "Generate the workload"; \ |
---|
175 | \ |
---|
176 | declare -i NB_ITERATION=1; \ |
---|
177 | CPT=$$(($$NB_THREAD+1)); \ |
---|
178 | while $(TEST) $$CPT -le $${#WORKLOAD[*]}; do \ |
---|
179 | NB_ITERATION=$$(($$NB_ITERATION*$$CPT)); \ |
---|
180 | CPT=$$(($$CPT+1)); \ |
---|
181 | done; \ |
---|
182 | CPT=$$(($${#WORKLOAD[*]}-$$NB_THREAD)); \ |
---|
183 | while $(TEST) $$CPT -gt 0; do \ |
---|
184 | NB_ITERATION=$$(($$NB_ITERATION/$$CPT)); \ |
---|
185 | CPT=$$(($$CPT-1)); \ |
---|
186 | done; \ |
---|
187 | $(ECHO) " * $$NB_ITERATION Workloads (n!/(p!*(n-p)!))"; \ |
---|
188 | \ |
---|
189 | declare -a -i PTR; \ |
---|
190 | CPT=1; \ |
---|
191 | while $(TEST) $$CPT -le $$NB_THREAD; do \ |
---|
192 | PTR[$$CPT]=$$(($$NB_THREAD-$$CPT+1)); \ |
---|
193 | CPT=$$(($$CPT+1)); \ |
---|
194 | done; \ |
---|
195 | \ |
---|
196 | CPT=0; \ |
---|
197 | declare -i IT; \ |
---|
198 | declare -a -i OVF; \ |
---|
199 | declare -a -i NB_OVF; \ |
---|
200 | rm -f $(FILE_WORKLOAD_LOG); \ |
---|
201 | \ |
---|
202 | while $(TEST) $$CPT -lt $$NB_ITERATION; do \ |
---|
203 | declare COMMAND="$$NB_THREAD\n"; \ |
---|
204 | $(ECHO) -ne " - [$$CPT]\t"; \ |
---|
205 | \ |
---|
206 | OVF[0]=0; \ |
---|
207 | NB_OVF=0; \ |
---|
208 | if $(TEST) $${PTR[1]} -ge $${#WORKLOAD[*]}; then \ |
---|
209 | OVF[0]=1; \ |
---|
210 | fi; \ |
---|
211 | \ |
---|
212 | declare WORKLOAD_CURRENT=""; \ |
---|
213 | IT=1; \ |
---|
214 | while $(TEST) $$IT -le $$NB_THREAD; do \ |
---|
215 | WORKLOAD_CURRENT="$${WORKLOAD_CURRENT} $${BENCHS[$${WORKLOAD[$${PTR[$$IT]}]}]}";\ |
---|
216 | $(ECHO) -ne " $${BENCHS[$${WORKLOAD[$${PTR[$$IT]}]}]}\t"; \ |
---|
217 | \ |
---|
218 | COMMAND="$${COMMAND}$$(($${WORKLOAD[$${PTR[$$IT]}]}+1))\n"; \ |
---|
219 | OVF[$$(($$IT))]=0; \ |
---|
220 | if $(TEST) $${OVF[$$(($$IT-1))]} -eq 1 ; then \ |
---|
221 | if $(TEST) $$(($${PTR[$$IT]}+$$NB_OVF)) -ge $${#WORKLOAD[*]}; then \ |
---|
222 | OVF[$$IT]=1; \ |
---|
223 | NB_OVF=$$(($$NB_OVF+1)); \ |
---|
224 | fi; \ |
---|
225 | fi; \ |
---|
226 | \ |
---|
227 | IT=$$(($$IT+1)); \ |
---|
228 | done; \ |
---|
229 | echo ""; \ |
---|
230 | \ |
---|
231 | $(ECHO) "$(EXE)_$${CPT}.x : $${WORKLOAD_CURRENT}" >> $(FILE_WORKLOAD_LOG); \ |
---|
232 | $(MAKE) clean; \ |
---|
233 | $(ECHO) -e $${COMMAND} | $(MAKE) define; \ |
---|
234 | $(MAKE) $(DIR_BIN)/$(EXE)_$${CPT}.x; \ |
---|
235 | \ |
---|
236 | PTR[1]=$$(($${PTR[1]}+1)); \ |
---|
237 | IT=$$NB_THREAD; \ |
---|
238 | while $(TEST) $$IT -ge 1; do \ |
---|
239 | if $(TEST) $${OVF[$$IT]} -eq 1 ; then \ |
---|
240 | PTR[$$(($$IT))]=$${PTR[$$(($$IT+1))]}; \ |
---|
241 | fi; \ |
---|
242 | \ |
---|
243 | if $(TEST) $${OVF[$$(($$IT-1))]} -eq 1 ; then \ |
---|
244 | PTR[$$(($$IT))]=$$(($${PTR[$$IT]}+1)); \ |
---|
245 | fi; \ |
---|
246 | IT=$$(($$IT-1)); \ |
---|
247 | done; \ |
---|
248 | \ |
---|
249 | CPT=$$(($$CPT+1)); \ |
---|
250 | done; |
---|