diff --git a/runtime/timers.hpp b/runtime/timers.hpp index bb73df8f6ba9872923aa3dd8ec2784dce92a3685..697a2090d3d5e6304b88573e89193e825ee5607f 100644 --- a/runtime/timers.hpp +++ b/runtime/timers.hpp @@ -36,7 +36,8 @@ public: void writeToFile(int rank, int world_size){ std::string filename = "timers_" + std::to_string(world_size) + ".txt"; if (rank==0) std::cout << "Writing timers log to: " << filename << std::endl; - + std::remove(filename.c_str()); + MPI_File file; MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_WRONLY | MPI_MODE_CREATE, MPI_INFO_NULL, &file); diff --git a/src/pairs/code_gen/cgen.py b/src/pairs/code_gen/cgen.py index 46276312d1b5272316efd2895dbfef440fc16ae6..272e1a95de8376f53267160361eb10c808e8db05 100644 --- a/src/pairs/code_gen/cgen.py +++ b/src/pairs/code_gen/cgen.py @@ -43,7 +43,7 @@ class CGen: self.target = None self.print = None self.kernel_context = False - self.loop_scope = False + self.loop_depth = False self.generate_full_object_names = False self.ref = ref self.debug = debug @@ -537,13 +537,13 @@ class CGen: self.print.add_indent(-4) if isinstance(ast_node, Continue): - if self.loop_scope: + if self.loop_depth: self.print("continue;") else: self.print("return;") if isinstance(ast_node, Break): - if self.loop_scope: + if self.loop_depth: self.print("break;") else: self.print("return;") @@ -775,9 +775,10 @@ class CGen: self.print("#pragma omp parallel for") self.print(f"for(int {iterator} = {lower_range}; {iterator} < {upper_range}; {iterator}++) {{") - self.loop_scope = True + parent_loop_scope = self.loop_depth + self.loop_depth = True self.generate_statement(ast_node.block) - self.loop_scope = False + self.loop_depth = parent_loop_scope self.print("}") @@ -983,9 +984,10 @@ class CGen: if isinstance(ast_node, While): cond = self.generate_expression(ast_node.cond) self.print(f"while({cond}) {{") - self.loop_scope = True + parent_loop_scope = self.loop_depth + self.loop_depth = True self.generate_statement(ast_node.block) - self.loop_scope = False + self.loop_depth = parent_loop_scope self.print("}") if isinstance(ast_node, Return): diff --git a/src/pairs/ir/module.py b/src/pairs/ir/module.py index c7937ed9b478f2420a44633af040976884a18c58..8b123580e797d9358118e88898ebbdb0a9e4f1ff 100644 --- a/src/pairs/ir/module.py +++ b/src/pairs/ir/module.py @@ -38,9 +38,6 @@ class Module(ASTNode): self._return_type = Types.Void self._profile = profile - if profile: - self.sim.enable_profiler() - if interface: sim.add_interface_module(self) else: diff --git a/src/pairs/mapping/funcs.py b/src/pairs/mapping/funcs.py index 062dfe3559f17bc799ffbe45670417fc3c829d72..bfa6f87776849f9f80cf07450d758a8a1be6a5c6 100644 --- a/src/pairs/mapping/funcs.py +++ b/src/pairs/mapping/funcs.py @@ -331,6 +331,9 @@ def compute(sim, func, cutoff_radius=None, symbols={}, parameters={}, compute_gl sim.init_block() sim.module_name(func.__name__) + if profile: + sim.enable_profiler() + if nparams == 1: for i in OneBodyKernel(sim, func.__name__, run_on_device=run_on_device, profile=profile): ir = BuildParticleIR(sim, symbols, parameters) diff --git a/src/pairs/transformations/instrumentation.py b/src/pairs/transformations/instrumentation.py index 5d039b8cb3ed8ee628b098a6126491b49402e107..049737dd01839d70d49dadcd925273bb0ea6bf38 100644 --- a/src/pairs/transformations/instrumentation.py +++ b/src/pairs/transformations/instrumentation.py @@ -15,15 +15,15 @@ class AddModulesInstrumentation(Mutator): if module.name == 'initialize' or module.name == 'end' or module.return_type!=Types.Void: return ast_node - - if module.must_profile(): - start_marker = Call_Void(ast_node.sim, "LIKWID_MARKER_START", [module.name]) - stop_marker = Call_Void(ast_node.sim, "LIKWID_MARKER_STOP", [module.name]) - module._block = Block.from_list(ast_node.sim, [start_marker, module._block, stop_marker]) timer_id = module.module_id + Timers.Offset start_timer = Call_Void(ast_node.sim, "pairs::start_timer", [timer_id]) stop_timer = Call_Void(ast_node.sim, "pairs::stop_timer", [timer_id]) module._block = Block.from_list(ast_node.sim, [start_timer, module._block, stop_timer]) + if module.must_profile(): + start_marker = Call_Void(ast_node.sim, "LIKWID_MARKER_START", [module.name]) + stop_marker = Call_Void(ast_node.sim, "LIKWID_MARKER_STOP", [module.name]) + module._block = Block.from_list(ast_node.sim, [start_marker, module._block, stop_marker]) + return ast_node