------------------------------------------------------------------------------ Convenience function for gathering midpoint information to a process.
| 230 | //------------------------------------------------------------------------------ |
| 231 | // Convenience function for gathering midpoint information to a process. |
| 232 | void 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, |
no test coverage detected