Skip to content

Commit 60d1060

Browse files
committed
add example5 - simple stencil2d
1 parent 2a0c52d commit 60d1060

File tree

4 files changed

+63
-3
lines changed

4 files changed

+63
-3
lines changed

.github/workflows/docker_workflow.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ jobs:
4747
cmake --build build -j
4848
- name: Run examples
4949
run: |
50-
mpirun -n 2 ./build/src/example1
51-
mpirun -n 2 ./build/src/example2
52-
mpirun -n 2 ./build/src/example3
50+
mpirun -n 3 ./build/src/example1
51+
mpirun -n 3 ./build/src/example2
52+
mpirun -n 3 ./build/src/example3
53+
mpirun -n 3 ./build/src/example5

scripts/build_run.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ cmake --build build -j
1313
mpirun -n 2 ./build/src/example1
1414
mpirun -n 2 ./build/src/example2
1515
mpirun -n 2 ./build/src/example3
16+
mpirun -n 2 ./build/src/example5

src/CMakeLists.txt

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

3232
target_compile_definitions(example4 INTERFACE DR_FORMAT)
3333
target_link_libraries(example4 DR::mpi fmt::fmt)
34+
35+
add_executable(example5 example5.cpp)
36+
37+
target_compile_definitions(example5 INTERFACE DR_FORMAT)
38+
target_link_libraries(example5 DR::mpi fmt::fmt)

src/example5.cpp

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
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+
10+
using T = uint16_t;
11+
using MDA = dr::mhp::distributed_mdarray<T, 2>;
12+
13+
int main() {
14+
#ifdef SYCL_LANGUAGE_VERSION
15+
mhp::init(sycl::default_selector_v);
16+
#else
17+
mhp::init();
18+
#endif
19+
std::size_t arr_size = 4;
20+
std::size_t radius = 1;
21+
std::array slice_starts{radius, radius};
22+
std::array slice_ends{arr_size - radius, arr_size - radius};
23+
24+
auto dist = dr::mhp::distribution().halo(radius);
25+
MDA a({arr_size, arr_size}, dist);
26+
MDA b({arr_size, arr_size}, dist);
27+
mhp::iota(a, 1);
28+
mhp::iota(b, 1);
29+
30+
auto in = dr::mhp::views::submdspan(a.view(), slice_starts, slice_ends);
31+
auto out = dr::mhp::views::submdspan(b.view(), slice_starts, slice_ends);
32+
auto in_array = &a;
33+
auto out_array = &b;
34+
35+
auto mdspan_stencil_op = [](auto &&v) {
36+
auto [in, out] = v;
37+
out(0, 0) = (in(-1, 0) + in(0, -1) + in(0, 0) + in(0, 1) + in(1, 0)) / 4;
38+
};
39+
40+
mhp::halo(*in_array).exchange();
41+
mhp::stencil_for_each(mdspan_stencil_op, in, out);
42+
43+
if (mhp::rank() == 0) {
44+
fmt::print("a: \n{} \n", a.mdspan());
45+
fmt::print("b: \n{} \n", b.mdspan());
46+
fmt::print("in: \n{} \n", in.mdspan());
47+
fmt::print("out: \n{} \n", out.mdspan());
48+
}
49+
50+
mhp::finalize();
51+
52+
return 0;
53+
}

0 commit comments

Comments
 (0)