1 | #ifdef PASS_PRE1 |
---|
2 | |
---|
3 | #define _AND_ && |
---|
4 | #define _OR_ || |
---|
5 | #define _NOT_ ! |
---|
6 | #define IS_INNER_LAYER (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_LAYER)) |
---|
7 | #define IS_INNER_INTERFACE (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_INTERFACE)) |
---|
8 | |
---|
9 | #define CELL ij,LL |
---|
10 | #define VERTEX1 ij+{{vertex1}},LL |
---|
11 | #define VERTEX2 ij+{{vertex2}},LL |
---|
12 | #define EDGE ij+{{edge}},LL |
---|
13 | #define EDGE_TRISK ij+{{edge_trisk}},LL |
---|
14 | #define DUAL_CELL ij+{{triangle}},LL |
---|
15 | #define CELL1 ij,LL |
---|
16 | #define CELL2 ij+{{neighbour}},LL |
---|
17 | #define VERTEX {{vertex}},LL |
---|
18 | #define SIGN {{sign}} |
---|
19 | #define LE_DE le_de(ij+{{edge}}) |
---|
20 | #define WEE wee(ij+{{edge}},{{itrisk}}) |
---|
21 | #define DE de(ij+{{edge}}) |
---|
22 | #define LE le(ij+{{edge}}) |
---|
23 | #define RIV2 Riv2({{vertex}},{{vertex_dir}}) |
---|
24 | #define AI Ai(ij) |
---|
25 | #define FV fv(ij+{{triangle}}) |
---|
26 | #define AV Av(ij+{{triangle}}) |
---|
27 | |
---|
28 | #endif |
---|
29 | |
---|
30 | #ifdef PASS_PRE2 |
---|
31 | |
---|
32 | #ifdef HEX_MASTER |
---|
33 | #define BARRIER |
---|
34 | #else |
---|
35 | #define BARRIER !$OMP BARRIER |
---|
36 | #endif |
---|
37 | |
---|
38 | #define KERNEL(name) {% call define_kernel(#name) %} |
---|
39 | #define FORALL_CELLS(...) {% call forall_cells(__VA_ARGS__) %} |
---|
40 | #define FORALL_CELLS_EXT(...) {% call forall_cells_ext(__VA_ARGS__) %} |
---|
41 | #define ON_PRIMAL {% call(forall_edges) on_hexagons() %} |
---|
42 | #define ON_DUAL {% call(triangle,forall_edges,forall_vertices) on_triangles() %} |
---|
43 | #define ON_EDGES {% call(edge,neighbour,sign,vertex1,vertex2,forall_trisk) on_edges() %} |
---|
44 | #define FORALL_EDGES {% call(edge,sign,vertex1,vertex2) forall_edges() %} |
---|
45 | #define FORALL_VERTICES {% call(vertex,vertex_dir) forall_vertices() %} |
---|
46 | #define FORALL_TRISK {% call(itrisk,edge_trisk) forall_trisk() %} |
---|
47 | #define END_BLOCK {% endcall %} |
---|
48 | #define SEQUENCE_C0 {% call(body,at_level,ext) sequence() %} |
---|
49 | #define SEQUENCE_C1 {% call(body,at_level,ext) sequence_ext() %} |
---|
50 | #define SEQUENCE_E0 {% call(body,at_level,ext) sequence_edge() %} |
---|
51 | #define PROLOGUE(level) {% call(edge,neighbour) at_level(level,ext) %} |
---|
52 | #define BODY(range){% call(edge,neighbour) body(range,ext) %} |
---|
53 | #define EPILOGUE(level){% call(edge,neighbour) at_level(level,ext) %} |
---|
54 | |
---|
55 | #define CST_IF(condition, action) {{ cst_if(#condition, #action) }} |
---|
56 | #define CST_IFTHEN(condition) {{flat}}if condition |
---|
57 | #define CST_ELSEIF(condition) {{flat}}elif condition |
---|
58 | #define CST_ELSE {{flat}}else |
---|
59 | #define CST_ENDIF {{flat}}endif |
---|
60 | |
---|
61 | #endif |
---|
62 | |
---|
63 | #if PASS_JINJA |
---|
64 | |
---|
65 | #ifdef HEX_MASTER |
---|
66 | |
---|
67 | {% set ll_begin, ll_beginp1 = '1', '2' %} |
---|
68 | {% set ll_endm1, ll_end, ll_endp1 = 'llm-1', 'llm', 'llm+1' %} |
---|
69 | {% macro ij_omp(ext) -%} |
---|
70 | ij_begin{{ext}},ij_end{{ext}} |
---|
71 | {%- endmacro %} |
---|
72 | |
---|
73 | #else |
---|
74 | |
---|
75 | {% set ll_begin, ll_beginp1 = 'll_begin', 'll_beginp1' %} |
---|
76 | {% set ll_endm1, ll_end, ll_endp1 = 'll_endm1', 'll_end', 'll_endp1' %} |
---|
77 | {% macro ij_omp(ext) -%} |
---|
78 | ij_omp_begin{{ext}},ij_omp_end{{ext}} |
---|
79 | {%- endmacro %} |
---|
80 | |
---|
81 | #endif |
---|
82 | |
---|
83 | {% macro sequence() -%} |
---|
84 | {{ caller(body_primal,at_level_primal,'') }} |
---|
85 | {%- endmacro %} |
---|
86 | |
---|
87 | {% macro sequence_ext() -%} |
---|
88 | {{ caller(body_primal,at_level_primal,'_ext') }} |
---|
89 | {%- endmacro %} |
---|
90 | |
---|
91 | {% macro at_level_primal(lev,ext) -%} |
---|
92 | {{ define('LL', lev) }} |
---|
93 | !DIR$ SIMD |
---|
94 | DO ij={{ ij_omp(ext) }} |
---|
95 | {{ caller() }} |
---|
96 | END DO |
---|
97 | {%- endmacro %} |
---|
98 | |
---|
99 | {% macro body_primal(range,ext) -%} |
---|
100 | {{ define('LL', 'l') }} |
---|
101 | DO l = {{ range }} |
---|
102 | !DIR$ SIMD |
---|
103 | DO ij={{ ij_omp(ext) }} |
---|
104 | {{ caller() }} |
---|
105 | END DO |
---|
106 | END DO |
---|
107 | {%- endmacro %} |
---|
108 | |
---|
109 | {% macro sequence_edge() -%} |
---|
110 | {{ caller(body_edge,at_level_edge,'') }} |
---|
111 | {%- endmacro %} |
---|
112 | |
---|
113 | {% macro at_level_edge(lev,ext) -%} |
---|
114 | {{ define('LL', lev) }} |
---|
115 | !DIR$ SIMD |
---|
116 | DO ij={{ ij_omp(ext) }} |
---|
117 | {{ caller('u_right','t_right') }} |
---|
118 | {{ caller('u_lup','t_lup') }} |
---|
119 | {{ caller('u_ldown','t_ldown') }} |
---|
120 | END DO |
---|
121 | {%- endmacro %} |
---|
122 | |
---|
123 | {% macro body_edge(range,ext) -%} |
---|
124 | {{ define('LL', 'l') }} |
---|
125 | DO l = {{ range }} |
---|
126 | !DIR$ SIMD |
---|
127 | DO ij={{ ij_omp(ext) }} |
---|
128 | {{ caller('u_right','t_right') }} |
---|
129 | {{ caller('u_lup','t_lup') }} |
---|
130 | {{ caller('u_ldown','t_ldown') }} |
---|
131 | END DO |
---|
132 | END DO |
---|
133 | {%- endmacro %} |
---|
134 | |
---|
135 | {#---------------------- big macro generating nested DO loops -------------------------#} |
---|
136 | {# specialized code is generated for l=1 and l=llm,llm+1 if necessary #} |
---|
137 | {# start/end values for l are replaced by corresponding OpenMP values #} |
---|
138 | |
---|
139 | {% macro define_levels(ll,kdown,kup,thecode) %} |
---|
140 | {{ define('LL', ll) }} |
---|
141 | {{ define_cppmacro('KDOWN','(ij,ll)', kdown) if 'KDOWN' in thecode }} |
---|
142 | {{ define_cppmacro('KUP','(ij,ll)', kup) if 'KUP' in thecode }} |
---|
143 | {%- endmacro %} |
---|
144 | |
---|
145 | {% macro forall(start,end,ij_range,thecode) %} |
---|
146 | {% set start_omp={'1':ll_begin , '2':ll_beginp1}[start] %} |
---|
147 | {% set end_omp={'llm-1':ll_endm1 , 'llm':ll_end, 'llm+1':ll_endp1}[end] %} |
---|
148 | {% set is_top_layer, is_top_inter = False, False %} |
---|
149 | |
---|
150 | {{ define('IS_TOP_LAYER', '_FALSE_') }} |
---|
151 | {{ define('IS_TOP_INTERFACE', '_FALSE_') }} |
---|
152 | |
---|
153 | {% if 'IS_BOTTOM_LEVEL' in thecode or 'KDOWN' in thecode%} |
---|
154 | {{ 'ERROR : using IS_BOTTOM_LEVEL in a loop starting at l=2' if start=='2' }} |
---|
155 | {# the code in the loop checks whether l==1, for the sake of performance |
---|
156 | we shall write special code for l=1 and start the loop at l=2 #} |
---|
157 | |
---|
158 | IF ({{ll_begin}}==1) THEN |
---|
159 | {{ define('IS_BOTTOM_LEVEL', '_TRUE_') }} |
---|
160 | {{ define_levels('1', 'ij,1', 'ij,1', thecode) }} |
---|
161 | !DIR$ SIMD |
---|
162 | DO ij={{ij_range}} |
---|
163 | {{ thecode }} |
---|
164 | END DO |
---|
165 | END IF |
---|
166 | {% set start_omp=ll_beginp1 %} |
---|
167 | {% endif %} |
---|
168 | |
---|
169 | {% if 'IS_TOP_LAYER' in thecode %} |
---|
170 | {{ 'ERROR : using _IS_TOP_LAYER_ in a loop ending at l=llm+1' if end=='llm+1' }} |
---|
171 | {# the code checks whether l==llm, write special code for l=llm and end the loop at l=llm-1 #} |
---|
172 | {% set end_omp, is_top_layer = ll_endm1, True %} |
---|
173 | {% endif %} |
---|
174 | |
---|
175 | {% if 'IS_TOP_INTERFACE' in thecode or 'KUP' in thecode %} |
---|
176 | {# the code checks whether l==llm+1, write special code for l=llm+1 and end the loop at l=llm #} |
---|
177 | {{ 'ERROR : using _IS_TOP_INTERFACE_ in a loop ending at l=llm' if end=='llm' }} |
---|
178 | {% set end_omp, is_top_inter = ll_end, True %} |
---|
179 | {% endif %} |
---|
180 | |
---|
181 | {{ define('IS_BOTTOM_LEVEL', '_FALSE_') }} |
---|
182 | {{ define_levels('l', 'ij,l-1', 'ij,l', thecode) }} |
---|
183 | DO l = {{start_omp}}, {{end_omp}} |
---|
184 | !DIR$ SIMD |
---|
185 | DO ij={{ij_range}} |
---|
186 | {{ thecode }} |
---|
187 | END DO |
---|
188 | END DO |
---|
189 | |
---|
190 | {% if is_top_layer %} |
---|
191 | IF({{ll_end}}==llm) THEN |
---|
192 | {{ define('IS_TOP_LAYER', '_TRUE_') }} |
---|
193 | {{ define_levels('llm', 'ij,llm-1', 'ij,llm', thecode) }} |
---|
194 | !DIR$ SIMD |
---|
195 | DO ij={{ij_range}} |
---|
196 | {{ thecode }} |
---|
197 | END DO |
---|
198 | END IF |
---|
199 | {% endif %} |
---|
200 | |
---|
201 | {% if is_top_inter %} |
---|
202 | IF({{ll_endp1}}==llm+1) THEN |
---|
203 | {{ define('IS_TOP_INTERFACE', '_TRUE_') }} |
---|
204 | {{ define_levels('llm+1', 'ij,llm', 'ij,llm', thecode) }} |
---|
205 | !DIR$ SIMD |
---|
206 | DO ij={{ij_range}} |
---|
207 | {{ thecode }} |
---|
208 | END DO |
---|
209 | END IF |
---|
210 | {% endif %} |
---|
211 | |
---|
212 | {% endmacro %} |
---|
213 | |
---|
214 | {#-------------------------------------------------------------------------------------#} |
---|
215 | |
---|
216 | {% macro forall_cells(start='1', end='llm') -%} |
---|
217 | {{ forall(start,end,'ij_begin, ij_end', caller()) }} |
---|
218 | {% endmacro %} |
---|
219 | |
---|
220 | {% macro forall_cells_ext(start='1', end='llm') -%} |
---|
221 | {{ forall(start,end,'ij_begin_ext, ij_end_ext', caller()) }} |
---|
222 | {% endmacro %} |
---|
223 | |
---|
224 | {% macro forall_edges_hex() -%} |
---|
225 | {{ caller('u_rup','ne_rup', 'z_rup','z_up') }} |
---|
226 | {{ caller('u_lup','ne_lup', 'z_lup','z_up') }} |
---|
227 | {{ caller('u_left','ne_left','z_lup','z_ldown') }} |
---|
228 | {{ caller('u_ldown','ne_ldown', 'z_ldown','z_down') }} |
---|
229 | {{ caller('u_rdown','ne_rdown', 'z_rdown','z_down') }} |
---|
230 | {{ caller('u_right','ne_right', 'z_rup','z_rdown') }} |
---|
231 | {%- endmacro %} |
---|
232 | |
---|
233 | {% macro on_hexagons() -%} |
---|
234 | {{ caller(forall_edges_hex) }} |
---|
235 | {%- endmacro %} |
---|
236 | |
---|
237 | {% macro forall_edges_zup() -%} |
---|
238 | {{ caller('u_rup','ne_rup', 'TODO','TODO') }} |
---|
239 | {{ caller('t_rup+u_left','ne_left', 'TODO','TODO') }} |
---|
240 | {{ caller('u_lup','(-ne_lup)', 'TODO','TODO') }} |
---|
241 | {%- endmacro %} |
---|
242 | |
---|
243 | {% macro forall_edges_zdown() -%} |
---|
244 | {{ caller('u_rdown','(-ne_rdown)', 'TODO', 'TODO') }} |
---|
245 | {{ caller('t_ldown+u_right','ne_right', 'TODO', 'TODO') }} |
---|
246 | {{ caller('u_ldown','ne_ldown', 'TODO', 'TODO') }} |
---|
247 | {%- endmacro %} |
---|
248 | |
---|
249 | {% macro forall_vertices_zup() -%} |
---|
250 | {{ caller('ij','vup') }} |
---|
251 | {{ caller('ij+t_rup','vldown') }} |
---|
252 | {{ caller('ij+t_lup','vrdown') }} |
---|
253 | {%- endmacro %} |
---|
254 | |
---|
255 | {% macro forall_vertices_zdown() -%} |
---|
256 | {{ caller('ij','vdown') }} |
---|
257 | {{ caller('ij+t_ldown','vrup') }} |
---|
258 | {{ caller('ij+t_rdown','vlup') }} |
---|
259 | {%- endmacro %} |
---|
260 | |
---|
261 | {% macro on_triangles() -%} |
---|
262 | {{ caller('z_up',forall_edges_zup,forall_vertices_zup) }} |
---|
263 | {{ caller('z_down',forall_edges_zdown,forall_vertices_zdown) }} |
---|
264 | {%- endmacro %} |
---|
265 | |
---|
266 | {% macro trisk_right() -%} |
---|
267 | {{ caller('1,1', 'u_rup') }} |
---|
268 | {{ caller('2,1', 'u_lup') }} |
---|
269 | {{ caller('3,1', 'u_left') }} |
---|
270 | {{ caller('4,1', 'u_ldown') }} |
---|
271 | {{ caller('5,1', 'u_rdown') }} |
---|
272 | {{ caller('1,2', 't_right+u_ldown') }} |
---|
273 | {{ caller('2,2', 't_right+u_rdown') }} |
---|
274 | {{ caller('3,2', 't_right+u_right') }} |
---|
275 | {{ caller('4,2', 't_right+u_rup') }} |
---|
276 | {{ caller('5,2', 't_right+u_lup') }} |
---|
277 | {%- endmacro %} |
---|
278 | |
---|
279 | {% macro trisk_lup() -%} |
---|
280 | {{ caller('1,1', 'u_left') }} |
---|
281 | {{ caller('2,1', 'u_ldown') }} |
---|
282 | {{ caller('3,1', 'u_rdown') }} |
---|
283 | {{ caller('4,1', 'u_right') }} |
---|
284 | {{ caller('5,1', 'u_rup') }} |
---|
285 | {{ caller('1,2', 't_lup+u_right') }} |
---|
286 | {{ caller('2,2', 't_lup+u_rup') }} |
---|
287 | {{ caller('3,2', 't_lup+u_lup') }} |
---|
288 | {{ caller('4,2', 't_lup+u_left') }} |
---|
289 | {{ caller('5,2', 't_lup+u_ldown') }} |
---|
290 | {%- endmacro %} |
---|
291 | |
---|
292 | {% macro trisk_ldown() -%} |
---|
293 | {{ caller('1,1', 'u_rdown') }} |
---|
294 | {{ caller('2,1', 'u_right') }} |
---|
295 | {{ caller('3,1', 'u_rup') }} |
---|
296 | {{ caller('4,1', 'u_lup') }} |
---|
297 | {{ caller('5,1', 'u_left') }} |
---|
298 | {{ caller('1,2', 't_ldown+u_lup') }} |
---|
299 | {{ caller('2,2', 't_ldown+u_left') }} |
---|
300 | {{ caller('3,2', 't_ldown+u_ldown') }} |
---|
301 | {{ caller('4,2', 't_ldown+u_rdown') }} |
---|
302 | {{ caller('5,2', 't_ldown+u_right') }} |
---|
303 | {%- endmacro %} |
---|
304 | |
---|
305 | {% macro on_edges() -%} |
---|
306 | {{ caller('u_right','t_right','ne_right','z_rdown','z_rup',trisk_right) }} |
---|
307 | {{ caller('u_lup','t_lup','ne_lup','z_up','z_lup', trisk_lup) }} |
---|
308 | {{ caller('u_ldown','t_ldown','ne_ldown','z_ldown','z_down', trisk_ldown) }} |
---|
309 | {%- endmacro %} |
---|
310 | |
---|
311 | {% set llm = 'llm' %} |
---|
312 | |
---|
313 | #endif |
---|
314 | |
---|
315 | #ifdef PASS_POST1 |
---|
316 | #define _TRUE_ (0==0) |
---|
317 | #define _FALSE_ (0==1) |
---|
318 | #define CELL ij,LL |
---|
319 | #endif |
---|
320 | |
---|
321 | #ifdef PASS_POST2 |
---|
322 | #define UP(ij,l) ij,l+1 |
---|
323 | #define DOWN(ij,l) ij,l-1 |
---|
324 | #define HIDX(ij,l) ij |
---|
325 | #define VIDX(ij,l) l |
---|
326 | #define AT_LEVEL(ij,l,lev) ij,lev |
---|
327 | #endif |
---|