| 52 | */ |
| 53 | template <typename... T> |
| 54 | void SynchronizedPrint(vtkMPIController* comm, const char* format, T&&... args) |
| 55 | { |
| 56 | assert(comm != nullptr); |
| 57 | int rank = comm->GetLocalProcessId(); |
| 58 | int numRanks = comm->GetNumberOfProcesses(); |
| 59 | |
| 60 | vtkMPICommunicator::Request rqst; |
| 61 | int* nullmsg = nullptr; |
| 62 | |
| 63 | if (rank == 0) |
| 64 | { |
| 65 | // STEP 0: print message |
| 66 | vtk::print("[{:d}]: ", rank); |
| 67 | std::fflush(stdout); |
| 68 | |
| 69 | vtk::print(format, std::forward<T>(args)...); |
| 70 | std::fflush(stdout); |
| 71 | |
| 72 | // STEP 1: signal next process (if any) to print |
| 73 | if (numRanks > 1) |
| 74 | { |
| 75 | comm->NoBlockSend(nullmsg, 0, rank + 1, 0, rqst); |
| 76 | } // END if |
| 77 | } // END first rank |
| 78 | else if (rank == numRanks - 1) |
| 79 | { |
| 80 | // STEP 0: Block until previous process completes |
| 81 | comm->Receive(nullmsg, 0, rank - 1, 0); |
| 82 | |
| 83 | // STEP 1: print message |
| 84 | vtk::print("[{:d}]: ", rank); |
| 85 | |
| 86 | vtk::print(format, std::forward<T>(args)...); |
| 87 | std::fflush(stdout); |
| 88 | } // END last rank |
| 89 | else |
| 90 | { |
| 91 | // STEP 0: Block until previous process completes |
| 92 | comm->Receive(nullmsg, 0, rank - 1, 0); |
| 93 | |
| 94 | // STEP 1: print message |
| 95 | vtk::print("[{:d}]: ", rank); |
| 96 | |
| 97 | vtk::print(format, std::forward<T>(args)...); |
| 98 | std::fflush(stdout); |
| 99 | |
| 100 | // STEP 2: signal next process to print |
| 101 | comm->NoBlockSend(nullmsg, 0, rank + 1, 0, rqst); |
| 102 | } |
| 103 | |
| 104 | comm->Barrier(); |
| 105 | } |
| 106 | template <typename... T> |
| 107 | VTK_DEPRECATED_IN_9_6_0("Use vtkMPIUtilities::SynchronizedPrint instead") |
| 108 | void SynchronizedPrintf(vtkMPIController* comm, const char* formatArg, T&&... args) |