diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 8aa72c0..955ce53 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,3 +26,8 @@ add_executable(example3 example3.cpp) target_compile_definitions(example3 INTERFACE DR_FORMAT) target_link_libraries(example3 DR::mpi fmt::fmt) + +add_executable(example4 example4.cpp) + +target_compile_definitions(example4 INTERFACE DR_FORMAT) +target_link_libraries(example4 DR::mpi fmt::fmt) diff --git a/src/example4.cpp b/src/example4.cpp new file mode 100644 index 0000000..94932ab --- /dev/null +++ b/src/example4.cpp @@ -0,0 +1,42 @@ +// SPDX-FileCopyrightText: Intel Corporation +// +// SPDX-License-Identifier: BSD-3-Clause + +#include +#include + +namespace mhp = dr::mhp; +using T = int; + +int main(int argc, char **argv) { + + mhp::init(sycl::default_selector_v); + std::size_t xdim = 9, ydim = 5; + + std::array extents2d = {xdim, ydim}; + + // any array with corresponding dimensions can be used + mhp::distributed_mdarray a(extents2d); + mhp::distributed_mdarray b(extents2d); + mhp::distributed_mdarray c(extents2d); + + // try populating the arrays with any data + mhp::iota(a, 100); + mhp::iota(b, 200); + + auto copy_op = [](auto v) { + auto [in1, in2, out] = v; + out = in1 + in2; + }; + mhp::for_each(copy_op, a, b, c); + + if (mhp::rank() == 0) { + fmt::print("A:\n{}\n", a.mdspan()); + fmt::print("B:\n{}\n", b.mdspan()); + fmt::print("C:\n{}\n", c.mdspan()); + } + + mhp::finalize(); + + return 0; +}