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

Function syncValues

IO/EnSight/vtkEnSightSOSGoldReader.cxx:85–152  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

83#if VTK_MODULE_ENABLE_VTK_ParallelMPI
84template <class T>
85bool syncValues(T* data, int numValues, int numPieces, vtkMultiProcessController* controller)
86{
87 // Compare values on all processes that will read real pieces.
88 // Returns whether the values match. If they match, all processes'
89 // values are modified to match that of node 0. This will leave the
90 // values unchanged on processes that will read real data, but
91 // inform the other processes of the proper values.
92
93 if (!controller)
94 {
95 return true;
96 }
97
98 vtkMPICommunicator* communicator =
99 vtkMPICommunicator::SafeDownCast(controller->GetCommunicator());
100
101 if (!communicator)
102 {
103 if (controller->GetNumberOfProcesses() == 1)
104 {
105 return true;
106 }
107 else
108 {
109 return false;
110 }
111 }
112
113 int numProcs = controller->GetNumberOfProcesses();
114 int myid = controller->GetLocalProcessId();
115
116 // Collect all the values to node 0.
117 T* values = new T[numProcs * numValues];
118 communicator->Gather(data, values, numValues, 0);
119
120 int result = VTK_OK;
121 // Node 0 compares its values to those from other processes that
122 // will actually be reading data.
123 if (myid == 0)
124 {
125 for (int i = 1; result && (i < numPieces); i++)
126 {
127 for (int j = 0; result && (j < numValues); j++)
128 {
129 if (values[i * numValues + j] != values[j])
130 {
131 result = VTK_ERROR;
132 }
133 }
134 }
135 }
136
137 // Free buffer where values were collected.
138 delete[] values;
139
140 // Broadcast result of comparison to all processes.
141 communicator->Broadcast(&result, 1, 0);
142

Callers 1

RequestInformationMethod · 0.85

Calls 5

GetNumberOfProcessesMethod · 0.80
GetCommunicatorMethod · 0.45
GetLocalProcessIdMethod · 0.45
GatherMethod · 0.45
BroadcastMethod · 0.45

Tested by

no test coverage detected