Skip to content

Commit 633ad92

Browse files
authored
add example5 - simple stencil2d (#6)
* add example5 - simple stencil2d * review fixes change to a floating point number remove unused variables
1 parent 2a0c52d commit 633ad92

File tree

4 files changed

+61
-3
lines changed

4 files changed

+61
-3
lines changed

.github/workflows/docker_workflow.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@ 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/example4
54+
mpirun -n 3 ./build/src/example5

scripts/build_run.sh

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

0 commit comments

Comments
 (0)