From 61555e477838b8f8593cedea932dd7a3b34a8b89 Mon Sep 17 00:00:00 2001 From: Mikael Simberg Date: Tue, 25 Jun 2024 14:29:05 +0200 Subject: [PATCH] Make MPI polling max size atomic This avoids data races between writing (set_max_polling_size) and reading (within the MPI polling loop) the max polling size. Reads are relaxed since we don't care much about stale values being used. --- libs/pika/async_mpi/src/mpi_polling.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/libs/pika/async_mpi/src/mpi_polling.cpp b/libs/pika/async_mpi/src/mpi_polling.cpp index b948b1160..e25397986 100644 --- a/libs/pika/async_mpi/src/mpi_polling.cpp +++ b/libs/pika/async_mpi/src/mpi_polling.cpp @@ -113,7 +113,7 @@ namespace pika::mpi::experimental { bool error_handler_initialized_ = false; int rank_ = -1; int size_ = -1; - std::size_t max_polling_requests = get_polling_default(); + std::atomic max_polling_requests{get_polling_default()}; // The sum of messages in queue + vector std::atomic all_in_flight_{0}; @@ -441,7 +441,7 @@ namespace pika::mpi::experimental { int num_completed = 0; // do we poll for N requests at a time, or just 1 - if (mpi_data_.max_polling_requests > 1) + if (mpi_data_.max_polling_requests.load(std::memory_order_relaxed) > 1) { // it seems some MPI implementations choke when the request list is // large, so we will use a max of max_poll_requests per test. @@ -704,7 +704,10 @@ namespace pika::mpi::experimental { void set_max_polling_size(std::size_t p) { detail::mpi_data_.max_polling_requests = p; } // ------------------------------------------------------------- - std::size_t get_max_polling_size() { return detail::mpi_data_.max_polling_requests; } + std::size_t get_max_polling_size() + { + return detail::mpi_data_.max_polling_requests.load(std::memory_order_relaxed); + } // ----------------------------------------------------------------- std::size_t get_completion_mode() { return detail::completion_flags_; }