Skip to content

Commit 4e4cc44

Browse files
authored
Examples description in a README.md file. (#10)
* added description for the example4 * added description for the example5 * added description for the example6 * switch to more technical vocabulary
1 parent eff4d21 commit 4e4cc44

File tree

3 files changed

+22
-9
lines changed

3 files changed

+22
-9
lines changed

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,20 @@ The example shows the distributed nature of dr data structures. The distributed_
146146
Additionally, a use of a subrange is presented, and `transform()` function, which puts transformed values of input structure to the output structure, element by element. The transforming function is given as lambda `newvalue`.
147147
_Please note: after each loop the vector content is printed with `fmt::print()`. The formatter function for `distributed_vector` is rather slow, as it gets the vector element by element, both from local node and remote nodes. You can think about customised, more effective way of results presentation._
148148

149-
<!--
150-
Consider adding one more example:
151-
*Simple 2-D operation - Find a pattern in the randomly filled array*
152-
-->
149+
### Example 4
150+
151+
[./src/example4.cpp](src/example4.cpp)
152+
153+
This example illustrates adding two distributed,multidimensional arrays. Each array has two dimensions and is initialized by an `std::array`. The arrays are populated with sequential values using a distributed version of iota called `mhp::iota`. A for_each loop is the main part of the code, computing the sum on a specified number of nodes. It takes a lambda copy function along with two input arrays (a and b) and an output array (c) as parameters. The result is printed on a node 0.
154+
155+
### Example 5
156+
157+
[./src/example5.cpp](src/example5.cpp)
158+
159+
Example 5 outlines a method for calculating a 2D 5-point stencil with distributed multidimensional arrays, specifically utilizing `dr::mhp::distributed_mdarray`. Initially, it involves setting up key parameters like the radius for element exchange between nodes through `dr::mhp::halo`, and defining the start and end points of the array slice. The example's core is the `mhp::stencil_for_each` function, which applies a lambda function to two subsets of the array, designated as input and output. The `mdspan_stencil_op` lambda function conducts a simple calculation that involves adding together the values of an element and its adjacent elements and subsequently calculating their average. The `mhp::halo().exchange()` enables values to be shared across distinct nodes, making this process feasible. Ultimately, the outcomes of the calculation are neatly displayed on node 0 using mdspan(), resulting in a clear indication of the modifications made to the 2D array. This example is a practical demonstration of executing stencil operations on distributed arrays.
160+
161+
### Example 6
162+
163+
[./src/example6.cpp](src/example6.cpp)
164+
165+
This example's code demonstrates a 2D pattern search in a distributed, multidimensional array (`mhp::distributed_mdarray<float, 2>`). It initializes a 2D array, populates it with `mhp::iota`, converts it to binary values using `mhp::transform` and defines a pattern of 2x2. A lambda function is used to scan the array and mark occurrences of the pattern in a separate array. The process is similar to the one demonstrated in example5.

src/example4.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,11 +24,11 @@ int main(int argc, char **argv) {
2424
mhp::iota(a, 100);
2525
mhp::iota(b, 200);
2626

27-
auto copy_op = [](auto v) {
27+
auto sum_op = [](auto v) {
2828
auto [in1, in2, out] = v;
2929
out = in1 + in2;
3030
};
31-
mhp::for_each(copy_op, a, b, c);
31+
mhp::for_each(sum_op, a, b, c);
3232

3333
if (mhp::rank() == 0) {
3434
fmt::print("A:\n{}\n", a.mdspan());

src/example5.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,14 @@ int main() {
1919
std::array slice_starts{radius, radius};
2020
std::array slice_ends{arr_size - radius, arr_size - radius};
2121

22-
auto dist = dr::mhp::distribution().halo(radius);
22+
auto dist = mhp::distribution().halo(radius);
2323
MDA a({arr_size, arr_size}, dist);
2424
MDA b({arr_size, arr_size}, dist);
2525
mhp::iota(a, 1);
2626
mhp::iota(b, 1);
2727

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);
28+
auto in = mhp::views::submdspan(a.view(), slice_starts, slice_ends);
29+
auto out = mhp::views::submdspan(b.view(), slice_starts, slice_ends);
3030

3131
auto mdspan_stencil_op = [](auto &&v) {
3232
auto [in, out] = v;

0 commit comments

Comments
 (0)