Commit 2e541e5c authored by Berk Geveci's avatar Berk Geveci Committed by Utkarsh Ayachit

Making the Plot3D reader parallel.

Updating vtkMultiBlockPLOT3DReader to enable parallel reading support.
vtkMultiBlockPLOT3DReader can now read subextents in parallel on
different ranks using POSIX I/O.
parent 34d5b074
This diff is collapsed.
......@@ -83,17 +83,18 @@
#ifndef vtkMultiBlockPLOT3DReader_h
#define vtkMultiBlockPLOT3DReader_h
#include "vtkIOGeometryModule.h" // For export macro
#include "vtkIOParallelModule.h" // For export macro
#include "vtkMultiBlockDataSetAlgorithm.h"
class vtkDataArray;
class vtkUnsignedCharArray;
class vtkIntArray;
class vtkStructuredGrid;
//BTX
class vtkMultiProcessController;
struct vtkMultiBlockPLOT3DReaderInternals;
//ETX
class VTKIOGEOMETRY_EXPORT vtkMultiBlockPLOT3DReader : public vtkMultiBlockDataSetAlgorithm
class VTKIOPARALLEL_EXPORT vtkMultiBlockPLOT3DReader : public vtkMultiBlockDataSetAlgorithm
{
public:
static vtkMultiBlockPLOT3DReader *New();
......@@ -233,9 +234,10 @@ public:
virtual int CanReadBinaryFile(const char* fname);
// Description:
// Overwritten to make sure that RequestInformation reads the meta-data
// again after the reader parameters were changed.
virtual void Modified();
// Set/Get the communicator object (we'll use global World controller
// if you don't set a different one).
void SetController(vtkMultiProcessController *c);
vtkGetObjectMacro(Controller, vtkMultiProcessController);
//BTX
enum
......@@ -256,11 +258,28 @@ protected:
int CheckSolutionFile(FILE*& qFp);
int CheckFunctionFile(FILE*& fFp);
int GetByteCountSize();
int SkipByteCount (FILE* fp);
int ReadIntBlock (FILE* fp, int n, int* block);
int ReadScalar(FILE* fp, int n, vtkDataArray* scalar);
int ReadVector(FILE* fp, int n, int numDims, vtkDataArray* vector);
int ReadValues(
FILE* fp,
int n,
vtkDataArray* scalar);
virtual int ReadIntScalar(
void* vfp,
int extent[6], int wextent[6],
vtkDataArray* scalar, vtkTypeUInt64 offset);
virtual int ReadScalar(
void* vfp,
int extent[6], int wextent[6],
vtkDataArray* scalar, vtkTypeUInt64 offset);
virtual int ReadVector(
void* vfp,
int extent[6], int wextent[6],
int numDims, vtkDataArray* vector, vtkTypeUInt64 offset);
virtual int OpenFileForDataRead(void*& fp, const char* fname);
virtual void CloseFile(void* fp);
int GetNumberOfBlocksInternal(FILE* xyzFp, int allocate);
......@@ -273,7 +292,6 @@ protected:
int AutoDetectionCheck(FILE* fp);
void AssignAttribute(int fNumber, vtkStructuredGrid* output,
int attributeType);
void MapFunction(int fNumber, vtkStructuredGrid* output);
......@@ -317,6 +335,8 @@ protected:
int DoublePrecision;
int AutoDetectFormat;
int ExecutedGhostLevels;
long FileSize;
//parameters used in computing derived functions
......@@ -343,6 +363,8 @@ protected:
vtkMultiBlockPLOT3DReaderInternals* Internal;
vtkMultiProcessController *Controller;
private:
vtkMultiBlockPLOT3DReader(const vtkMultiBlockPLOT3DReader&); // Not implemented.
void operator=(const vtkMultiBlockPLOT3DReader&); // Not implemented.
......
......@@ -18,7 +18,7 @@
int vtkMultiBlockPLOT3DReaderInternals::ReadInts(FILE* fp, int n, int* val)
{
int retVal = static_cast<int>(fread(val, sizeof(int), n, fp));
if (this->ByteOrder == vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN)
if (this->Settings.ByteOrder == vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN)
{
vtkByteSwap::Swap4LERange(val, n);
}
......@@ -32,7 +32,7 @@ int vtkMultiBlockPLOT3DReaderInternals::ReadInts(FILE* fp, int n, int* val)
void vtkMultiBlockPLOT3DReaderInternals::CheckBinaryFile(FILE *fp, long fileSize)
{
rewind(fp);
this->BinaryFile = 0;
this->Settings.BinaryFile = 0;
// The shortest binary file is 12 files: 2 ints for block dims + 1 float for
// a coordinate.
......@@ -54,7 +54,7 @@ void vtkMultiBlockPLOT3DReaderInternals::CheckBinaryFile(FILE *fp, long fileSize
bytes[i] == ' ' || bytes[i] == '\r' ||
bytes[i] == '\n' || bytes[i] == '\t'))
{
this->BinaryFile = 1;
this->Settings.BinaryFile = 1;
return;
}
}
......@@ -77,11 +77,11 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckByteOrder(FILE* fp)
// endian.
if(cpy[0] == 0 && cpy[3] != 0)
{
this->ByteOrder = vtkMultiBlockPLOT3DReader::FILE_BIG_ENDIAN;
this->Settings.ByteOrder = vtkMultiBlockPLOT3DReader::FILE_BIG_ENDIAN;
}
else
{
this->ByteOrder = vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN;
this->Settings.ByteOrder = vtkMultiBlockPLOT3DReader::FILE_LITTLE_ENDIAN;
}
return 1;
}
......@@ -108,18 +108,18 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckByteCount(FILE* fp)
}
if (count == count2)
{
this->HasByteCount = 1;
this->Settings.HasByteCount = 1;
}
else
{
this->HasByteCount = 0;
this->Settings.HasByteCount = 0;
}
return 1;
}
int vtkMultiBlockPLOT3DReaderInternals::CheckMultiGrid(FILE* fp)
{
if (this->HasByteCount)
if (this->Settings.HasByteCount)
{
rewind(fp);
// We read the byte count, if it is 4 (1 int),
......@@ -133,11 +133,11 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckMultiGrid(FILE* fp)
}
if(recMarkBeg == sizeof(int))
{
this->MultiGrid = 1;
this->Settings.MultiGrid = 1;
}
else
{
this->MultiGrid = 0;
this->Settings.MultiGrid = 0;
}
return 1;
}
......@@ -146,12 +146,12 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckMultiGrid(FILE* fp)
int vtkMultiBlockPLOT3DReaderInternals::Check2DGeom(FILE* fp)
{
if (this->HasByteCount)
if (this->Settings.HasByteCount)
{
rewind(fp);
int recMarkBeg, recMarkEnd;
int numGrids = 1;
if(this->MultiGrid)
if(this->Settings.MultiGrid)
{
if (!this->ReadInts(fp, 1, &recMarkBeg) ||
!this->ReadInts(fp, 1, &numGrids) ||
......@@ -181,7 +181,7 @@ int vtkMultiBlockPLOT3DReaderInternals::Check2DGeom(FILE* fp)
ndims = 2;
}
}
this->NumberOfDimensions = ndims;
this->Settings.NumberOfDimensions = ndims;
return 1;
}
return 0;
......@@ -193,7 +193,7 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckBlankingAndPrecision(FILE* fp)
int* jmax;
rewind(fp);
if(this->MultiGrid)
if(this->Settings.MultiGrid)
{
if (!this->ReadInts(fp, 1, &recMarkBeg) ||
!this->ReadInts(fp, 1, &numGrids) ||
......@@ -206,7 +206,7 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckBlankingAndPrecision(FILE* fp)
{
return 0;
}
nMax = this->NumberOfDimensions * numGrids;
nMax = this->Settings.NumberOfDimensions * numGrids;
jmax = new int[numGrids*3]; // allocate memory for jmax
if (!this->ReadInts(fp, nMax, jmax) ||
!this->ReadInts(fp, 1, &recMarkEnd))
......@@ -215,40 +215,40 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckBlankingAndPrecision(FILE* fp)
return 0;
}
totPts = 1;
for (int i=0; i<this->NumberOfDimensions; i++)
for (int i=0; i<this->Settings.NumberOfDimensions; i++)
{
totPts *= jmax[i];
}
this->ReadInts(fp, 1, &recMarkBeg);
// single precision, with iblanking
if(recMarkBeg == totPts*(this->NumberOfDimensions*4 + 4))
if(recMarkBeg == totPts*(this->Settings.NumberOfDimensions*4 + 4))
{
this->Precision = 4;
this->IBlanking = 1;
this->Settings.Precision = 4;
this->Settings.IBlanking = 1;
delete[] jmax;
return 1;
}
// double precision, with iblanking
else if(recMarkBeg == totPts*(this->NumberOfDimensions*8 + 4))
else if(recMarkBeg == totPts*(this->Settings.NumberOfDimensions*8 + 4))
{
this->Precision = 8;
this->IBlanking = 1;
this->Settings.Precision = 8;
this->Settings.IBlanking = 1;
delete[] jmax;
return 1;
}
// single precision, no iblanking
else if(recMarkBeg == totPts*this->NumberOfDimensions*4)
else if(recMarkBeg == totPts*this->Settings.NumberOfDimensions*4)
{
this->Precision = 4;
this->IBlanking = 0;
this->Settings.Precision = 4;
this->Settings.IBlanking = 0;
delete[] jmax;
return 1;
}
// double precision, no iblanking
else if(recMarkBeg == totPts*this->NumberOfDimensions*8)
else if(recMarkBeg == totPts*this->Settings.NumberOfDimensions*8)
{
this->Precision = 8;
this->IBlanking = 0;
this->Settings.Precision = 8;
this->Settings.IBlanking = 0;
delete[] jmax;
return 1;
}
......@@ -292,10 +292,10 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, long fileSize)
1,
gridDims))
{
this->MultiGrid = 0;
this->Precision = precision;
this->IBlanking = blanking;
this->NumberOfDimensions = dimension;
this->Settings.MultiGrid = 0;
this->Settings.Precision = precision;
this->Settings.IBlanking = blanking;
this->Settings.NumberOfDimensions = dimension;
return 1;
}
}
......@@ -335,10 +335,10 @@ int vtkMultiBlockPLOT3DReaderInternals::CheckCFile(FILE* fp, long fileSize)
nGrids,
gridDims2))
{
this->MultiGrid = 1;
this->Precision = precision;
this->IBlanking = blanking;
this->NumberOfDimensions = dimension;
this->Settings.MultiGrid = 1;
this->Settings.Precision = precision;
this->Settings.IBlanking = blanking;
this->Settings.NumberOfDimensions = dimension;
delete[] gridDims2;
return 1;
}
......
......@@ -24,25 +24,45 @@
struct vtkMultiBlockPLOT3DReaderInternals
{
struct Dims
{
Dims()
{
memset(this->Values, 0, 3*sizeof(int));
}
int Values[3];
};
std::vector<Dims> Dimensions;
std::vector<vtkSmartPointer<vtkStructuredGrid> > Blocks;
int BinaryFile;
int ByteOrder;
int HasByteCount;
int MultiGrid;
int NumberOfDimensions;
int Precision; // in bytes
int IBlanking;
struct InternalSettings
{
int BinaryFile;
int ByteOrder;
int HasByteCount;
int MultiGrid;
int NumberOfDimensions;
int Precision; // in bytes
int IBlanking;
InternalSettings() :
BinaryFile(1),
ByteOrder(vtkMultiBlockPLOT3DReader::FILE_BIG_ENDIAN),
HasByteCount(1),
MultiGrid(0),
NumberOfDimensions(3),
Precision(4),
IBlanking(0)
{
}
};
InternalSettings Settings;
bool NeedToCheckXYZFile;
vtkMultiBlockPLOT3DReaderInternals() :
BinaryFile(1),
ByteOrder(vtkMultiBlockPLOT3DReader::FILE_BIG_ENDIAN),
HasByteCount(1),
MultiGrid(0),
NumberOfDimensions(3),
Precision(4),
IBlanking(0),
NeedToCheckXYZFile(true)
{
}
......
......@@ -339,6 +339,7 @@ int vtkPlot3DMetaReader::RequestInformation(
vtkInformationVector* outputVector)
{
vtkInformation* outInfo = outputVector->GetInformationObject(0);
outInfo->Set(vtkAlgorithm::CAN_HANDLE_PIECE_REQUEST(), 1);
this->Internal->TimeSteps.clear();
......@@ -482,8 +483,19 @@ int vtkPlot3DMetaReader::RequestData(
{
this->Reader->SetFunctionFileName(0);
}
this->Reader->UpdateInformation();
this->Reader->SetUpdateExtent(
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_PIECE_NUMBER()),
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_PIECES()),
outInfo->Get(vtkStreamingDemandDrivenPipeline::UPDATE_NUMBER_OF_GHOST_LEVELS())
);
this->Reader->Update();
output->ShallowCopy(this->Reader->GetOutput());
vtkDataObject* ioutput = this->Reader->GetOutput();
output->ShallowCopy(ioutput);
output->GetInformation()->Set(
vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS(),
ioutput->GetInformation()->Get(
vtkDataObject::DATA_NUMBER_OF_GHOST_LEVELS()));
}
else
{
......
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