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

Function GatherMidpoints

IO/ParallelNetCDF/vtkPSLACReader.cxx:232–293  ·  view source on GitHub ↗

------------------------------------------------------------------------------ Convenience function for gathering midpoint information to a process.

Source from the content-addressed store, hash-verified

230//------------------------------------------------------------------------------
231// Convenience function for gathering midpoint information to a process.
232void GatherMidpoints(vtkMultiProcessController* controller, const midpointListsType& sendMidpoints,
233 midpointListsType& recvMidpoints, int process)
234{
235 vtkIdType sendLength = static_cast<vtkIdType>(sendMidpoints.position.size());
236 if (sendLength != static_cast<vtkIdType>(sendMidpoints.topology.size()))
237 {
238 vtkGenericWarningMacro(<< "Bad midpoint array structure.");
239 return;
240 }
241
242 vtkIdType numProcesses = controller->GetNumberOfProcesses();
243
244 // Gather the amount of data each process is going to send.
245 std::vector<vtkIdType> receiveCounts(numProcesses);
246 controller->Gather(&sendLength, &receiveCounts.at(0), 1, process);
247
248 // Get ready the arrays for the receiver that determine how much data
249 // to get and where to put it.
250 std::vector<vtkIdType> positionLengths(numProcesses);
251 std::vector<vtkIdType> positionOffsets(numProcesses);
252 std::vector<vtkIdType> topologyLengths(numProcesses);
253 std::vector<vtkIdType> topologyOffsets(numProcesses);
254
255 const double* sendPositionBuffer =
256 ((sendLength > 0) ? reinterpret_cast<const double*>(&sendMidpoints.position.at(0)) : nullptr);
257 const vtkIdType* sendTopologyBuffer =
258 ((sendLength > 0) ? reinterpret_cast<const vtkIdType*>(&sendMidpoints.topology.at(0))
259 : nullptr);
260 double* recvPositionBuffer;
261 vtkIdType* recvTopologyBuffer;
262
263 if (process == controller->GetLocalProcessId())
264 {
265 vtkIdType numEntries = 0;
266 for (int i = 0; i < numProcesses; i++)
267 {
268 positionLengths[i] = midpointPositionSize * receiveCounts[i];
269 positionOffsets[i] = midpointPositionSize * numEntries;
270 topologyLengths[i] = midpointTopologySize * receiveCounts[i];
271 topologyOffsets[i] = midpointTopologySize * numEntries;
272 numEntries += receiveCounts[i];
273 }
274 recvMidpoints.position.resize(numEntries);
275 recvMidpoints.topology.resize(numEntries);
276
277 recvPositionBuffer =
278 ((numEntries > 0) ? reinterpret_cast<double*>(&recvMidpoints.position.at(0)) : nullptr);
279 recvTopologyBuffer =
280 ((numEntries > 0) ? reinterpret_cast<vtkIdType*>(&recvMidpoints.topology.at(0)) : nullptr);
281 }
282 else
283 {
284 recvPositionBuffer = nullptr;
285 recvTopologyBuffer = nullptr;
286 }
287
288 // Gather the actual data.
289 controller->GatherV(sendPositionBuffer, recvPositionBuffer, midpointPositionSize * sendLength,

Callers 1

Calls 7

GetNumberOfProcessesMethod · 0.80
GatherVMethod · 0.80
sizeMethod · 0.45
GatherMethod · 0.45
atMethod · 0.45
GetLocalProcessIdMethod · 0.45
resizeMethod · 0.45

Tested by

no test coverage detected