From affc47d86bcf7cd0035dd52a07180deed6fefc86 Mon Sep 17 00:00:00 2001 From: John Biddiscombe Date: Mon, 11 Nov 2024 16:25:56 +0100 Subject: [PATCH] Allow move only objects to be used (and kept alive) in transform_mpi Add test for move only transform_mpi --- .../include/pika/async_mpi/transform_mpi.hpp | 10 +++++++--- .../async_mpi/tests/unit/algorithm_transform_mpi.cpp | 11 +++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/libs/pika/async_mpi/include/pika/async_mpi/transform_mpi.hpp b/libs/pika/async_mpi/include/pika/async_mpi/transform_mpi.hpp index fcea93afb..1c02b0fd8 100644 --- a/libs/pika/async_mpi/include/pika/async_mpi/transform_mpi.hpp +++ b/libs/pika/async_mpi/include/pika/async_mpi/transform_mpi.hpp @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -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(); @@ -79,8 +81,9 @@ namespace pika::mpi::experimental { if (requests_inline) { return std::forward(sender) | - let_value([=, f = std::forward(f)](auto&... args) mutable { - auto snd0 = just(args...); + let_value([=, f = std::forward(f)](auto&&... args) mutable { + std::tuple ts{args...}; + auto snd0 = just(ts) | ex::unpack(); return dispatch_mpi_sender{ std::move(snd0), std::move(f)} | let_value(completion_snd); @@ -90,7 +93,8 @@ namespace pika::mpi::experimental { { return std::forward(sender) | continues_on(mpi_pool_scheduler(p)) | let_value([=, f = std::forward(f)](auto&... args) mutable { - auto snd0 = just(args...); + std::tuple ts{args...}; + auto snd0 = just(ts) | ex::unpack(); return dispatch_mpi_sender{ std::move(snd0), std::move(f)} | let_value(completion_snd); diff --git a/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp b/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp index 3b030dbaf..c79684f39 100644 --- a/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp +++ b/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp @@ -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) {