[615] | 1 | #ifdef PASS_PRE1 |
---|
| 2 | #define _AND_ && |
---|
| 3 | #define _OR_ || |
---|
| 4 | #define _NOT_ ! |
---|
| 5 | #define IS_INNER_LAYER (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_LAYER)) |
---|
| 6 | #define IS_INNER_INTERFACE (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_INTERFACE)) |
---|
| 7 | #endif |
---|
| 8 | |
---|
| 9 | #ifdef PASS_PRE2 |
---|
| 10 | |
---|
| 11 | #define BARRIER !$OMP BARRIER |
---|
| 12 | #define IS_INNER_INTERFACE (.NOT. (IS_BOTTOM_LEVEL .OR. IS_TOP_INTERFACE)) |
---|
| 13 | #define KERNEL(name) {% call() define_kernel(#name) %} |
---|
| 14 | #define FORALL_CELLS(...) {% call(lrange,flags) forall_cells(__VA_ARGS__) %} |
---|
| 15 | #define FORALL_CELLS_EXT(...) {% call(lrange,flags) forall_cells(__VA_ARGS__) %} |
---|
[644] | 16 | #define ON_PRIMAL {% call(mesh, degree=0) on_mesh('primal',lrange,flags) %} |
---|
| 17 | #define ON_DUAL {% call(mesh, degree=0) on_mesh('dual',lrange,flags) %} |
---|
| 18 | #define ON_EDGES {% call(mesh, degree=0) on_edges('edge',lrange,flags) %} |
---|
| 19 | #define FORALL_EDGES {% call forall_edges(mesh,degree) %} |
---|
| 20 | #define FORALL_VERTICES {% call forall_vertices(mesh,degree) %} |
---|
| 21 | #define FORALL_TRISK {% call forall_trisk(degree) %} |
---|
[615] | 22 | #define END_BLOCK {% endcall %} |
---|
| 23 | #define SEQUENCE {% call sequence() %} |
---|
| 24 | #define SEQUENCE_EXT {% call sequence() %} |
---|
| 25 | #define PROLOGUE(level) {% call at_level(level) %} |
---|
| 26 | #define EPILOGUE(level) {% call at_level(level) %} |
---|
| 27 | #define BODY(range) {% call(cell_up,cell_down) body(range) %} |
---|
| 28 | |
---|
| 29 | #define CST_IF(condition, action) {{ cst_if(#condition, #action) }} |
---|
| 30 | #define CST_IFTHEN(condition) {{flat}}if condition |
---|
| 31 | #define CST_ELSEIF(condition) {{flat}}elif condition |
---|
| 32 | #define CST_ELSE {{flat}}else |
---|
| 33 | #define CST_ENDIF {{flat}}endif |
---|
| 34 | |
---|
| 35 | #endif |
---|
| 36 | |
---|
| 37 | #ifdef PASS_JINJA |
---|
| 38 | |
---|
| 39 | {# -------------------------- Design notes ------------------------------ |
---|
| 40 | |
---|
[644] | 41 | The syntax |
---|
| 42 | {% call(ARGNAMES) macro(ARGS) %} |
---|
| 43 | ... |
---|
| 44 | {% endcall %} |
---|
| 45 | passes ARGS to macro ; this macro "calls" the body using the syntax 'caller(arg1,...)' ; these arguments |
---|
| 46 | are available in the body under the names ARGNAMES, as if it were a macro caller(ARGNAMES). |
---|
| 47 | |
---|
[615] | 48 | Using its optional argument 'options', forall_cells() sets variable 'flags' |
---|
| 49 | and passes it on to on_mesh() / on_edges() |
---|
| 50 | |
---|
| 51 | Similarly variable 'lrange' is passed from forall_cells to on_mesh() / on_egdes() |
---|
| 52 | |
---|
| 53 | -------------------------------------------------------------------------- #} |
---|
| 54 | |
---|
[644] | 55 | |
---|
[615] | 56 | {# ----------------------- SEQUENCE, FORALL ----------------------- #} |
---|
| 57 | |
---|
| 58 | {% macro sequence() -%} |
---|
| 59 | |
---|
| 60 | !$OMP DO SCHEDULE(STATIC) |
---|
| 61 | DO ij=1,primal_num |
---|
| 62 | {{ caller() }} |
---|
| 63 | END DO |
---|
| 64 | !$OMP END DO |
---|
| 65 | |
---|
| 66 | {%- endmacro %} |
---|
| 67 | |
---|
| 68 | {% macro body(range) -%} |
---|
| 69 | {{ define('CELL','l,ij') }} |
---|
| 70 | DO l = {{ range }} |
---|
| 71 | {{ caller() }} |
---|
| 72 | END DO |
---|
| 73 | {{ undef('CELL') }} |
---|
| 74 | {%- endmacro %} |
---|
| 75 | |
---|
| 76 | {% macro at_level(lev) -%} |
---|
| 77 | {{ define('CELL','l,ij') }} |
---|
| 78 | l={{ lev }} |
---|
| 79 | {{ caller() }} |
---|
| 80 | {{ undef('CELL') }} |
---|
| 81 | {%- endmacro %} |
---|
| 82 | |
---|
| 83 | {% macro forall_cells(start='1', end='llm', options=[]) -%} |
---|
| 84 | {% set flags=[options] if options is string else options %} |
---|
| 85 | {{ caller((start,end),flags) }} |
---|
| 86 | {%- endmacro %} |
---|
| 87 | |
---|
| 88 | {# ------------------------------ MESHES --------------------------- #} |
---|
| 89 | |
---|
[647] | 90 | {% macro get_edges(thecode, mesh,degree) %} |
---|
| 91 | {% for iedge in range(1,degree+1) %} |
---|
| 92 | {{ 'edge%d = %s_edge(%d,ij)'%(iedge,mesh,iedge) }} |
---|
| 93 | {% endfor %} |
---|
| 94 | {% for iedge in range(1,degree+1) %} |
---|
| 95 | {{ 'le_de%d = le_de(edge%d)'%(iedge,iedge) }} |
---|
| 96 | {% endfor %} |
---|
| 97 | {% for iedge in range(1,degree+1) %} |
---|
| 98 | {{ 'sign%d = %s_ne(%d,ij)'%(iedge,mesh,iedge) }} |
---|
| 99 | {% endfor %} |
---|
| 100 | {% for iedge in range(1,degree+1) %} |
---|
| 101 | {{ 'ij_up%d = up(edge%d)'%(iedge,iedge) if 'VERTEX1' in thecode }} |
---|
| 102 | {% endfor %} |
---|
| 103 | {% for iedge in range(1,degree+1) %} |
---|
| 104 | {{ 'ij_down%d = down(edge%d)'%(iedge,iedge) if 'VERTEX2' in thecode }} |
---|
| 105 | {% endfor %} |
---|
| 106 | {% endmacro %} |
---|
| 107 | |
---|
[644] | 108 | {# argument 'code' is the body enclosed by ON_XXX ... END_BLOCK ; it takes arguments : mesh,degree=0 #} |
---|
| 109 | |
---|
| 110 | {% macro vloop_unroll(mesh, lrange, flags, code) %} |
---|
| 111 | |
---|
| 112 | {% set thecode, has_primal, has_dual, has_trisk, has_none = code(mesh), False, False, False, True %} |
---|
| 113 | |
---|
| 114 | {% if 'primal_deg' in thecode %} |
---|
| 115 | ! this VLOOP iterates over primal cell edges |
---|
| 116 | {% set has_primal, has_none = True,False %} |
---|
| 117 | {% endif %} |
---|
| 118 | {% if 'dual_deg' in thecode %} |
---|
| 119 | ! this VLOOP iterates over dual cell edges |
---|
| 120 | {% set has_dual,has_none = True,False %} |
---|
| 121 | {% endif %} |
---|
| 122 | {% if 'trisk_deg' in thecode %} |
---|
| 123 | ! this VLOOP iterates over the TRISK stencil |
---|
| 124 | {% set has_trisk,has_none = True,False %} |
---|
| 125 | {% endif %} |
---|
| 126 | |
---|
| 127 | {% if has_none %} |
---|
| 128 | {{ vloop(mesh, lrange, flags, code) }} |
---|
| 129 | {% endif %} |
---|
| 130 | |
---|
| 131 | {% if has_primal %} |
---|
| 132 | SELECT CASE(primal_deg(ij)) |
---|
| 133 | CASE(4) |
---|
[647] | 134 | {{ get_edges(thecode, mesh, 4) }} |
---|
[644] | 135 | {{ vloop(mesh, lrange, flags, code, 4) }} |
---|
| 136 | CASE(5) |
---|
[647] | 137 | {{ get_edges(thecode, mesh, 5) }} |
---|
[644] | 138 | {{ vloop(mesh, lrange, flags, code, 5) }} |
---|
| 139 | CASE(6) |
---|
[647] | 140 | {{ get_edges(thecode, mesh, 6) }} |
---|
[644] | 141 | {{ vloop(mesh, lrange, flags, code, 6) }} |
---|
| 142 | CASE DEFAULT |
---|
| 143 | {{ vloop(mesh, lrange, flags, code) }} |
---|
| 144 | END SELECT |
---|
| 145 | {% endif %} |
---|
| 146 | |
---|
| 147 | {% if has_dual %} |
---|
| 148 | SELECT CASE(dual_deg(ij)) |
---|
| 149 | CASE(3) |
---|
| 150 | {{ vloop(mesh, lrange, flags, code, 3) }} |
---|
| 151 | CASE(4) |
---|
| 152 | {{ vloop(mesh, lrange, flags, code, 4) }} |
---|
| 153 | CASE DEFAULT |
---|
| 154 | {{ vloop(mesh, lrange, flags, code) }} |
---|
| 155 | END SELECT |
---|
| 156 | {% endif %} |
---|
| 157 | |
---|
| 158 | {% if has_trisk %} |
---|
| 159 | SELECT CASE(trisk_deg(edge)) |
---|
| 160 | CASE(10) |
---|
| 161 | {{ vloop(mesh, lrange, flags, code, 10) }} |
---|
| 162 | CASE(4) |
---|
| 163 | {{ vloop(mesh, lrange, flags, code, 4) }} |
---|
| 164 | CASE DEFAULT |
---|
| 165 | {{ vloop(mesh, lrange, flags, code) }} |
---|
| 166 | END SELECT |
---|
| 167 | {% endif %} |
---|
| 168 | |
---|
| 169 | {%- endmacro %} |
---|
| 170 | |
---|
| 171 | {% macro vloop(mesh, lrange, flags, code, degree=0) %} |
---|
| 172 | |
---|
[615] | 173 | {% set start,end = lrange %} |
---|
[644] | 174 | {% set thecode, is_top_layer, is_top_inter = code(mesh,degree), False, False %} |
---|
[615] | 175 | |
---|
| 176 | {{ define('IS_TOP_LAYER', '_FALSE_') }} |
---|
| 177 | {{ define('IS_TOP_INTERFACE', '_FALSE_') }} |
---|
| 178 | |
---|
| 179 | {% if 'IS_BOTTOM_LEVEL' in thecode or 'KDOWN' in thecode%} |
---|
| 180 | {# the code in the loop checks whether l==1, for the sake of performance |
---|
| 181 | we shall write special code for l=1 and start the loop at l=2 #} |
---|
| 182 | {{ define('IS_BOTTOM_LEVEL', '_TRUE_') }} |
---|
| 183 | {{ 'kdown = 1' if 'KDOWN' in thecode }} |
---|
| 184 | {{ 'kup = 1' if 'KUP' in thecode }} |
---|
| 185 | l=1 |
---|
| 186 | {{ thecode }} |
---|
| 187 | {% set start='2' %} |
---|
| 188 | {% endif %} |
---|
| 189 | |
---|
| 190 | {% if 'IS_TOP_LAYER' in thecode %} |
---|
| 191 | {{ 'ERROR : using IS_TOP_LAYER in a loop ending at l=llm+1' if end=='llm+1' }} |
---|
| 192 | {# the code checks whether l==llm, write special code for l=llm and end the loop at l=llm-1 #} |
---|
| 193 | {% set end, is_top_layer = 'llm-1', True %} |
---|
| 194 | {% endif %} |
---|
| 195 | |
---|
| 196 | {% if 'IS_TOP_INTERFACE' in thecode or 'KUP' in thecode %} |
---|
| 197 | {# the code checks whether l==llm+1, write special code for l=llm+1 and end the loop at l=llm #} |
---|
| 198 | {{ 'ERROR : using IS_TOP_INTERFACE in a loop ending at l=llm' if end=='llm' }} |
---|
| 199 | {% set end, is_top_inter ='llm', True %} |
---|
| 200 | {% endif %} |
---|
| 201 | |
---|
| 202 | {{ define('IS_BOTTOM_LEVEL', '_FALSE_') }} |
---|
[647] | 203 | !DIR$ SIMD |
---|
[615] | 204 | DO l = {{start}}, {{end}} |
---|
| 205 | {{ 'kdown = l-1' if 'KDOWN' in thecode }} |
---|
| 206 | {{ 'kup = l' if 'KUP' in thecode }} |
---|
| 207 | {{ thecode }} |
---|
| 208 | END DO |
---|
| 209 | |
---|
| 210 | {% if is_top_layer %} |
---|
| 211 | {{ define('IS_TOP_LAYER', '_TRUE_') }} |
---|
| 212 | {{ 'kdown = llm-1' if 'KDOWN' in thecode }} |
---|
| 213 | {{ 'kup = llm' if 'KUP' in thecode }} |
---|
| 214 | l=llm |
---|
| 215 | {{ thecode }} |
---|
| 216 | {% endif %} |
---|
| 217 | |
---|
| 218 | {% if is_top_inter %} |
---|
| 219 | {{ define('IS_TOP_INTERFACE', '_TRUE_') }} |
---|
| 220 | {{ 'kdown = llm' if 'KDOWN' in thecode }} |
---|
| 221 | {{ 'kup = llm' if 'KUP' in thecode }} |
---|
| 222 | l=llm+1 |
---|
| 223 | {{ thecode }} |
---|
| 224 | {% endif %} |
---|
| 225 | |
---|
| 226 | {% endmacro %} |
---|
| 227 | |
---|
| 228 | {% macro on_mesh(mesh,lrange,flags) -%} |
---|
| 229 | {{ define('CELL','l,ij') if mesh=='primal' }} |
---|
| 230 | {{ define('DUAL_CELL', 'l,ij') if mesh=='dual'}} |
---|
| 231 | !$OMP DO SCHEDULE(STATIC) |
---|
| 232 | DO ij = 1, {{ mesh }}_num |
---|
[644] | 233 | {{ vloop_unroll(mesh, lrange, flags, caller) }} |
---|
[615] | 234 | END DO |
---|
| 235 | !$OMP END DO |
---|
| 236 | {{ undef('CELL') }} |
---|
| 237 | {{ undef('DUAL_CELL') }} |
---|
| 238 | {%- endmacro %} |
---|
| 239 | |
---|
| 240 | {# ------------------------------ STENCILS --------------------------- #} |
---|
| 241 | |
---|
| 242 | {% macro on_edges(mesh,lrange,flags) -%} |
---|
| 243 | {% set thecode = caller(mesh) %} |
---|
| 244 | {{ define('EDGE', 'l,edge') }} |
---|
| 245 | {{ define('LE_DE', 'le_de(edge)') }} |
---|
| 246 | {{ define('SIGN', '1.') }} |
---|
| 247 | {{ define('CELL1', 'l,ij_left') }} |
---|
| 248 | {{ define('CELL2', 'l,ij_right') }} |
---|
| 249 | {{ define('VERTEX1', 'l,ij_down') }} |
---|
| 250 | {{ define('VERTEX2', 'l,ij_up') }} |
---|
| 251 | !$OMP DO SCHEDULE(STATIC) |
---|
| 252 | DO edge = 1, edge_num |
---|
| 253 | {{ 'ij_left = left(edge)' if 'CELL1' in thecode }} |
---|
| 254 | {{ 'ij_right = right(edge)' if 'CELL2' in thecode }} |
---|
| 255 | {{ 'ij_up = up(edge)' if 'VERTEX1' in thecode }} |
---|
| 256 | {{ 'ij_down = down(edge)' if 'VERTEX2' in thecode }} |
---|
[644] | 257 | {{ vloop_unroll(mesh, lrange, flags, caller) }} |
---|
[615] | 258 | END DO |
---|
| 259 | !$OMP END DO |
---|
| 260 | {{ undef('EDGE') }} |
---|
| 261 | {{ undef('LE_DE') }} |
---|
| 262 | {{ undef('SIGN') }} |
---|
| 263 | {{ undef('CELL1') }} |
---|
| 264 | {{ undef('CELL2') }} |
---|
| 265 | {{ undef('VERTEX1') }} |
---|
| 266 | {{ undef('VERTEX2') }} |
---|
| 267 | {%- endmacro %} |
---|
| 268 | |
---|
[644] | 269 | {% macro forall_edges(mesh,degree) -%} |
---|
[615] | 270 | {% set thecode = caller() %} |
---|
[644] | 271 | |
---|
| 272 | {% if degree>1 %} |
---|
| 273 | {% for iedge in range(1,degree+1) %} |
---|
[647] | 274 | {{ define('EDGE', 'l,edge%d'%iedge) }} |
---|
| 275 | {{ define('SIGN', 'sign%d'%iedge) }} |
---|
| 276 | {{ define('LE_DE', 'le_de%d'%iedge) }} |
---|
| 277 | {{ define('VERTEX1', 'l,ij_up%d'%iedge) }} |
---|
| 278 | {{ define('VERTEX2', 'l,ij_down%d'%iedge) }} |
---|
[644] | 279 | {{ thecode }} |
---|
| 280 | {% endfor %} |
---|
| 281 | {% else %} |
---|
[647] | 282 | {{ define('EDGE', 'l,edge') }} |
---|
| 283 | {{ define('SIGN', mesh + '_ne(iedge,ij)') }} |
---|
| 284 | {{ define('LE_DE', 'le_de(edge)') }} |
---|
| 285 | {{ define('VERTEX1', 'l,ij_up') }} |
---|
| 286 | {{ define('VERTEX2', 'l,ij_down') }} |
---|
[615] | 287 | DO iedge = 1, {{ mesh }}_deg(ij) |
---|
| 288 | edge = {{ mesh }}_edge(iedge,ij) |
---|
[644] | 289 | {{ 'ij_up = up(edge)' if 'VERTEX1' in thecode }} |
---|
| 290 | {{ 'ij_down = down(edge)' if 'VERTEX2' in thecode }} |
---|
[615] | 291 | {{ thecode }} |
---|
| 292 | END DO |
---|
[644] | 293 | {% endif %} |
---|
| 294 | |
---|
[615] | 295 | {{ undef('EDGE') }} |
---|
| 296 | {{ undef('SIGN') }} |
---|
| 297 | {{ undef('LE_DE') }} |
---|
[647] | 298 | {{ undef('VERTEX1') }} |
---|
| 299 | {{ undef('VERTEX2') }} |
---|
[615] | 300 | {%- endmacro %} |
---|
| 301 | |
---|
[644] | 302 | {% macro forall_trisk(degree) -%} |
---|
| 303 | {% set thecode = caller() %} |
---|
[615] | 304 | {{ define('EDGE_TRISK', 'l,edge_trisk') }} |
---|
[644] | 305 | {% if degree>1 %} |
---|
| 306 | {% for itrisk in range(1,degree+1) %} |
---|
[647] | 307 | itrisk = {{ itrisk }} |
---|
[644] | 308 | edge_trisk = trisk({{ itrisk }},edge) |
---|
| 309 | {{ thecode }} |
---|
| 310 | {% endfor %} |
---|
| 311 | {% else %} |
---|
[615] | 312 | DO itrisk = 1, trisk_deg(edge) |
---|
| 313 | edge_trisk = trisk(itrisk,edge) |
---|
[644] | 314 | {{ thecode }} |
---|
[615] | 315 | END DO |
---|
[644] | 316 | {% endif %} |
---|
[615] | 317 | {{ undef('EDGE_TRISK') }} |
---|
| 318 | {%- endmacro %} |
---|
| 319 | |
---|
[644] | 320 | {% macro forall_vertices(mesh,degree) -%} |
---|
| 321 | {% set thecode = caller() %} |
---|
[615] | 322 | {{ define('VERTEX', 'l,vertex') }} |
---|
[644] | 323 | {% if degree>1 %} |
---|
| 324 | {% for ivertex in range(1,degree+1) %} |
---|
| 325 | ivertex = {{ ivertex }} |
---|
| 326 | vertex = {{ mesh }}_vertex({{ ivertex }},ij) |
---|
| 327 | {{ thecode }} |
---|
| 328 | {% endfor %} |
---|
| 329 | {% else %} |
---|
[615] | 330 | DO ivertex = 1, {{ mesh }}_deg(ij) |
---|
| 331 | vertex = {{ mesh }}_vertex(ivertex,ij) |
---|
[644] | 332 | {{ thecode }} |
---|
[615] | 333 | END DO |
---|
[644] | 334 | {% endif %} |
---|
[615] | 335 | {{ undef('VERTEX') }} |
---|
| 336 | {%- endmacro %} |
---|
| 337 | |
---|
| 338 | {# --------------------------------------------------------- #} |
---|
| 339 | |
---|
| 340 | {% set llm='llm' %} |
---|
| 341 | |
---|
| 342 | {{ undef('SIGN') }} |
---|
| 343 | {{ undef('CELL') }} |
---|
| 344 | {{ undef('CELL1') }} |
---|
| 345 | {{ undef('CELL2') }} |
---|
| 346 | {{ undef('VERTEX1') }} |
---|
| 347 | {{ undef('VERTEX2') }} |
---|
| 348 | {{ undef('EDGE_TRISK') }} |
---|
| 349 | |
---|
| 350 | {# --------------------- END JINJA ------------------------- #} |
---|
| 351 | |
---|
| 352 | #endif |
---|
| 353 | |
---|
| 354 | #ifdef PASS_POST1 |
---|
| 355 | |
---|
| 356 | #define _TRUE_ (0==0) |
---|
| 357 | #define _FALSE_ (0==1) |
---|
| 358 | |
---|
| 359 | #define RIV2 Riv2(ivertex,ij) |
---|
| 360 | #define AI Ai(ij) |
---|
| 361 | #define AV Av(ij) |
---|
| 362 | #define FV fv(ij) |
---|
| 363 | #define WEE wee(itrisk,edge) |
---|
| 364 | #define edge_ne(iedge,ij) 1. |
---|
| 365 | #endif |
---|
| 366 | |
---|
| 367 | #ifdef PASS_POST2 |
---|
| 368 | #define KUP(l,ij) kup,ij |
---|
| 369 | #define KDOWN(l,ij) kdown,ij |
---|
| 370 | #define DOWN(l,ij) l-1,ij |
---|
| 371 | #define UP(l,ij) l+1,ij |
---|
| 372 | #define HIDX(l,ij) ij |
---|
| 373 | #define VIDX(l,ij) l |
---|
| 374 | #endif |
---|