Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add example4 - dmdarray adding #5

Merged
merged 1 commit into from
Nov 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,8 @@ add_executable(example3 example3.cpp)

target_compile_definitions(example3 INTERFACE DR_FORMAT)
target_link_libraries(example3 DR::mpi fmt::fmt)

add_executable(example4 example4.cpp)

target_compile_definitions(example4 INTERFACE DR_FORMAT)
target_link_libraries(example4 DR::mpi fmt::fmt)
42 changes: 42 additions & 0 deletions src/example4.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// SPDX-FileCopyrightText: Intel Corporation
//
// SPDX-License-Identifier: BSD-3-Clause

#include <dr/mhp.hpp>
#include <fmt/core.h>

namespace mhp = dr::mhp;
using T = int;

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a descriptive comment, eg.
/* The example presents operation of ... The result is stored in ... */

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about describing all new examples together in the README file

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So a brief summary, like
/* add content of two 2-d arrays and display the results */
The files have their names (not informing about the content, just exampleX), so as a reader of a tutorial, I would appreciate some additional textual sync between the description and the particular code.

int main(int argc, char **argv) {

mhp::init(sycl::default_selector_v);
std::size_t xdim = 9, ydim = 5;

std::array<std::size_t, 2> extents2d = {xdim, ydim};

// any array with corresponding dimensions can be used
mhp::distributed_mdarray<T, 2> a(extents2d);
mhp::distributed_mdarray<T, 2> b(extents2d);
mhp::distributed_mdarray<T, 2> c(extents2d);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a comment to lines 21-22, encouraging a tutorial user to change the initial content of arrays a & b.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


// try populating the arrays with any data
mhp::iota(a, 100);
mhp::iota(b, 200);

auto copy_op = [](auto v) {
auto [in1, in2, out] = v;
out = in1 + in2;
};
mhp::for_each(copy_op, a, b, c);

if (mhp::rank() == 0) {
fmt::print("A:\n{}\n", a.mdspan());
fmt::print("B:\n{}\n", b.mdspan());
fmt::print("C:\n{}\n", c.mdspan());
}

mhp::finalize();

return 0;
}