Skip to content

Commit b134a09

Browse files
committed
add example4 - dmdarray adding
1 parent 7db7b6c commit b134a09

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

src/CMakeLists.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,8 @@ add_executable(example3 example3.cpp)
2626

2727
target_compile_definitions(example3 INTERFACE DR_FORMAT)
2828
target_link_libraries(example3 DR::mpi fmt::fmt)
29+
30+
add_executable(example4 example4.cpp)
31+
32+
target_compile_definitions(example4 INTERFACE DR_FORMAT)
33+
target_link_libraries(example4 DR::mpi fmt::fmt)

src/example4.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// SPDX-FileCopyrightText: Intel Corporation
2+
//
3+
// SPDX-License-Identifier: BSD-3-Clause
4+
5+
#include <dr/mhp.hpp>
6+
#include <fmt/core.h>
7+
8+
namespace mhp = dr::mhp;
9+
using T = int;
10+
11+
int main(int argc, char **argv) {
12+
13+
mhp::init(sycl::default_selector_v);
14+
std::size_t xdim = 9, ydim = 5;
15+
16+
std::array<std::size_t, 2> extents2d = {xdim, ydim};
17+
18+
mhp::distributed_mdarray<T, 2> a(extents2d);
19+
mhp::distributed_mdarray<T, 2> b(extents2d);
20+
mhp::distributed_mdarray<T, 2> c(extents2d);
21+
mhp::iota(a, 100);
22+
mhp::iota(b, 200);
23+
24+
auto copy_op = [](auto v) {
25+
auto [in1, in2, out] = v;
26+
out = in1 + in2;
27+
};
28+
mhp::for_each(copy_op, a, b, c);
29+
30+
if (mhp::rank() == 0) {
31+
fmt::print("A:\n{}\n", a.mdspan());
32+
fmt::print("B:\n{}\n", b.mdspan());
33+
fmt::print("C:\n{}\n", c.mdspan());
34+
}
35+
36+
mhp::finalize();
37+
38+
return 0;
39+
}

0 commit comments

Comments
 (0)