MCPcopy Create free account
hub / github.com/Kitware/VTK / SynchronizedPrint

Function SynchronizedPrint

Parallel/MPI/vtkMPIUtilities.h:54–105  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

52 */
53template <typename... T>
54void 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}
106template <typename... T>
107VTK_DEPRECATED_IN_9_6_0("Use vtkMPIUtilities::SynchronizedPrint instead")
108void SynchronizedPrintf(vtkMPIController* comm, const char* formatArg, T&&... args)

Calls 7

GetNumberOfProcessesMethod · 0.80
NoBlockSendMethod · 0.80
assertFunction · 0.50
printFunction · 0.50
GetLocalProcessIdMethod · 0.45
ReceiveMethod · 0.45
BarrierMethod · 0.45