Commit 24a324ef authored by Berk Geveci's avatar Berk Geveci Committed by George Zagaris
Browse files

Cleaned up and fixed transmit filters for structured data.

Change-Id: I7e5c55259159752882c8ae056e08f9bec12b3c02
parent 32cf800f
......@@ -30,6 +30,7 @@ set(Module_SRCS
vtkProcessIdScalars.cxx
vtkRectilinearGridOutlineFilter.cxx
vtkTransmitPolyDataPiece.cxx
vtkTransmitStructuredDataPiece.cxx
vtkTransmitRectilinearGridPiece.cxx
vtkTransmitStructuredGridPiece.cxx
vtkTransmitUnstructuredGridPiece.cxx
......
......@@ -107,6 +107,7 @@ void MyProcess::Execute()
spr->SetFileName(fname);
sp = spr->GetOutput();
sp->Register(0);
spr->Update();
......@@ -125,6 +126,7 @@ void MyProcess::Execute()
}
else
{
sp = vtkStructuredPoints::New();
}
vtkMPICommunicator *comm =
......@@ -138,6 +140,7 @@ void MyProcess::Execute()
{
spr->Delete();
}
sp->Delete();
prm->Delete();
return;
}
......@@ -145,13 +148,7 @@ void MyProcess::Execute()
// FILTER WE ARE TRYING TO TEST
vtkTransmitImageDataPiece *pass = vtkTransmitImageDataPiece::New();
pass->SetController(this->Controller);
if (me == 0)
{
pass->SetInputData(sp);
}
else
{
}
pass->SetInputData(sp);
// FILTERING
vtkContourFilter *cf = vtkContourFilter::New();
......@@ -181,16 +178,6 @@ void MyProcess::Execute()
prm->SetRenderWindow(renWin);
prm->SetController(this->Controller);
prm->InitializeOffScreen(); // Mesa GL only
if (me == 0)
{
prm->ResetAllCameras();
}
// We must update the whole pipeline here, otherwise node 0
// goes into GetActiveCamera which updates the pipeline, putting
// it into vtkDistributedDataFilter::Execute() which then hangs.
// If it executes here, dd will be up-to-date won't have to
// execute in GetActiveCamera.
mapper->SetPiece(me);
mapper->SetNumberOfPieces(numProcs);
......@@ -204,6 +191,8 @@ void MyProcess::Execute()
//camera->UpdateViewport(renderer);
camera->SetParallelScale(16);
prm->ResetAllCameras();
renWin->Render();
renWin->Render();
......@@ -234,6 +223,7 @@ void MyProcess::Execute()
{
spr->Delete();
}
sp->Delete();
prm->Delete();
}
......
......@@ -121,6 +121,10 @@ void MyProcess::Execute()
go = 0;
}
}
else
{
sp = vtkSmartPointer<vtkStructuredPoints>::New();
}
vtkMPICommunicator *comm =
vtkMPICommunicator::SafeDownCast(this->Controller->GetCommunicator());
......@@ -134,10 +138,7 @@ void MyProcess::Execute()
vtkSmartPointer<vtkTransmitImageDataPiece> pass =
vtkSmartPointer<vtkTransmitImageDataPiece>::New();
pass->SetController(this->Controller);
if (me == 0)
{
pass->SetInputData(sp);
}
pass->SetInputData(sp);
// FILTERING
vtkSmartPointer<vtkContourFilter> cf =
......@@ -204,7 +205,6 @@ void MyProcess::Execute()
prm->InitializeOffScreen(); // Mesa GL only
if (me == 0)
{
prm->ResetAllCameras();
}
// We must update the whole pipeline here, otherwise node 0
......@@ -213,19 +213,10 @@ void MyProcess::Execute()
// If it executes here, dd will be up-to-date won't have to
// execute in GetActiveCamera.
// mapper->SetPiece(me);
// mapper->SetNumberOfPieces(numProcs);
mapper->SetPiece(me);
mapper->SetNumberOfPieces(numProcs);
mapper->Update();
if (me ==1)
{
vtkSmartPointer<vtkPolyDataWriter> writer =
vtkSmartPointer<vtkPolyDataWriter>::New();
writer->SetInputConnection(elev->GetOutputPort());
writer->SetFileName("contour1.vtk");
writer->Write();
}
const int MY_RETURN_VALUE_MESSAGE=0x11;
if (me == 0)
......@@ -234,6 +225,8 @@ void MyProcess::Execute()
//camera->UpdateViewport(renderer);
camera->SetParallelScale(16);
prm->ResetAllCameras();
renWin->Render();
renWin->Render();
......
......@@ -105,6 +105,7 @@ void MyProcess::Execute()
rgr->SetFileName(fname);
rg = rgr->GetOutput();
rg->Register(0);
rgr->Update();
......@@ -118,6 +119,10 @@ void MyProcess::Execute()
go = 0;
}
}
else
{
rg = vtkRectilinearGrid::New();
}
vtkMPICommunicator *comm =
vtkMPICommunicator::SafeDownCast(this->Controller->GetCommunicator());
......@@ -130,6 +135,7 @@ void MyProcess::Execute()
{
rgr->Delete();
}
rg->Delete();
prm->Delete();
return;
}
......@@ -137,10 +143,7 @@ void MyProcess::Execute()
// FILTER WE ARE TRYING TO TEST
vtkTransmitRectilinearGridPiece *pass = vtkTransmitRectilinearGridPiece::New();
pass->SetController(this->Controller);
if (me == 0)
{
pass->SetInputData(rg);
}
pass->SetInputData(rg);
// FILTERING
vtkContourFilter *cf = vtkContourFilter::New();
......@@ -170,10 +173,6 @@ void MyProcess::Execute()
prm->SetRenderWindow(renWin);
prm->SetController(this->Controller);
prm->InitializeOffScreen(); // Mesa GL only
if (me == 0)
{
prm->ResetAllCameras();
}
// We must update the whole pipeline here, otherwise node 0
// goes into GetActiveCamera which updates the pipeline, putting
......@@ -193,6 +192,8 @@ void MyProcess::Execute()
//camera->UpdateViewport(renderer);
camera->SetParallelScale(16);
prm->ResetAllCameras();
renWin->Render();
renWin->Render();
......@@ -223,6 +224,7 @@ void MyProcess::Execute()
{
rgr->Delete();
}
rg->Delete();
prm->Delete();
}
......
......@@ -104,6 +104,7 @@ void MyProcess::Execute()
sgr->SetFileName(fname);
sg = sgr->GetOutput();
sg->Register(0);
sgr->Update();
......@@ -117,6 +118,10 @@ void MyProcess::Execute()
go = 0;
}
}
else
{
sg = vtkStructuredGrid::New();
}
vtkMPICommunicator *comm =
vtkMPICommunicator::SafeDownCast(this->Controller->GetCommunicator());
......@@ -129,6 +134,7 @@ void MyProcess::Execute()
{
sgr->Delete();
}
sg->Delete();
prm->Delete();
return;
}
......@@ -136,10 +142,7 @@ void MyProcess::Execute()
// FILTER WE ARE TRYING TO TEST
vtkTransmitStructuredGridPiece *pass = vtkTransmitStructuredGridPiece::New();
pass->SetController(this->Controller);
if (me == 0)
{
pass->SetInputData(sg);
}
pass->SetInputData(sg);
// FILTERING
vtkContourFilter *cf = vtkContourFilter::New();
......@@ -169,10 +172,6 @@ void MyProcess::Execute()
prm->SetRenderWindow(renWin);
prm->SetController(this->Controller);
prm->InitializeOffScreen(); // Mesa GL only
if (me == 0)
{
prm->ResetAllCameras();
}
// We must update the whole pipeline here, otherwise node 0
// goes into GetActiveCamera which updates the pipeline, putting
......@@ -192,6 +191,8 @@ void MyProcess::Execute()
//camera->UpdateViewport(renderer);
camera->SetParallelScale(16);
prm->ResetAllCameras();
renWin->Render();
renWin->Render();
......@@ -222,6 +223,7 @@ void MyProcess::Execute()
{
sgr->Delete();
}
sg->Delete();
prm->Delete();
}
......
vtk_add_test_python(
RectOutline.py
TestCutMaterial.py
TestExtractCTHPart.py
TestExtrudePiece.py
TestImageStreamer.py
)
vtk_add_test_python(RectOutline.py)
vtk_add_test_python(TestCutMaterial.py)
vtk_add_test_python(TestExtractCTHPart.py)
vtk_add_test_python(TestExtrudePiece.py)
vtk_add_test_python(TestImageStreamer.py)
add_test(NAME ${vtk-module}Python-testTransmit
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS}
$<TARGET_FILE:pvtkpython> ${CMAKE_CURRENT_SOURCE_DIR}/testTransmit.py
${VTK_MPI_POSTFLAGS})
\ No newline at end of file
import vtk
from vtk.test import Testing
from vtk.util.misc import vtkGetTempDir
VTK_TEMP_DIR = vtkGetTempDir()
contr = vtk.vtkMultiProcessController.GetGlobalController()
if not contr:
nranks = 1
rank = 0
else:
nranks = contr.GetNumberOfProcesses()
rank = contr.GetLocalProcessId()
def GetSource(dataType):
s = vtk.vtkRTAnalyticSource()
# Fake serial source
if rank == 0:
s.Update()
if dataType == 'ImageData':
return s.GetOutput()
elif dataType == 'UnstructuredGrid':
dst = vtk.vtkDataSetTriangleFilter()
dst.SetInputData(s.GetOutput())
dst.Update()
return dst.GetOutput()
elif dataType == 'RectilinearGrid':
input = s.GetOutput()
rg = vtk.vtkRectilinearGrid()
rg.SetExtent(input.GetExtent())
dims = input.GetDimensions()
spacing = input.GetSpacing()
x = vtk.vtkFloatArray()
x.SetNumberOfTuples(dims[0])
for i in range(dims[0]):
x.SetValue(i, spacing[0]*i)
y = vtk.vtkFloatArray()
y.SetNumberOfTuples(dims[1])
for i in range(dims[1]):
y.SetValue(i, spacing[1]*i)
z = vtk.vtkFloatArray()
z.SetNumberOfTuples(dims[2])
for i in range(dims[2]):
z.SetValue(i, spacing[2]*i)
rg.SetXCoordinates(x)
rg.SetYCoordinates(y)
rg.SetZCoordinates(z)
rg.GetPointData().ShallowCopy(input.GetPointData())
return rg
elif dataType == 'StructuredGrid':
input = s.GetOutput()
sg = vtk.vtkStructuredGrid()
sg.SetExtent(input.GetExtent())
pts = vtk.vtkPoints()
sg.SetPoints(pts)
npts = input.GetNumberOfPoints()
for i in xrange(npts):
pts.InsertNextPoint(input.GetPoint(i))
sg.GetPointData().ShallowCopy(input.GetPointData())
return sg
def TestDataType(dataType, filter):
if rank == 0:
print dataType
s = GetSource(dataType)
da = vtk.vtkIntArray()
da.SetNumberOfTuples(6)
if rank == 0:
try:
ext = s.GetExtent()
except:
ext = (0, -1, 0, -1, 0, -1)
for i in range(6):
da.SetValue(i, ext[i])
contr.Broadcast(da, 0)
ext = []
for i in range(6):
ext.append(da.GetValue(i))
ext = tuple(ext)
tp = vtk.vtkTrivialProducer()
tp.SetOutput(s)
tp.SetWholeExtent(ext)
ncells = vtk.vtkIntArray()
ncells.SetNumberOfTuples(1)
if rank == 0:
ncells.SetValue(0, s.GetNumberOfCells())
contr.Broadcast(ncells, 0)
result = vtk.vtkIntArray()
result.SetNumberOfTuples(1)
result.SetValue(0, 1)
if rank > 0:
if s.GetNumberOfCells() != 0:
result.SetValue(0, 0)
filter.SetInputConnection(tp.GetOutputPort())
filter.UpdateInformation()
filter.SetUpdateExtent(rank, nranks, 0)
filter.Update()
if filter.GetOutput().GetNumberOfCells() != ncells.GetValue(0) / nranks:
result.SetValue(0, 0)
filter.UpdateInformation()
filter.SetUpdateExtent(rank, nranks, 1)
filter.Update()
gl = filter.GetOutput().GetCellData().GetArray("vtkGhostLevels")
if not gl:
result.SetValue(0, 0)
else:
rng = gl.GetRange()
if rng[1] != 1:
result.SetValue(0, 0)
resArray = vtk.vtkIntArray()
resArray.SetNumberOfTuples(1)
contr.AllReduce(result, resArray, vtk.vtkCommunicator.MIN_OP)
assert resArray.GetValue(0) == 1
TestDataType('ImageData', vtk.vtkTransmitImageDataPiece())
TestDataType('RectilinearGrid', vtk.vtkTransmitRectilinearGridPiece())
TestDataType('StructuredGrid', vtk.vtkTransmitStructuredGridPiece())
TestDataType('UnstructuredGrid', vtk.vtkTransmitUnstructuredGridPiece())
......@@ -45,45 +45,6 @@ vtkTransmitPolyDataPiece::~vtkTransmitPolyDataPiece()
this->SetController(NULL);
}
//----------------------------------------------------------------------------
int vtkTransmitPolyDataPiece::RequestUpdateExtent(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *vtkNotUsed(outputVector))
{
// get the info object
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
if (this->Controller == NULL)
{
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
1);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(), 0);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
0);
return 1;
}
if (this->Controller->GetLocalProcessId() == 0)
{ // Request everything.
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
1);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(), 0);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
0);
}
else
{ // Request nothing.
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES(),
0);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER(),
0);
inInfo->Set(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS(),
0);
}
return 1;
}
//----------------------------------------------------------------------------
int vtkTransmitPolyDataPiece::RequestData(
vtkInformation *vtkNotUsed(request),
......
......@@ -12,12 +12,13 @@
PURPOSE. See the above copyright notice for more information.
=========================================================================*/
// .NAME vtkTransmitPolyDataPiece - Return specified piece, including specified
// number of ghost levels.
// .NAME vtkTransmitRectilinearGridPiece - Redistributes data produced
// by serial readers
//
// .SECTION Description
// This filter updates the appropriate piece by requesting the piece from
// process 0. Process 0 always updates all of the data. It is important that
// Execute get called on all processes, otherwise the filter will deadlock.
// This filter can be used to redistribute data from producers that can't
// produce data in parallel. All data is produced on first process and
// the distributed to others using the multiprocess controller.
#ifndef __vtkTransmitPolyDataPiece_h
......@@ -55,7 +56,6 @@ protected:
int RequestData(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
void RootExecute(vtkPolyData *input, vtkPolyData *output, vtkInformation *outInfo);
void SatelliteExecute(int procId, vtkPolyData *output, vtkInformation *outInfo);
int RequestUpdateExtent(vtkInformation *, vtkInformationVector **, vtkInformationVector *);
int CreateGhostCells;
vtkMultiProcessController *Controller;
......
......@@ -14,356 +14,22 @@
=========================================================================*/
#include "vtkTransmitRectilinearGridPiece.h"
#include "vtkCellData.h"
#include "vtkExtractRectilinearGrid.h"
#include "vtkInformation.h"
#include "vtkInformationVector.h"
#include "vtkMultiProcessController.h"
#include "vtkObjectFactory.h"
#include "vtkPointData.h"
#include "vtkStreamingDemandDrivenPipeline.h"
#include "vtkRectilinearGrid.h"
#include "vtkDoubleArray.h"
vtkStandardNewMacro(vtkTransmitRectilinearGridPiece);
vtkCxxSetObjectMacro(vtkTransmitRectilinearGridPiece,Controller,
vtkMultiProcessController);
//----------------------------------------------------------------------------
vtkTransmitRectilinearGridPiece::vtkTransmitRectilinearGridPiece()
{
this->Controller = NULL;
this->CreateGhostCells = 1;
this->SetNumberOfInputPorts(1);
this->SetController(vtkMultiProcessController::GetGlobalController());
if (this->Controller)
{
if (this->Controller->GetLocalProcessId() != 0)
{
this->SetNumberOfInputPorts(0);
}
}
}
//----------------------------------------------------------------------------
vtkTransmitRectilinearGridPiece::~vtkTransmitRectilinearGridPiece()
{
this->SetController(NULL);
}
//----------------------------------------------------------------------------
int vtkTransmitRectilinearGridPiece::RequestInformation(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *outputVector)
{
if (this->Controller == NULL)
{
return 1;
}
else
{
int wExtent[6] = {0,-1,0,-1,0,-1};
vtkInformation *outInfo = outputVector->GetInformationObject(0);
if (this->Controller->GetLocalProcessId() == 0)
{
//Root sends meta-information to the satellites.
vtkInformation *inInfo = inputVector[0]->GetInformationObject(0);
inInfo->Get(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(), wExtent);
int numProcs = this->Controller->GetNumberOfProcesses();
for (int i = 1; i < numProcs; ++i)
{
this->Controller->Send(wExtent, 6, i, 22342);
}
}
else
{
//Satellites ask root for meta-info, because they do not read it themselves.
this->Controller->Receive(wExtent, 6, 0, 22342);
vtkRectilinearGrid *output = vtkRectilinearGrid::SafeDownCast(
outInfo->Get(vtkDataObject::DATA_OBJECT()));
output->SetExtent(wExtent);
}
outInfo->Set(vtkStreamingDemandDrivenPipeline::WHOLE_EXTENT(),
wExtent,
6);
return 1;
}
}
//----------------------------------------------------------------------------
int vtkTransmitRectilinearGridPiece::RequestUpdateExtent(
vtkInformation *vtkNotUsed(request),
vtkInformationVector **inputVector,
vtkInformationVector *vtkNotUsed(outputVector))
{
// get the info object
if (this->Controller == NULL)
{