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