Skip to content

Commit 2a0c52d

Browse files
authored
add example4 - dmdarray adding (#5)
1 parent 7db7b6c commit 2a0c52d

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-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: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
// any array with corresponding dimensions can be used
19+
mhp::distributed_mdarray<T, 2> a(extents2d);
20+
mhp::distributed_mdarray<T, 2> b(extents2d);
21+
mhp::distributed_mdarray<T, 2> c(extents2d);
22+
23+
// try populating the arrays with any data
24+
mhp::iota(a, 100);
25+
mhp::iota(b, 200);
26+
27+
auto copy_op = [](auto v) {
28+
auto [in1, in2, out] = v;
29+
out = in1 + in2;
30+
};
31+
mhp::for_each(copy_op, a, b, c);
32+
33+
if (mhp::rank() == 0) {
34+
fmt::print("A:\n{}\n", a.mdspan());
35+
fmt::print("B:\n{}\n", b.mdspan());
36+
fmt::print("C:\n{}\n", c.mdspan());
37+
}
38+
39+
mhp::finalize();
40+
41+
return 0;
42+
}

0 commit comments

Comments
 (0)