1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
// SPDX-License-Identifier: BSD-3-Clause
#include "vtkDistributedDataFilter.h"
#include "vtkMPIController.h"
#include "vtkMultiProcessController.h"
#include "vtkNew.h"
#include "vtkSmartPointer.h"
#include "vtkTestUtilities.h"
#include "vtkUnstructuredGrid.h"
#include "vtkXMLUnstructuredGridReader.h"
#include <string>
void AbortTest(vtkMPIController* controller, const std::string& message)
{
if (controller->GetLocalProcessId() == 0)
{
vtkErrorWithObjectMacro(nullptr, << message);
}
controller->Finalize();
exit(EXIT_FAILURE);
}
int TestPolyhedralMeshDistributedDataFilter(int argc, char* argv[])
{
vtkNew<vtkMPIController> controller;
controller->Initialize(&argc, &argv, 0);
const int rank = controller->GetLocalProcessId();
vtkMultiProcessController::SetGlobalController(controller);
vtkSmartPointer<vtkUnstructuredGrid> ug;
// Load a full polyhedral mesh on rank 0, others have an empty piece
if (rank == 0)
{
vtkNew<vtkXMLUnstructuredGridReader> r;
char* fname = vtkTestUtilities::ExpandDataFileName(argc, argv, "Data/voronoiMesh.vtu");
r->SetFileName(fname);
r->Update();
ug = r->GetOutput();
delete[] fname;
}
else
{
ug = vtkSmartPointer<vtkUnstructuredGrid>::New();
}
// Fetch number of cells of the full distributed mesh
vtkIdType allNbCells = 0;
vtkIdType localNbCells = ug->GetNumberOfCells();
controller->AllReduce(&localNbCells, &allNbCells, 1, vtkCommunicator::SUM_OP);
if (allNbCells == 0)
{
AbortTest(controller, "ERROR: Check grid failed!");
}
// Distribute the mesh with the D3 filter
vtkNew<vtkDistributedDataFilter> d3;
d3->SetInputData(ug);
d3->SetController(controller);
d3->SetBoundaryMode(0);
d3->SetUseMinimalMemory(0);
d3->SetMinimumGhostLevel(0);
d3->Update();
ug = vtkUnstructuredGrid::SafeDownCast(d3->GetOutput());
// Check that each rank own a piece of the full mesh
int success = ug->GetNumberOfCells() != 0 ? 1 : 0;
int allsuccess = 0;
controller->AllReduce(&success, &allsuccess, 1, vtkCommunicator::MIN_OP);
if (allsuccess == 0)
{
AbortTest(controller, "ERROR: Invalid mesh distribution - some ranks have 0 cell.");
}
// Check that input and output distributed meshes have same number of cells
vtkIdType allOutNbCells = 0;
vtkIdType localOutNbCells = ug->GetNumberOfCells();
controller->AllReduce(&localOutNbCells, &allOutNbCells, 1, vtkCommunicator::SUM_OP);
if (allNbCells != allOutNbCells)
{
AbortTest(controller,
"ERROR: Invalid mesh distribution - input and output mesh have different number of cells.");
}
controller->Finalize();
return EXIT_SUCCESS;
}
|