------------------------------------------------------------------------------
| 298 | } |
| 299 | //------------------------------------------------------------------------------ |
| 300 | int vtkPChacoReader::DivideCells( |
| 301 | vtkMultiProcessController* contr, vtkUnstructuredGrid* output, int source) |
| 302 | { |
| 303 | int retVal = 1; |
| 304 | |
| 305 | int i = 0; |
| 306 | |
| 307 | int nprocs = contr->GetNumberOfProcesses(); |
| 308 | int myrank = contr->GetLocalProcessId(); |
| 309 | |
| 310 | vtkUnstructuredGrid* mygrid = nullptr; |
| 311 | |
| 312 | if (source == myrank) |
| 313 | { |
| 314 | vtkIdType ntotalcells = output->GetNumberOfCells(); |
| 315 | vtkIdType nshare = ntotalcells / nprocs; |
| 316 | vtkIdType leftover = ntotalcells - (nprocs * nshare); |
| 317 | |
| 318 | vtkIdType startId = 0; |
| 319 | |
| 320 | for (i = 0; i < nprocs; i++) |
| 321 | { |
| 322 | if (!retVal && (i != myrank)) |
| 323 | { |
| 324 | this->SendGrid(contr, i, nullptr); // we failed |
| 325 | continue; |
| 326 | } |
| 327 | |
| 328 | vtkIdType ncells = ((i < leftover) ? nshare + 1 : nshare); |
| 329 | |
| 330 | vtkIdType endId = startId + ncells - 1; |
| 331 | |
| 332 | vtkUnstructuredGrid* ug = this->SubGrid(output, startId, endId); |
| 333 | |
| 334 | if (i != myrank) |
| 335 | { |
| 336 | retVal = this->SendGrid(contr, i, ug); |
| 337 | ug->Delete(); |
| 338 | } |
| 339 | else |
| 340 | { |
| 341 | mygrid = ug; |
| 342 | } |
| 343 | startId += ncells; |
| 344 | } |
| 345 | } |
| 346 | else |
| 347 | { |
| 348 | mygrid = this->GetGrid(contr, source); |
| 349 | if (mygrid == nullptr) |
| 350 | { |
| 351 | retVal = 0; |
| 352 | } |
| 353 | } |
| 354 | |
| 355 | int vote = 0; |
| 356 | contr->Reduce(&retVal, &vote, 1, vtkCommunicator::SUM_OP, 0); |
| 357 | contr->Broadcast(&vote, 1, 0); |
no test coverage detected