diff --git a/runtime/domain/regular_6d_stencil.cpp b/runtime/domain/regular_6d_stencil.cpp index ae66aca0db373bb5814182ab5bbf7018713e2c30..649e18624899655dc5730d27e51dc5cc15d80918 100644 --- a/runtime/domain/regular_6d_stencil.cpp +++ b/runtime/domain/regular_6d_stencil.cpp @@ -107,18 +107,17 @@ void Regular6DStencil::copyRuntimeArray(const std::string& name, void *dest, con int *neighbor_ranks = static_cast<int *>(dest); neighbor_ranks[d * 2 + 0] = prev[d]; neighbor_ranks[d * 2 + 1] = next[d]; - } - - if(name.compare("pbc") == 0) { + } else if(name.compare("pbc") == 0) { int *pbc = static_cast<int *>(dest); pbc[d * 2 + 0] = pbc_prev[d]; pbc[d * 2 + 1] = pbc_next[d]; - } - - if(name.compare("subdom") == 0) { + } else if(name.compare("subdom") == 0) { real_t *subdom = static_cast<real_t *>(dest); subdom[d * 2 + 0] = subdom_min[d]; subdom[d * 2 + 1] = subdom_max[d]; + } else { + std::cerr << "copyRuntimeArray(): Array \"" << name << "\" is invalid." << std::endl; + exit(-1); } } } diff --git a/src/pairs/code_gen/cgen.py b/src/pairs/code_gen/cgen.py index e22067801c7d707911fcb3dad215b80bd67d6a44..df4816f0543933900633f6b9a7f92b295f1e3481 100644 --- a/src/pairs/code_gen/cgen.py +++ b/src/pairs/code_gen/cgen.py @@ -314,9 +314,10 @@ class CGen: narrays = module.sim.arrays.narrays() part = DomainPartitioners.c_keyword(module.sim.partitioner()) + self.generate_full_object_names = True self.print("int main(int argc, char **argv) {") - self.print(f" PairsRuntime *pairs = new PairsRuntime({nprops}, {ncontactprops}, {narrays}, {part});") - self.print(f" struct pairs_object *pobj = new pairs_objects();") + self.print(f" PairsRuntime *pairs_runtime = new PairsRuntime({nprops}, {ncontactprops}, {narrays}, {part});") + self.print(f" struct pairs_objects *pobj = new pairs_objects();") if module.sim._enable_profiler: self.print(" LIKWID_MARKER_INIT;") @@ -327,9 +328,10 @@ class CGen: self.print(" LIKWID_MARKER_CLOSE;") self.print(" pairs::print_timers(pairs_runtime);") - self.print(" pairs::print_stats(pairs_runtime, nlocal, nghost);") + self.print(" pairs::print_stats(pairs_runtime, pobj->nlocal, pobj->nghost);") self.print(" return 0;") self.print("}") + self.generate_full_object_names = False else: self.print(f"void {module.name}(struct pairs_objects *pobj) {{") @@ -434,6 +436,7 @@ class CGen: t = ast_node.array.type() tkw = Types.c_keyword(self.sim, t) size = self.generate_expression(ScalarOp.inline(ast_node.array.alloc_size())) + if ast_node.array.init_value is not None: v_str = str(ast_node.array.init_value) if t == Types.Int64: @@ -441,10 +444,8 @@ class CGen: if t == Types.UInt64: v_str += "ULL" - init_string = v_str + (f", {v_str}" * (size - 1)) - self.print(f"{tkw} {ast_node.array.name()}[{size}] = {{{init_string}}};") - else: - self.print(f"{tkw} {ast_node.array.name()}[{size}];") + for i in range(size): + self.print(f"{ast_node.array.name()}[{i}] = {v_str};") if isinstance(ast_node, Assign): if not Types.is_scalar(ast_node._dest.type()): @@ -773,15 +774,17 @@ class CGen: if isinstance(ast_node, RegisterArray): a = ast_node.array() - ptr_addr = self.generate_object_address(a) - d_ptr_addr = self.generate_object_address(a, device=True) tkw = Types.c_keyword(self.sim, a.type()) size = self.generate_expression(ast_node.size()) if a.is_static(): - self.print(f"pairs_runtime->addStaticArray({a.id()}, \"{a.name()}\", {ptr_addr}, {d_ptr_addr}, {size});") + ptr_ref = self.generate_object_reference(a) + d_ptr_ref = self.generate_object_reference(a, device=True) + self.print(f"pairs_runtime->addStaticArray({a.id()}, \"{a.name()}\", {ptr_ref}, {d_ptr_ref}, {size});") else: + ptr_addr = self.generate_object_address(a) + d_ptr_addr = self.generate_object_address(a, device=True) self.print(f"pairs_runtime->addArray({a.id()}, \"{a.name()}\", {ptr_addr}, {d_ptr_addr}, {size});") if isinstance(ast_node, RegisterProperty):