diff --git a/python/dune/codegen/pdelab/driver/__init__.py b/python/dune/codegen/pdelab/driver/__init__.py index c33d3acebfe27686f35055801f1282dc1d2b1450..b60544c1c78242f1490c76c46d4be6a2c4448501 100644 --- a/python/dune/codegen/pdelab/driver/__init__.py +++ b/python/dune/codegen/pdelab/driver/__init__.py @@ -269,7 +269,7 @@ def generate_driver(): compare_L2_squared() # Make sure that timestream is declared before retrieving chache items - if get_option("instrumentation_level") >= 1 and not get_option("use_likwid"): + if get_option("instrumentation_level") >= 1: from dune.codegen.pdelab.driver.timings import setup_timer setup_timer() @@ -277,7 +277,7 @@ def generate_driver(): return_statement() from dune.codegen.generation import retrieve_cache_items - from cgen import FunctionDeclaration, FunctionBody, Block, Value, LineComment, Line + from cgen import FunctionDeclaration, FunctionBody, Block, Value, LineComment, Line, Generable driver_signature = FunctionDeclaration(Value('int', 'main'), [Value('int', 'argc'), Value('char**', 'argv')]) contents = [] @@ -291,6 +291,11 @@ def generate_driver(): contents.append(Line("\n")) add_section("init", "Initialize basic stuff...") + + if get_option("instrumentation_level") >= 1: + init_contents = contents + contents = [] + add_section("grid", "Setup grid (view)...") add_section("fem", "Set up finite element maps...") add_section("gfs", "Set up grid function spaces...") @@ -303,19 +308,16 @@ def generate_driver(): add_section("instat", "Set up instationary stuff...") add_section("printing", "Maybe print residuals and matrices to stdout...") add_section("error", "Maybe calculate errors for test results...") + + if get_option("instrumentation_level") >= 1: + from dune.codegen.pdelab.driver.timings import timed_region + contents = init_contents + timed_region('driver', contents) + add_section("end", "Stuff that should happen at the end...") add_section("return_stmt", "Return statement...") - if get_option("instrumentation_level") >= 1 and not get_option("use_likwid"): - from dune.codegen.generation import post_include - from dune.codegen.pdelab.driver.timings import name_timing_stream - timestream = name_timing_stream() - post_include("HP_DECLARE_TIMER(driver);\n", filetag="driver") - contents.insert(0, Line(text="HP_TIMER_START(driver);\n")) - contents.insert(len(contents) - 2, Line(text="HP_TIMER_STOP(driver);\n")) - contents.insert(len(contents) - 2, Line(text="DUMP_TIMER({}, driver, {}, true);\n".format(get_option("instrumentation_level"), timestream))) - contents.insert(0, Line(text="\n")) - driver_body = Block(contents) + contents.insert(0, "\n") + driver_body = Block([c if isinstance(c, Generable) else Line(c + '\n') for c in contents]) # Wrap a try/catch block around the driver body from dune.codegen.cgen import CatchBlock, TryCatchBlock, Value, Block, Line diff --git a/python/dune/codegen/pdelab/driver/timings.py b/python/dune/codegen/pdelab/driver/timings.py index c4c7bd3f3932c6e57da521ebb1ffe8600337545b..6bc73aec5b634e973d754d3d447214bcc5fadd63 100644 --- a/python/dune/codegen/pdelab/driver/timings.py +++ b/python/dune/codegen/pdelab/driver/timings.py @@ -119,20 +119,6 @@ def finalize_likwid(): return ["LIKWID_MARKER_CLOSE;"] -@cached -def driver_likwid(): - @preamble(section="init") - def start_driver_likwid(): - return ["LIKWID_MARKER_START(\"driver\");"] - - @preamble(section="end") - def stop_driver_likwid(): - return ["LIKWID_MARKER_STOP(\"driver\");"] - - start_driver_likwid() - stop_driver_likwid() - - @preamble(section="timings") def local_operator_likwid(): lop_name = name_localoperator(get_form_ident()) @@ -146,7 +132,6 @@ def setup_timer(): pre_include("#define LIKWID_PERFMON", filetag="driver") include_file("likwid.h", filetag="driver") init_likwid() - driver_likwid() if get_option('instrumentation_level') >= 3: local_operator_likwid() finalize_likwid()