From 0d6cdc0c6d484ff87fbf9067ad57a3ce538f6ccd Mon Sep 17 00:00:00 2001 From: noobpwnftw Date: Mon, 16 Jul 2018 04:27:44 +0800 Subject: [PATCH] Implement yielding loop while waiting for input Some MPI implementations use busy-wait pooling, which will turn MPI_Bcast into busy-wait loop, workaround with our own yielding loop. --- src/cluster.cpp | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/src/cluster.cpp b/src/cluster.cpp index 44a830b0..940a8ee9 100644 --- a/src/cluster.cpp +++ b/src/cluster.cpp @@ -124,6 +124,23 @@ bool getline(std::istream& input, std::string& str) { vec.assign(str.begin(), str.end()); size = vec.size(); } + + // Some MPI implementations use busy-wait pooling, while we need yielding + static MPI_Request reqInput = MPI_REQUEST_NULL; + MPI_Ibarrier(InputComm, &reqInput); + if (is_root()) + MPI_Wait(&reqInput, MPI_STATUS_IGNORE); + else { + while (true) { + static int flag; + MPI_Test(&reqInput, &flag, MPI_STATUS_IGNORE); + if (flag) + break; + else + std::this_thread::sleep_for(std::chrono::milliseconds(10)); + } + } + MPI_Bcast(&size, 1, MPI_UNSIGNED_LONG, 0, InputComm); if (!is_root()) vec.resize(size);