From 929da39aae04386a8edeaeb8c31a5d3e3aa3d7ed Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Thu, 14 Nov 2024 16:39:19 +0100 Subject: [PATCH 1/3] Merge pull request #1321 from msimberg/transform-mpi-lifetimes Test and fix lifetimes of `transform_mpi` values --- .../include/pika/async_mpi/dispatch_mpi.hpp | 3 +- .../include/pika/async_mpi/transform_mpi.hpp | 17 +++++++---- .../tests/unit/algorithm_transform_mpi.cpp | 30 +++++++++++++++++-- .../include/pika/config/compiler_specific.hpp | 10 +++++-- 4 files changed, 48 insertions(+), 12 deletions(-) diff --git a/libs/pika/async_mpi/include/pika/async_mpi/dispatch_mpi.hpp b/libs/pika/async_mpi/include/pika/async_mpi/dispatch_mpi.hpp index 27ca26250..71b9366cd 100644 --- a/libs/pika/async_mpi/include/pika/async_mpi/dispatch_mpi.hpp +++ b/libs/pika/async_mpi/include/pika/async_mpi/dispatch_mpi.hpp @@ -237,9 +237,8 @@ namespace pika::mpi::experimental { friend constexpr PIKA_FORCEINLINE auto tag_fallback_invoke(dispatch_mpi_t, Sender&& sender, F&& f) { - auto snd1 = detail::dispatch_mpi_sender{ + return detail::dispatch_mpi_sender{ PIKA_FORWARD(Sender, sender), PIKA_FORWARD(F, f)}; - return pika::execution::experimental::make_unique_any_sender(std::move(snd1)); } template 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 7fd6137c6..7472b6925 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(); @@ -78,14 +80,19 @@ namespace pika::mpi::experimental { if (requests_inline) { - return dispatch_mpi_sender{PIKA_MOVE(sender), PIKA_FORWARD(F, f)} | - let_value(completion_snd); + return std::forward(sender) | + let_value([=, f = std::forward(f)](auto&... args) mutable { + return just(std::forward_as_tuple(args...)) | ex::unpack() | + dispatch_mpi(std::move(f)) | let_value(completion_snd); + }); } else { - auto snd0 = PIKA_FORWARD(Sender, sender) | continues_on(mpi_pool_scheduler(p)); - return dispatch_mpi_sender{PIKA_MOVE(snd0), PIKA_FORWARD(F, f)} | - let_value(completion_snd); + return std::forward(sender) | continues_on(mpi_pool_scheduler(p)) | + let_value([=, f = std::forward(f)](auto&... args) mutable { + return just(std::forward_as_tuple(args...)) | ex::unpack() | + dispatch_mpi(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 c4093ede9..dd69e2ff2 100644 --- a/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp +++ b/libs/pika/async_mpi/tests/unit/algorithm_transform_mpi.cpp @@ -200,14 +200,38 @@ int pika_main() PIKA_TEST_EQ(data, 42); } + // Values passed to transform_mpi should be kept alive by transform_mpi itself + { + int count = 1 << 20; + auto s = ex::just(std::vector{count, 0}, 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.data(), data.size(), datatype, i, comm, request); + }); + 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.x, 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) { int data = 0, count = 1; if (rank == 0) { data = 42; } - auto s = mpi::transform_mpi( - const_reference_sender{count}, [&](int& count, MPI_Request* request) { - MPI_Ibcast(&data, count, datatype, 0, comm, request); + auto s = mpi::transform_mpi(const_reference_sender{count}, + [&](int& count_transform_mpi, MPI_Request* request) { + PIKA_TEST(&count_transform_mpi != &count); + MPI_Ibcast(&data, count_transform_mpi, datatype, 0, comm, request); }); tt::sync_wait(PIKA_MOVE(s)); PIKA_TEST_EQ(data, 42); diff --git a/libs/pika/config/include/pika/config/compiler_specific.hpp b/libs/pika/config/include/pika/config/compiler_specific.hpp index 1526da789..2b851fa98 100644 --- a/libs/pika/config/include/pika/config/compiler_specific.hpp +++ b/libs/pika/config/include/pika/config/compiler_specific.hpp @@ -162,14 +162,20 @@ #endif // clang-format on +# if !defined(__has_feature) +# define PIKA_HAS_FEATURE(x) 0 +# else +# define PIKA_HAS_FEATURE(x) __has_feature(x) +# endif + # if defined(PIKA_HAVE_SANITIZERS) -# if defined(__SANITIZE_ADDRESS__) || (defined(__has_feature) && __has_feature(address_sanitizer)) +# if defined(__SANITIZE_ADDRESS__) || PIKA_HAS_FEATURE(address_sanitizer) # define PIKA_HAVE_ADDRESS_SANITIZER # if defined(PIKA_GCC_VERSION) || defined(PIKA_CLANG_VERSION) # define PIKA_NO_SANITIZE_ADDRESS __attribute__((no_sanitize("address"))) # endif # endif -# if defined(__SANITIZE_THREAD__) || (defined(__has_feature) && __has_feature(thread_sanitizer)) +# if defined(__SANITIZE_THREAD__) || PIKA_HAS_FEATURE(thread_sanitizer) # define PIKA_HAVE_THREAD_SANITIZER # if defined(PIKA_GCC_VERSION) || defined(PIKA_CLANG_VERSION) # define PIKA_NO_SANITIZE_THREAD __attribute__((no_sanitize("thread"))) From c62ba8e6fdc7e38a93a8ae01d5c5e586ede06994 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Mon, 18 Nov 2024 12:10:48 +0100 Subject: [PATCH 2/3] Add release notes for 0.30.1 --- docs/changelog.md | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/docs/changelog.md b/docs/changelog.md index e5e51f357..12db02425 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -6,6 +6,16 @@ # Changelog +## 0.30.1 (2024-11-19) + +### New features + +### Breaking changes + +### Bugfixes + +- A parameter lifetime issue in `transform_mpi` that affects almost all MPI modes was fixed. ([#1321](https://github.com/pika-org/pika/pull/1321)) + ## 0.30.0 (2024-11-08) ### New features From 229ad3d826d63febe88007deadf04d64bce5baa3 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Tue, 19 Nov 2024 09:21:06 +0100 Subject: [PATCH 3/3] Update version and date for 0.30.1 --- CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 04ba838db..afec94efa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,8 +45,8 @@ set_property(GLOBAL PROPERTY USE_FOLDERS ON) # ################################################################################################## set(PIKA_VERSION_MAJOR 0) set(PIKA_VERSION_MINOR 30) -set(PIKA_VERSION_PATCH 0) -set(PIKA_VERSION_DATE 20241108) +set(PIKA_VERSION_PATCH 1) +set(PIKA_VERSION_DATE 20241119) set(PIKA_VERSION_TAG "") set(PIKA_VERSION "${PIKA_VERSION_MAJOR}.${PIKA_VERSION_MINOR}.${PIKA_VERSION_PATCH}")