Commit 32cf800f authored by Berk Geveci's avatar Berk Geveci Committed by George Zagaris
Browse files

Update the XML readers and writers to work with pipeline changes.

The XML readers and writers, both parallel and serial, now work
with the pipeline changes. Now, all writers work with pieces
even though the structured ones can handle asking for a sub-
extent.

Change-Id: I9f757ba12a3b9fb84e141506dacadad608eb8b99
parent 1a0b4e9d
......@@ -7,6 +7,7 @@ vtk_module(vtkFiltersParallelGeometry
TEST_DEPENDS
vtkIOXML
vtkIOParallel
vtkIOParallelXML
vtkCommonDataModel
vtkParallelMPI
vtkTestingCore
......
......@@ -7,9 +7,6 @@ set(Module_SRCS
vtkPImageWriter.cxx
vtkPOpenFOAMReader.cxx
vtkPSLACReader.cxx
vtkXMLPHierarchicalBoxDataWriter.cxx
vtkXMLPMultiBlockDataWriter.cxx
vtkXMLPUniformGridAMRWriter.cxx
)
vtk_module_library(vtkIOParallel ${Module_SRCS})
set(Module_SRCS
vtkXMLPDataSetWriter.cxx
vtkXMLPDataWriter.cxx
vtkXMLPImageDataWriter.cxx
vtkXMLPPolyDataWriter.cxx
vtkXMLPRectilinearGridWriter.cxx
vtkXMLPStructuredDataWriter.cxx
vtkXMLPStructuredGridWriter.cxx
vtkXMLPUnstructuredDataWriter.cxx
vtkXMLPUnstructuredGridWriter.cxx
vtkXMLPHierarchicalBoxDataWriter.cxx
vtkXMLPMultiBlockDataWriter.cxx
vtkXMLPUniformGridAMRWriter.cxx
)
set_source_files_properties(
vtkXMLPDataWriter
vtkXMLPStructuredDataWriter
vtkXMLPUnstructuredDataWriter
ABSTRACT
)
vtk_module_library(vtkIOParallelXML ${Module_SRCS})
add_test(NAME ${vtk-module}Cxx-testParallelXMLWriters
COMMAND ${MPIEXEC} ${MPIEXEC_NUMPROC_FLAG} 4 ${MPIEXEC_PREFLAGS}
$<TARGET_FILE:pvtkpython> ${CMAKE_CURRENT_SOURCE_DIR}/testParallelXMLWriters.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()
pf = vtk.vtkProgrammableFilter()
def execute():
info = pf.GetOutputInformation(0)
et = vtk.vtkExtentTranslator()
et.SetWholeExtent(info.Get(vtk.vtkStreamingDemandDrivenPipeline.WHOLE_EXTENT()))
et.SetPiece(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER()))
et.SetNumberOfPieces(info.Get(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES()))
et.PieceToExtent()
output = pf.GetOutput()
input = pf.GetInput()
output.ShallowCopy(input)
output.Crop(et.GetExtent())
pf.SetExecuteMethod(execute)
def GetSource(dataType):
s = vtk.vtkRTAnalyticSource()
if dataType == 'ImageData':
return s
elif dataType == 'UnstructuredGrid':
dst = vtk.vtkDataSetTriangleFilter()
dst.SetInputConnection(s.GetOutputPort())
return dst
elif dataType == 'RectilinearGrid':
s.Update()
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())
pf.SetInputData(rg)
return pf
elif dataType == 'StructuredGrid':
s.Update()
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())
pf.SetInputData(sg)
return pf
def TestDataType(dataType, reader, writer, ext, numTris):
s = GetSource(dataType)
filename = VTK_TEMP_DIR + "/%s.p%s" % (dataType, ext)
writer.SetInputConnection(s.GetOutputPort())
npieces = 16
writer.SetNumberOfPieces(npieces)
pperrank = npieces / nranks
start = pperrank * rank
end = start + pperrank - 1
writer.SetStartPiece(start)
writer.SetEndPiece(end)
writer.SetFileName(filename)
#writer.SetDataModeToAscii()
writer.Write()
if contr:
contr.Barrier()
reader.SetFileName(filename)
cf = vtk.vtkContourFilter()
cf.SetValue(0, 130)
cf.SetInputConnection(reader.GetOutputPort())
cf.UpdateInformation()
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_NUMBER_OF_PIECES(), nranks)
cf.GetOutputInformation(0).Set(vtk.vtkStreamingDemandDrivenPipeline.UPDATE_PIECE_NUMBER(), rank)
cf.Update()
ntris = cf.GetOutput().GetNumberOfCells()
da = vtk.vtkIntArray()
da.InsertNextValue(ntris)
da2 = vtk.vtkIntArray()
da2.SetNumberOfTuples(1)
contr.AllReduce(da, da2, vtk.vtkCommunicator.SUM_OP)
if rank == 0:
print da2.GetValue(0)
import os
os.remove(filename)
for i in range(npieces):
os.remove(VTK_TEMP_DIR + "/%s_%d.%s" % (dataType, i, ext))
assert da2.GetValue(0) == numTris
TestDataType('ImageData', vtk.vtkXMLPImageDataReader(), vtk.vtkXMLPImageDataWriter(), 'vti', 4924)
TestDataType('RectilinearGrid', vtk.vtkXMLPRectilinearGridReader(), vtk.vtkXMLPRectilinearGridWriter(), 'vtr', 4924)
TestDataType('StructuredGrid', vtk.vtkXMLPStructuredGridReader(), vtk.vtkXMLPStructuredGridWriter(), 'vts', 4924)
TestDataType('UnstructuredGrid', vtk.vtkXMLPUnstructuredGridReader(), vtk.vtkXMLPUnstructuredGridWriter(), 'vtu', 11856)
vtk_module(vtkIOParallelXML
GROUPS
StandAlone
DEPENDS
vtkIOXML
vtkParallelCore
PRIVATE_DEPENDS
vtksys
)
......@@ -118,20 +118,9 @@ int vtkXMLPDataSetWriter::WriteInternal()
writer->SetGhostLevel(this->GetGhostLevel());
writer->SetStartPiece(this->GetStartPiece());
writer->SetEndPiece(this->GetEndPiece());
writer->SetWriteSummaryFile(this->WriteSummaryFile);
writer->AddObserver(vtkCommand::ProgressEvent, this->ProgressObserver);
// Decide whether to write the summary file.
int writeSummary = 0;
if(this->WriteSummaryFileInitialized)
{
writeSummary = this->WriteSummaryFile;
}
else if(this->StartPiece == 0)
{
writeSummary = 1;
}
writer->SetWriteSummaryFile(writeSummary);
// Try to write.
int result = writer->Write();
......
......@@ -26,10 +26,10 @@
#ifndef __vtkXMLPDataSetWriter_h
#define __vtkXMLPDataSetWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLPDataWriter.h"
class VTKIOXML_EXPORT vtkXMLPDataSetWriter : public vtkXMLPDataWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPDataSetWriter : public vtkXMLPDataWriter
{
public:
vtkTypeMacro(vtkXMLPDataSetWriter,vtkXMLPDataWriter);
......
......@@ -17,9 +17,13 @@
#include "vtkCallbackCommand.h"
#include "vtkDataSet.h"
#include "vtkErrorCode.h"
#include "vtkMultiProcessController.h"
#include <vtksys/ios/sstream>
vtkCxxSetObjectMacro(vtkXMLPDataWriter,
Controller,
vtkMultiProcessController);
//----------------------------------------------------------------------------
vtkXMLPDataWriter::vtkXMLPDataWriter()
......@@ -28,8 +32,7 @@ vtkXMLPDataWriter::vtkXMLPDataWriter()
this->EndPiece = 0;
this->NumberOfPieces = 1;
this->GhostLevel = 0;
this->WriteSummaryFileInitialized = 0;
this->WriteSummaryFile = 0;
this->WriteSummaryFile = 1;
this->PathName = 0;
this->FileNameBase = 0;
......@@ -40,6 +43,9 @@ vtkXMLPDataWriter::vtkXMLPDataWriter()
this->ProgressObserver = vtkCallbackCommand::New();
this->ProgressObserver->SetCallback(&vtkXMLPDataWriter::ProgressCallbackFunction);
this->ProgressObserver->SetClientData(this);
this->Controller = 0;
this->SetController(vtkMultiProcessController::GetGlobalController());
}
//----------------------------------------------------------------------------
......@@ -49,6 +55,7 @@ vtkXMLPDataWriter::~vtkXMLPDataWriter()
delete [] this->FileNameBase;
delete [] this->FileNameExtension;
delete [] this->PieceFileNameExtension;
this->SetController(0);
this->ProgressObserver->Delete();
}
......@@ -66,7 +73,6 @@ void vtkXMLPDataWriter::PrintSelf(ostream& os, vtkIndent indent)
//----------------------------------------------------------------------------
void vtkXMLPDataWriter::SetWriteSummaryFile(int flag)
{
this->WriteSummaryFileInitialized = 1;
vtkDebugMacro(<< this->GetClassName() << " ("
<< this << "): setting WriteSummaryFile to " << flag);
if(this->WriteSummaryFile != flag)
......@@ -91,13 +97,12 @@ int vtkXMLPDataWriter::WriteInternal()
// Decide whether to write the summary file.
int writeSummary = 0;
if(this->WriteSummaryFileInitialized)
{
writeSummary = this->WriteSummaryFile;
}
else if(this->StartPiece == 0)
if(this->WriteSummaryFile)
{
writeSummary = 1;
if (!this->Controller || this->Controller->GetLocalProcessId() == 0)
{
writeSummary = this->WriteSummaryFile;
}
}
// Write the summary file if requested.
......
......@@ -22,12 +22,13 @@
#ifndef __vtkXMLPDataWriter_h
#define __vtkXMLPDataWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLWriter.h"
class vtkCallbackCommand;
class vtkMultiProcessController;
class VTKIOXML_EXPORT vtkXMLPDataWriter : public vtkXMLWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPDataWriter : public vtkXMLWriter
{
public:
vtkTypeMacro(vtkXMLPDataWriter,vtkXMLWriter);
......@@ -51,13 +52,21 @@ public:
vtkGetMacro(GhostLevel, int);
// Description:
// Get/Set whether this instance of the writer should write the
// summary file that refers to all of the pieces' individual files.
// Default is yes only for piece 0 writer.
// Get/Set whether the writer should write the summary file that
// refers to all of the pieces' individual files.
// This is on by default. Note that only the first process writes
// the summary file.
virtual void SetWriteSummaryFile(int flag);
vtkGetMacro(WriteSummaryFile, int);
vtkBooleanMacro(WriteSummaryFile, int);
// Description:
// Controller used to communicate data type of blocks.
// By default, the global controller is used. If you want another
// controller to be used, set it with this.
virtual void SetController(vtkMultiProcessController*);
vtkGetObjectMacro(Controller, vtkMultiProcessController);
protected:
vtkXMLPDataWriter();
~vtkXMLPDataWriter();
......@@ -74,8 +83,8 @@ protected:
char* CreatePieceFileName(int index, const char* path=0);
void SplitFileName();
int WritePieces();
int WritePiece(int index);
virtual int WritePieces();
virtual int WritePiece(int index);
// Callback registered with the ProgressObserver.
static void ProgressCallbackFunction(vtkObject*, unsigned long, void*,
......@@ -88,7 +97,6 @@ protected:
int NumberOfPieces;
int GhostLevel;
int WriteSummaryFile;
int WriteSummaryFileInitialized;
char* PathName;
char* FileNameBase;
......@@ -98,6 +106,8 @@ protected:
// The observer to report progress from the internal writer.
vtkCallbackCommand* ProgressObserver;
vtkMultiProcessController* Controller;
private:
vtkXMLPDataWriter(const vtkXMLPDataWriter&); // Not implemented.
void operator=(const vtkXMLPDataWriter&); // Not implemented.
......
......@@ -22,8 +22,9 @@
#define __vtkXMLPHierarchicalBoxDataWriter_h
#include "vtkXMLPUniformGridAMRWriter.h"
#include "vtkIOParallelXMLModule.h" // For export macro
class VTKIOPARALLEL_EXPORT vtkXMLPHierarchicalBoxDataWriter :
class VTKIOPARALLELXML_EXPORT vtkXMLPHierarchicalBoxDataWriter :
public vtkXMLPUniformGridAMRWriter
{
public:
......
......@@ -26,12 +26,12 @@
#ifndef __vtkXMLPImageDataWriter_h
#define __vtkXMLPImageDataWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLPStructuredDataWriter.h"
class vtkImageData;
class VTKIOXML_EXPORT vtkXMLPImageDataWriter : public vtkXMLPStructuredDataWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPImageDataWriter : public vtkXMLPStructuredDataWriter
{
public:
static vtkXMLPImageDataWriter* New();
......
......@@ -23,13 +23,13 @@
#ifndef __vtkXMLPMultiBlockDataWriter_h
#define __vtkXMLPMultiBlockDataWriter_h
#include "vtkIOParallelModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLMultiBlockDataWriter.h"
class vtkCompositeDataSet;
class vtkMultiProcessController;
class VTKIOPARALLEL_EXPORT vtkXMLPMultiBlockDataWriter : public vtkXMLMultiBlockDataWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPMultiBlockDataWriter : public vtkXMLMultiBlockDataWriter
{
public:
static vtkXMLPMultiBlockDataWriter* New();
......@@ -114,5 +114,3 @@ private:
};
#endif
......@@ -26,12 +26,12 @@
#ifndef __vtkXMLPPolyDataWriter_h
#define __vtkXMLPPolyDataWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLPUnstructuredDataWriter.h"
class vtkPolyData;
class VTKIOXML_EXPORT vtkXMLPPolyDataWriter : public vtkXMLPUnstructuredDataWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPPolyDataWriter : public vtkXMLPUnstructuredDataWriter
{
public:
static vtkXMLPPolyDataWriter* New();
......
......@@ -27,12 +27,12 @@
#ifndef __vtkXMLPRectilinearGridWriter_h
#define __vtkXMLPRectilinearGridWriter_h
#include "vtkIOXMLModule.h" // For export macro
#include "vtkIOParallelXMLModule.h" // For export macro
#include "vtkXMLPStructuredDataWriter.h"
class vtkRectilinearGrid;
class VTKIOXML_EXPORT vtkXMLPRectilinearGridWriter : public vtkXMLPStructuredDataWriter
class VTKIOPARALLELXML_EXPORT vtkXMLPRectilinearGridWriter : public vtkXMLPStructuredDataWriter
{
public:
static vtkXMLPRectilinearGridWriter* New();
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment