#ifdef PASS_PRE1 #define _AND_ && #define _OR_ || #define _NOT_ ! #define IS_INNER_LAYER (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_LAYER)) #define IS_INNER_INTERFACE (_NOT_ (IS_BOTTOM_LEVEL _OR_ IS_TOP_INTERFACE)) #define CELL ij,LL #define VERTEX1 ij+{{vertex1}},LL #define VERTEX2 ij+{{vertex2}},LL #define EDGE ij+{{edge}},LL #define EDGE_TRISK ij+{{edge_trisk}},LL #define DUAL_CELL ij+{{triangle}},LL #define CELL1 ij,LL #define CELL2 ij+{{neighbour}},LL #define VERTEX {{vertex}},LL #define SIGN {{sign}} #define LE_DE le_de(ij+{{edge}}) #define WEE wee(ij+{{edge}},{{itrisk}}) #define DE de(ij+{{edge}}) #define RIV2 Riv2({{vertex}},{{vertex_dir}}) #define AI Ai(ij) #define FV fv(ij+{{triangle}}) #define AV Av(ij+{{triangle}}) #endif #ifdef PASS_PRE2 #define BARRIER !$OMP BARRIER #define KERNEL(name) {% call define_kernel(#name) %} #define FORALL_CELLS(...) {% call forall_cells(__VA_ARGS__) %} #define FORALL_CELLS_EXT(...) {% call forall_cells_ext(__VA_ARGS__) %} #define ON_PRIMAL {% call(forall_edges) on_hexagons() %} #define ON_DUAL {% call(triangle,forall_edges,forall_vertices) on_triangles() %} #define ON_EDGES {% call(edge,neighbour,sign,vertex1,vertex2,forall_trisk) on_edges() %} #define FORALL_EDGES {% call(edge,sign,vertex1,vertex2) forall_edges() %} #define FORALL_VERTICES {% call(vertex,vertex_dir) forall_vertices() %} #define FORALL_TRISK {% call(itrisk,edge_trisk) forall_trisk() %} #define END_BLOCK {% endcall %} #define SEQUENCE {% call(ext) sequence() %} #define SEQUENCE_EXT {% call(ext) sequence_ext() %} #define PROLOGUE(level) {% call at_level(level,ext) %} #define BODY(range){% call body(range,ext) %} #define EPILOGUE(level){% call at_level(level,ext) %} #define CST_IF(condition, action) {{ cst_if(#condition, #action) }} #define CST_IFTHEN(condition) {{flat}}if condition #define CST_ELSEIF(condition) {{flat}}elif condition #define CST_ELSE {{flat}}else #define CST_ENDIF {{flat}}endif #endif #if PASS_JINJA {% macro sequence() -%} {{ caller('') }} {%- endmacro %} {% macro sequence_ext() -%} {{ caller('_ext') }} {%- endmacro %} {% macro at_level(lev,ext) -%} {{ define('LL', lev) }} DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} {{ caller() }} END DO {%- endmacro %} {% macro body(range,ext) -%} {{ define('LL', 'l') }} DO l = {{ range }} DO ij=ij_omp_begin{{ext}},ij_omp_end{{ext}} {{ caller() }} END DO END DO {%- endmacro %} {#---------------------- big macro generating nested DO loops -------------------------#} {# specialized code is generated for l=1 and l=llm,llm+1 if necessary #} {# start/end values for l are replaced by corresponding OpenMP values #} {% macro define_levels(ll,kdown,kup,thecode) %} {{ define('LL', ll) }} {{ define_cppmacro('KDOWN','(ij,ll)', kdown) if 'KDOWN' in thecode }} {{ define_cppmacro('KUP','(ij,ll)', kup) if 'KUP' in thecode }} {%- endmacro %} {% macro forall(start,end,ij_range,thecode) %} {% set start_omp={'1':'ll_begin' , '2':'ll_beginp1'}[start] %} {% set end_omp={'llm-1':'ll_endm1' , 'llm':'ll_end', 'llm+1':'ll_endp1'}[end] %} {% set is_top_layer, is_top_inter = False, False %} {{ define('IS_TOP_LAYER', '_FALSE_') }} {{ define('IS_TOP_INTERFACE', '_FALSE_') }} {% if 'IS_BOTTOM_LEVEL' in thecode or 'KDOWN' in thecode%} {{ 'ERROR : using IS_BOTTOM_LEVEL in a loop starting at l=2' if start=='2' }} {# the code in the loop checks whether l==1, for the sake of performance we shall write special code for l=1 and start the loop at l=2 #} IF (ll_begin==1) THEN {{ define('IS_BOTTOM_LEVEL', '_TRUE_') }} {{ define_levels('1', 'ij,1', 'ij,1', thecode) }} !DIR$ SIMD DO ij={{ij_range}} {{ thecode }} END DO END IF {% set start_omp='ll_beginp1' %} {% endif %} {% if 'IS_TOP_LAYER' in thecode %} {{ 'ERROR : using _IS_TOP_LAYER_ in a loop ending at l=llm+1' if end=='llm+1' }} {# the code checks whether l==llm, write special code for l=llm and end the loop at l=llm-1 #} {% set end_omp, is_top_layer = 'll_endm1', True %} {% endif %} {% if 'IS_TOP_INTERFACE' in thecode or 'KUP' in thecode %} {# the code checks whether l==llm+1, write special code for l=llm+1 and end the loop at l=llm #} {{ 'ERROR : using _IS_TOP_INTERFACE_ in a loop ending at l=llm' if end=='llm' }} {% set end_omp, is_top_inter ='ll_end', True %} {% endif %} {{ define('IS_BOTTOM_LEVEL', '_FALSE_') }} {{ define_levels('l', 'ij,l-1', 'ij,l', thecode) }} DO l = {{start_omp}}, {{end_omp}} !DIR$ SIMD DO ij={{ij_range}} {{ thecode }} END DO END DO {% if is_top_layer %} IF(ll_end==llm) THEN {{ define('IS_TOP_LAYER', '_TRUE_') }} {{ define_levels('llm', 'ij,llm-1', 'ij,llm', thecode) }} !DIR$ SIMD DO ij={{ij_range}} {{ thecode }} END DO END IF {% endif %} {% if is_top_inter %} IF(ll_endp1==llm+1) THEN {{ define('IS_TOP_INTERFACE', '_TRUE_') }} {{ define_levels('llm+1', 'ij,llm', 'ij,llm', thecode) }} !DIR$ SIMD DO ij={{ij_range}} {{ thecode }} END DO END IF {% endif %} {% endmacro %} {#-------------------------------------------------------------------------------------#} {% macro forall_cells(start='1', end='llm') -%} {{ forall(start,end,'ij_begin, ij_end', caller()) }} {% endmacro %} {% macro forall_cells_ext(start='1', end='llm') -%} {{ forall(start,end,'ij_begin_ext, ij_end_ext', caller()) }} {% endmacro %} {% macro forall_edges_hex() -%} {{ caller('u_rup','ne_rup', 'z_rup','z_up') }} {{ caller('u_lup','ne_lup', 'z_lup','z_up') }} {{ caller('u_left','ne_left','z_lup','z_ldown') }} {{ caller('u_ldown','ne_ldown', 'z_ldown','z_down') }} {{ caller('u_rdown','ne_rdown', 'z_rdown','z_down') }} {{ caller('u_right','ne_right', 'z_rup','z_rdown') }} {%- endmacro %} {% macro on_hexagons() -%} {{ caller(forall_edges_hex) }} {%- endmacro %} {% macro forall_edges_zup() -%} {{ caller('u_rup','ne_rup', 'TODO','TODO') }} {{ caller('t_rup+u_left','ne_left', 'TODO','TODO') }} {{ caller('u_lup','(-ne_lup)', 'TODO','TODO') }} {%- endmacro %} {% macro forall_edges_zdown() -%} {{ caller('u_rdown','(-ne_rdown)', 'TODO', 'TODO') }} {{ caller('t_ldown+u_right','ne_right', 'TODO', 'TODO') }} {{ caller('u_ldown','ne_ldown', 'TODO', 'TODO') }} {%- endmacro %} {% macro forall_vertices_zup() -%} {{ caller('ij','vup') }} {{ caller('ij+t_rup','vldown') }} {{ caller('ij+t_lup','vrdown') }} {%- endmacro %} {% macro forall_vertices_zdown() -%} {{ caller('ij','vdown') }} {{ caller('ij+t_ldown','vrup') }} {{ caller('ij+t_rdown','vlup') }} {%- endmacro %} {% macro on_triangles() -%} {{ caller('z_up',forall_edges_zup,forall_vertices_zup) }} {{ caller('z_down',forall_edges_zdown,forall_vertices_zdown) }} {%- endmacro %} {% macro trisk_right() -%} {{ caller('1,1', 'u_rup') }} {{ caller('2,1', 'u_lup') }} {{ caller('3,1', 'u_left') }} {{ caller('4,1', 'u_ldown') }} {{ caller('5,1', 'u_rdown') }} {{ caller('1,2', 't_right+u_ldown') }} {{ caller('2,2', 't_right+u_rdown') }} {{ caller('3,2', 't_right+u_right') }} {{ caller('4,2', 't_right+u_rup') }} {{ caller('5,2', 't_right+u_lup') }} {%- endmacro %} {% macro trisk_lup() -%} {{ caller('1,1', 'u_left') }} {{ caller('2,1', 'u_ldown') }} {{ caller('3,1', 'u_rdown') }} {{ caller('4,1', 'u_right') }} {{ caller('5,1', 'u_rup') }} {{ caller('1,2', 't_lup+u_right') }} {{ caller('2,2', 't_lup+u_rup') }} {{ caller('3,2', 't_lup+u_lup') }} {{ caller('4,2', 't_lup+u_left') }} {{ caller('5,2', 't_lup+u_ldown') }} {%- endmacro %} {% macro trisk_ldown() -%} {{ caller('1,1', 'u_rdown') }} {{ caller('2,1', 'u_right') }} {{ caller('3,1', 'u_rup') }} {{ caller('4,1', 'u_lup') }} {{ caller('5,1', 'u_left') }} {{ caller('1,2', 't_ldown+u_lup') }} {{ caller('2,2', 't_ldown+u_left') }} {{ caller('3,2', 't_ldown+u_ldown') }} {{ caller('4,2', 't_ldown+u_rdown') }} {{ caller('5,2', 't_ldown+u_right') }} {%- endmacro %} {% macro on_edges() -%} {{ caller('u_right','t_right','ne_right','z_rdown','z_rup',trisk_right) }} {{ caller('u_lup','t_lup','ne_lup','z_up','z_lup', trisk_lup) }} {{ caller('u_ldown','t_ldown','ne_ldown','z_ldown','z_down', trisk_ldown) }} {%- endmacro %} {% set llm = 'llm' %} #endif #ifdef PASS_POST1 #define _TRUE_ (0==0) #define _FALSE_ (0==1) #define CELL ij,LL #endif #ifdef PASS_POST2 #define UP(ij,l) ij,l+1 #define DOWN(ij,l) ij,l-1 #define HIDX(ij,l) ij #define VIDX(ij,l) l #endif