我正在使用vtkDistributedDataFilter将数据分发到多个进程中。一切正常,除非vtkUnstructuredGrid内有多面体单元。然后,过滤器将引发分段错误。 谁能帮我
当前我是
以下程序会产生分段错误:
#include <mpi.h>
#include "vtkMPIController.h"
#include <vtkActor.h>
#include <vtkCamera.h>
#include <vtkCellArray.h>
#include <vtkCellData.h>
#include <vtkDataArray.h>
#include <vtkDataSetMapper.h>
#include <vtkDistributedDataFilter.h>
#include <vtkIdList.h>
#include <vtkNamedColors.h>
#include <vtkPointData.h>
#include <vtkPoints.h>
#include <vtkPolyhedron.h>
#include <vtkProperty.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkSmartPointer.h>
#include <vtkUnstructuredGrid.h>
#include <vtkVersion.h>
#include <vtkXMLUnstructuredGridWriter.h>
int main(int argc, char** argv)
{
MPI_Init(&argc, &argv);
vtkMPIController *contr = vtkMPIController::New();
contr->Initialize(&argc, &argv, 1);
int world_size;
MPI_Comm_size(MPI_COMM_WORLD, &world_size);
int world_rank;
MPI_Comm_rank(MPI_COMM_WORLD, &world_rank);
printf("%d, %d\n", world_size, world_rank);
vtkSmartPointer<vtkUnstructuredGrid> ugrid =
vtkSmartPointer<vtkUnstructuredGrid>::New();
if(world_rank == 0)
{
vtkIdType pointIds[8] = {0, 1, 2, 3, 4, 5, 6, 7};
vtkSmartPointer<vtkPoints> points =
vtkSmartPointer<vtkPoints>::New();
points->InsertNextPoint(-1.0,-1.0,-1.0);//0
points->InsertNextPoint( 1.0,-1.0,-1.0);//1
points->InsertNextPoint( 1.0, 1.0,-1.0);//2
points->InsertNextPoint(-1.0, 1.0,-1.0);//3
points->InsertNextPoint(-1.0,-1.0, 1.0);//4
points->InsertNextPoint( 1.0,-1.0, 1.0);//5
points->InsertNextPoint( 1.0, 1.0, 1.0);//6
points->InsertNextPoint(-1.0, 1.0, 1.0);//7
points->InsertNextPoint( 2.0,-1.0,-1.0);//8
points->InsertNextPoint( 2.0, 1.0,-1.0);//9
points->InsertNextPoint( 2.0,-1.0, 1.0);//10
points->InsertNextPoint( 2.0, 1.0, 1.0);//11
vtkSmartPointer<vtkCellArray> faces =
vtkSmartPointer<vtkCellArray>::New();
vtkIdType face0[4] = {0, 3, 2, 1};
vtkIdType face1[4] = {0, 4, 7, 3};
vtkIdType face2[4] = {4, 5, 6, 7};
vtkIdType face3[4] = {5, 1, 2, 6};
vtkIdType face4[4] = {0, 1, 5, 4};
vtkIdType face5[4] = {2, 3, 7, 6};
faces->InsertNextCell(4, face0);
faces->InsertNextCell(4, face1);
faces->InsertNextCell(4, face2);
faces->InsertNextCell(4, face3);
faces->InsertNextCell(4, face4);
faces->InsertNextCell(4, face5);
vtkIdType pointIds2[8] = {1, 2, 5, 6, 8, 9, 10, 11};
vtkSmartPointer<vtkCellArray> faces2 =
vtkSmartPointer<vtkCellArray>::New();
vtkIdType face6[4] = {5, 1, 2, 6};
vtkIdType face7[4] = {1, 2, 9, 8};
vtkIdType face8[4] = {2, 6, 11, 9};
vtkIdType face9[4] = {6, 5, 10, 11};
vtkIdType face10[4] = {5, 1, 8, 10};
vtkIdType face11[4] = {11, 10, 8, 9};
faces2->InsertNextCell(4, face6);
faces2->InsertNextCell(4, face7);
faces2->InsertNextCell(4, face8);
faces2->InsertNextCell(4, face9);
faces2->InsertNextCell(4, face10);
faces2->InsertNextCell(4, face11);
ugrid->SetPoints(points);
ugrid->InsertNextCell(VTK_POLYHEDRON, 8, pointIds, 6, faces->GetPointer());
ugrid->InsertNextCell(VTK_POLYHEDRON, 8, pointIds2, 6, faces2->GetPointer());
}
vtkSmartPointer<vtkDistributedDataFilter> distFilter =
vtkSmartPointer<vtkDistributedDataFilter>::New();
distFilter->SetInputData(ugrid);
distFilter->SetController(contr);
distFilter->Update();
MPI_Finalize();
return EXIT_SUCCESS;
}
与此CMakeLists.txt一起编译:
cmake_minimum_required(VERSION 2.8)
PROJECT(Polyhedron)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(Polyhedron MACOSX_BUNDLE Polyhedron.cxx )
target_link_libraries(Polyhedron ${VTK_LIBRARIES})