| 43 | } |
| 44 | |
| 45 | void MpiRuntime::wait(MPI_Request& request, const char* operation, bool idle, bool short_poll) { |
| 46 | const auto start = std::chrono::steady_clock::now(); |
| 47 | const auto deadline = start + timeout_; |
| 48 | for (;;) { |
| 49 | int completed = 0; |
| 50 | check(MPI_Test(&request, &completed, MPI_STATUS_IGNORE), operation); |
| 51 | if (completed) return; |
| 52 | const auto now = std::chrono::steady_clock::now(); |
| 53 | if (!idle && now >= deadline) fail(std::string(operation) + ": timeout"); |
| 54 | if (short_poll && now - start < std::chrono::milliseconds(2)) std::this_thread::yield(); |
| 55 | else std::this_thread::sleep_for(idle ? std::chrono::microseconds(1000) : std::chrono::microseconds(50)); |
| 56 | } |
| 57 | } |
| 58 | |
| 59 | void MpiRuntime::broadcast(std::span<std::byte> bytes) { |
| 60 | if (bytes.empty() || bytes.size() > max_prompt_bytes) fail("broadcast payload must contain 1 byte..8 MiB"); |