Skip to content

Commit

Permalink
Make MPI polling max size atomic
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
msimberg committed Jun 25, 2024
1 parent 13e41fe commit 61555e4
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions libs/pika/async_mpi/src/mpi_polling.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::size_t> max_polling_requests{get_polling_default()};

// The sum of messages in queue + vector
std::atomic<std::uint32_t> all_in_flight_{0};
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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_; }
Expand Down

0 comments on commit 61555e4

Please sign in to comment.