Skip to content

Commit

Permalink
Allow move only objects to be used (and kept alive) in transform_mpi
Browse files Browse the repository at this point in the history
Add test for move only transform_mpi
  • Loading branch information
biddisco committed Nov 11, 2024
1 parent 70741c0 commit affc47d
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
10 changes: 7 additions & 3 deletions libs/pika/async_mpi/include/pika/async_mpi/transform_mpi.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <pika/execution/algorithms/detail/partial_algorithm.hpp>
#include <pika/execution/algorithms/just.hpp>
#include <pika/execution/algorithms/let_value.hpp>
#include <pika/execution/algorithms/unpack.hpp>
#include <pika/execution_base/any_sender.hpp>
#include <pika/execution_base/receiver.hpp>
#include <pika/execution_base/sender.hpp>
Expand Down Expand Up @@ -52,6 +53,7 @@ namespace pika::mpi::experimental {
using pika::execution::experimental::just;
using pika::execution::experimental::let_value;
using pika::execution::experimental::unique_any_sender;
using pika::execution::experimental::unpack;

// get mpi completion mode settings
auto mode = get_completion_mode();
Expand Down Expand Up @@ -79,8 +81,9 @@ namespace pika::mpi::experimental {
if (requests_inline)
{
return std::forward<Sender>(sender) |
let_value([=, f = std::forward<F>(f)](auto&... args) mutable {
auto snd0 = just(args...);
let_value([=, f = std::forward<F>(f)](auto&&... args) mutable {
std::tuple<decltype(args)&...> ts{args...};
auto snd0 = just(ts) | ex::unpack();
return dispatch_mpi_sender<decltype(snd0), F>{
std::move(snd0), std::move(f)} |
let_value(completion_snd);
Expand All @@ -90,7 +93,8 @@ namespace pika::mpi::experimental {
{
return std::forward<Sender>(sender) | continues_on(mpi_pool_scheduler(p)) |
let_value([=, f = std::forward<F>(f)](auto&... args) mutable {
auto snd0 = just(args...);
std::tuple<decltype(args)&...> ts{args...};
auto snd0 = just(ts) | ex::unpack();
return dispatch_mpi_sender<decltype(snd0), F>{
std::move(snd0), std::move(f)} |
let_value(completion_snd);
Expand Down
11 changes: 11 additions & 0 deletions libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,17 @@ int pika_main()
tt::sync_wait(PIKA_MOVE(s));
}

{
auto s = ex::just(custom_type_non_default_constructible_non_copyable{42}, datatype,
0, comm) |
ex::drop_operation_state() |
mpi::transform_mpi([](auto& data, MPI_Datatype datatype, int i, MPI_Comm comm,
MPI_Request* request) {
MPI_Ibcast(&data, 1, datatype, i, comm, request);
});
tt::sync_wait(PIKA_MOVE(s));
}

// transform_mpi should be able to handle reference types (by copying
// them to the operation state)
{
Expand Down

0 comments on commit affc47d

Please sign in to comment.