VTK
vtkPStructuredGridConnectivity.h
Go to the documentation of this file.
1/*=========================================================================
2
3 Program: Visualization Toolkit
4 Module: vtkPStructuredGridConnectivity.h
5
6 Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
7 All rights reserved.
8 See Copyright.txt or http://www.kitware.com/Copyright.htm for details.
9
10 This software is distributed WITHOUT ANY WARRANTY; without even
11 the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
12 PURPOSE. See the above copyright notice for more information.
13
14 =========================================================================*/
34#ifndef vtkPStructuredGridConnectivity_h
35#define vtkPStructuredGridConnectivity_h
36
37// VTK include directives
38#include "vtkFiltersParallelGeometryModule.h" // For export macro
40#include "vtkMPICommunicator.h" // Needed for vtkMPICommunicator::Request
41
42// C++ include directives
43#include <vector> // For STL vector
44
45// Forward declarations
49//class vtkMPICommunicator::Request;
50
51class VTKFILTERSPARALLELGEOMETRY_EXPORT vtkPStructuredGridConnectivity :
53{
54public:
57 void PrintSelf(ostream& os, vtkIndent indent );
58
60
64 vtkGetMacro( Controller,vtkMultiProcessController* );
66
70 void SetNumberOfGrids( const unsigned int N );
71
75 void RegisterGrid( const int gridID, int extents[6],
76 vtkUnsignedCharArray* nodesGhostArray,
77 vtkUnsignedCharArray* cellGhostArray,
78 vtkPointData* pointData,
79 vtkCellData* cellData,
80 vtkPoints* gridNodes );
81
87 { return static_cast<int>(this->GridIds.size()); };
88
95 int GetGridRank( const int gridID );
96
100 bool IsGridRemote( const int gridID );
101
105 bool IsGridLocal( const int gridID );
106
113
120
125 virtual void CreateGhostLayers( const int N=1 );
126
127protected:
130
132 int Rank;
134
135 std::vector< int > GridRanks; // Corresponding rank for each grid
136 std::vector< int > GridIds; // List of GridIds, owned by this process
137
138 // Data structures to store the remote ghost data of each grid for each one
139 // of its neighbors. The first index is the global grid index. The second
140 // is the neighbor index.
141 std::vector< std::vector< vtkPoints* > > RemotePoints;
142 std::vector< std::vector< vtkPointData* > > RemotePointData;
143 std::vector< std::vector< vtkCellData* > > RemoteCellData;
144
145 // Data structures to store the send/receive buffer sizes and corresponding
146 // persistent buffers. The first index is the global grid index. The second
147 // index is the neighbor index for the given grid.
148 std::vector< std::vector< unsigned int > > SendBufferSizes;
149 std::vector< std::vector< unsigned int > > RcvBufferSizes;
150 std::vector< std::vector< unsigned char* > > SendBuffers;
151 std::vector< std::vector< unsigned char* > > RcvBuffers;
152
156
157 // Array of MPI requests
159
163 bool GridExtentsAreEqual( int rhs[6], int lhs[6] );
164
168 bool HasPointData(const int gridIdx);
169
173 bool HasCellData(const int gridIdx);
174
178 bool HasPoints(const int gridIdx);
179
183 void InitializeMessageCounters();
184
189 void ClearRemoteData();
190
194 void ClearRawBuffers();
195
200 void RegisterRemoteGrid( const int gridID, int extents[6], int process );
201
207 const int gridIdx,const int nei,const vtkStructuredNeighbor& Neighbor );
208
214 virtual void TransferGhostDataFromNeighbors(const int gridID);
215
220
226
232 int *buffersizes, vtkIdType N, const int processId );
233
238 void SerializeBufferSizes(int *&sizesbuf, vtkIdType &N);
239
245
252
258
263 void PostSends();
264
271
278
283
289 const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
290
295 vtkDataArray *dataArray, vtkMultiProcessStream& bytestream );
296
302 int sourceExtent[6], int targetExtent[6], vtkFieldData *fieldData,
303 vtkMultiProcessStream& bytestream );
304
310 const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
311
317 const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
318
324 const int gridIdx, const int nei,
325 int ext[6], vtkMultiProcessStream& bytestream );
326
331 vtkDataArray *&dataArray,const int dataType,
332 const int numberOfTuples, const int numberOfComponents,
333 vtkMultiProcessStream& bytestream );
334
340 int ext[6], vtkFieldData *fieldData,
341 vtkMultiProcessStream &bytestream );
342
348 const int gridIdx, const int nei,
349 int ext[6], vtkMultiProcessStream& bytestream );
350
356 const int gridIdx, const int nei,
357 int ext[6], vtkMultiProcessStream& bytestream );
358
366 const int sndGridID, const int rcvGrid, int sndext[6],
367 unsigned char*& buffer, unsigned int &size);
368
374 const int gridID, const int neiListID,
375 const int neiGridIdx, int rcvext[6],
376 unsigned char *buffer, unsigned int size );
377
383
388 void SerializeGridExtents( int *&sndbuffer, vtkIdType &N );
389
395 int *rcvbuffer, vtkIdType &N, const int processId );
396
397private:
399 void operator=(const vtkPStructuredGridConnectivity& ) VTK_DELETE_FUNCTION;
400};
401
402//=============================================================================
403// INLINE METHODS
404//=============================================================================
405
406
408 int rhs[6], int lhs[6] )
409{
410 for( int i=0; i < 6; ++i )
411 {
412 if( rhs[i] != lhs[i] )
413 {
414 return false;
415 }
416 }
417 return true;
418}
419
420//------------------------------------------------------------------------------
422{
423 // Sanity check
424 assert("pre: grid index is out-of-bounds!" &&
425 (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
426
427 if( (this->GridPointData[gridIdx] != NULL) &&
428 (this->GridPointData[gridIdx]->GetNumberOfArrays() > 0) )
429 {
430 return true;
431 }
432 return false;
433}
434
435//------------------------------------------------------------------------------
437{
438 // Sanity check
439 assert("pre: grid index is out-of-bounds!" &&
440 (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
441
442 if( (this->GridCellData[gridIdx] != NULL) &&
443 (this->GridCellData[gridIdx]->GetNumberOfArrays( ) > 0) )
444 {
445 return true;
446 }
447 return false;
448}
449
450//------------------------------------------------------------------------------
451inline bool vtkPStructuredGridConnectivity::HasPoints(const int gridIdx)
452{
453 // Sanity check
454 assert("pre: grid index is out-of-bounds!" &&
455 (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
456
457 if( this->GridPoints[gridIdx] != NULL )
458 {
459 return true;
460 }
461 return false;
462}
463
464//------------------------------------------------------------------------------
466{
468}
469
470//------------------------------------------------------------------------------
472{
473 this->SendBufferSizes.clear();
474 this->RcvBufferSizes.clear();
475
476 // STEP 0: Clear send buffers
477 for( unsigned int i=0; i < this->SendBuffers.size(); ++i )
478 {
479 for( unsigned int j=0; j < this->SendBuffers[i].size(); ++j )
480 {
481 delete [] this->SendBuffers[i][j];
482 } // END for all neighbors
483 this->SendBuffers[i].clear();
484 } // END for all grids
485 this->SendBuffers.clear();
486
487 // STEP 1: Clear rcv buffers
488 for( unsigned int i=0; i < this->RcvBuffers.size(); ++i )
489 {
490 for( unsigned int j=0; j < this->RcvBuffers[i].size(); ++j )
491 {
492 delete [] this->RcvBuffers[i][j];
493 } // END for all neighbors
494 this->RcvBuffers[i].clear();
495 } // END for all grids
496 this->RcvBuffers.clear();
497}
498
499//------------------------------------------------------------------------------
501{
502 // STEP 0: Clear remote points
503 for( unsigned int i=0; i < this->RemotePoints.size(); ++i )
504 {
505 for( unsigned int j=0; j < this->RemotePoints[i].size(); ++j )
506 {
507 if( this->RemotePoints[ i ][ j ] != NULL )
508 {
509 this->RemotePoints[ i ][ j ]->Delete();
510 }
511 } // END for all j
512 this->RemotePoints[ i ].clear();
513 } // END for all i
514 this->RemotePoints.clear();
515
516 // STEP 1: Clear remote point data
517 for( unsigned int i=0; i < this->RemotePointData.size(); ++i )
518 {
519 for( unsigned int j=0; j < this->RemotePointData[i].size(); ++j )
520 {
521 if( this->RemotePointData[ i ][ j ] != NULL )
522 {
523 this->RemotePointData[ i ][ j ]->Delete();
524 }
525 } // END for all j
526 this->RemotePointData[ i ].clear();
527 } // END for all i
528 this->RemotePointData.clear();
529
530 // STEP 2: Clear remote cell data
531 for( unsigned int i=0; i < this->RemoteCellData.size(); ++i )
532 {
533 for( unsigned int j=0; j < this->RemoteCellData[i].size(); ++j )
534 {
535 if( this->RemoteCellData[ i ][ j ] != NULL )
536 {
537 this->RemoteCellData[ i ][ j ]->Delete();
538 }
539 } // END for all j
540 this->RemoteCellData[ i ].clear();
541 }
542 this->RemoteCellData.clear();
543}
544
545//------------------------------------------------------------------------------
547{
548 return( !this->IsGridLocal(gridID) );
549}
550
551//------------------------------------------------------------------------------
553{
554 assert( "pre: Instance has not been intialized!" && this->Initialized );
555 assert( "pre: gridID is out-of-bounds" &&
556 (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
557 assert( "pre: GridRanks is not properly allocated" &&
558 this->NumberOfGrids == this->GridRanks.size() );
559 return( (this->GridRanks[ gridID ] == this->Rank) );
560}
561
562//------------------------------------------------------------------------------
564{
565 assert( "pre: Instance has not been intialized!" && this->Initialized );
566 assert( "pre: gridID out-of-bounds!" &&
567 (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
568 return( this->GridRanks[ gridID ] );
569}
570#endif /* vtkPStructuredGridConnectivity_h */
std::vector< vtkPointData * > GridPointData
std::vector< vtkPoints * > GridPoints
std::vector< vtkCellData * > GridCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:39
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:55
represent and manipulate fields of data
Definition: vtkFieldData.h:57
a simple class to control print indentation
Definition: vtkIndent.h:40
Process communication using MPI.
Multiprocessing communication superclass.
stream used to pass data across processes using vtkMultiProcessController.
vtkPStructuredGridConnectivity inherits from vtkStructuredGridConnectivity and implements functionali...
std::vector< std::vector< vtkCellData * > > RemoteCellData
int GetNumberOfLocalGrids()
Returns the number of local grids registers by the process that owns the current vtkPStructuredGridCo...
std::vector< std::vector< unsigned char * > > SendBuffers
bool GridExtentsAreEqual(int rhs[6], int lhs[6])
Returns true if the two extents are equal, otherwise false.
void DeserializeGhostPoints(const int gridIdx, const int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost points received from a remote process.
std::vector< std::vector< unsigned int > > RcvBufferSizes
static vtkPStructuredGridConnectivity * New()
void SerializeDataArray(vtkDataArray *dataArray, vtkMultiProcessStream &bytestream)
Serializes the data array into a bytestream.
void DeserializeFieldData(int ext[6], vtkFieldData *fieldData, vtkMultiProcessStream &bytestream)
Helper method to de-serialize field data.
void DeserializeGhostPointData(const int gridIdx, const int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost point data received from a remote process.
virtual void CreateGhostLayers(const int N=1)
Creates ghost layers on the grids owned by this process using data from both local and remote block n...
void ClearRawBuffers()
Clears all raw send/rcv buffers.
bool IsGridLocal(const int gridID)
Returns true iff the grid corresponding to the given gridID is local.
void DeserializeGridExtentForProcess(int *rcvbuffer, vtkIdType &N, const int processId)
Deserializes the received grid extent information to the GridExtents internal data-structures.
void ExchangeGhostDataPost()
Helper method for exchanging ghost data.
void DeserializeGhostData(const int gridID, const int neiListID, const int neiGridIdx, int rcvext[6], unsigned char *buffer, unsigned int size)
Given the raw buffer consisting of ghost data, this method deserializes the object and returns the gr...
void PrintSelf(ostream &os, vtkIndent indent)
Methods invoked by print to print information about the object including superclasses.
int GetGridRank(const int gridID)
Returns the rank of the given gridID.
void SetNumberOfGrids(const unsigned int N)
Sets the total number of domains distributed among processors.
vtkMPICommunicator::Request * MPIRequests
void ExchangeGhostData()
Exchanges ghost data of the grids owned by this process.
bool IsGridRemote(const int gridID)
Returns true iff the grid is remote, otherwise false.
std::vector< std::vector< unsigned char * > > RcvBuffers
std::vector< std::vector< unsigned int > > SendBufferSizes
void PostSends()
Helper method to communicate ghost data.
void CommunicateGhostData()
Helper method for exchanging ghost data.
void SerializeGhostPointData(const int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize ghost point data.
std::vector< std::vector< vtkPoints * > > RemotePoints
virtual void TransferGhostDataFromNeighbors(const int gridID)
This method transfers the fields (point data and cell data) to the ghost extents from the neighboring...
std::vector< std::vector< vtkPointData * > > RemotePointData
void ExchangeGridExtents()
Exchanges the grid extents among all processes and fully populates the GridExtents vector.
void ClearRemoteData()
Clears all internal VTK data-structures that are used to store the remote ghost data.
void PackGhostData()
Helper method to pack all the ghost data into send buffers.
void ExchangeBufferSizes()
Helper method to exchange buffer sizes.Each process sends the send buffer size of each grid to each o...
void DeserializeGhostCellData(const int gridIdx, const int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost cell data received from a remote process.
void DeserializeBufferSizesForProcess(int *buffersizes, vtkIdType N, const int processId)
Helper method to deserialize the buffer sizes coming from the given process.
bool HasCellData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has cell data.
void RegisterRemoteGrid(const int gridID, int extents[6], int process)
Registers a remote grid with the given grid Id, structured extents and process.
void UnpackGhostData()
Helper method to unpack the raw ghost data from the receive buffers in to the VTK remote point data-s...
void SerializeGridExtents(int *&sndbuffer, vtkIdType &N)
Serializes the grid extents and information in a buffer to send over MPI The data is serialized as fo...
void ComputeNeighbors()
Computes the neighboring topology of a distributed structured grid data-set.
void DeserializeDataArray(vtkDataArray *&dataArray, const int dataType, const int numberOfTuples, const int numberOfComponents, vtkMultiProcessStream &bytestream)
Helper method to deserialize the data array from a bytestream.
void SerializeBufferSizes(int *&sizesbuf, vtkIdType &N)
Helper method to serialize the buffer sizes for the grids of this process to neighboring grids.
void ExchangeGhostDataInit()
Helper method for exchanging ghost data.
void SerializeGhostData(const int sndGridID, const int rcvGrid, int sndext[6], unsigned char *&buffer, unsigned int &size)
Given a grid ID and the corresponding send extent, this method serializes the grid and data within th...
void RegisterGrid(const int gridID, int extents[6], vtkUnsignedCharArray *nodesGhostArray, vtkUnsignedCharArray *cellGhostArray, vtkPointData *pointData, vtkCellData *cellData, vtkPoints *gridNodes)
See vtkStructuredGridConnectivity::RegisterGrid.
void TransferRemoteNeighborData(const int gridIdx, const int nei, const vtkStructuredNeighbor &Neighbor)
This method transfers all the remote neighbor data to the ghosted grid instance of the grid correspon...
void SerializeFieldData(int sourceExtent[6], int targetExtent[6], vtkFieldData *fieldData, vtkMultiProcessStream &bytestream)
Helper method to serialize field data.
void SerializeGhostPoints(const int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize the ghost points to send to a remote process.
void PostReceives()
Helper method to communicate ghost data.
void Initialize()
Initializes this instance of vtkPStructuredGridConnectivity, essentially, the acquires the local proc...
bool HasPointData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has point data.
void SerializeGhostCellData(const int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize ghost cell data.
void InitializeMessageCounters()
Sets all message counters to 0.
bool HasPoints(const int gridIdx)
Returns true iff the grid corresponding to the given ID has points.
represent and manipulate point attribute data
Definition: vtkPointData.h:38
represent and manipulate 3D points
Definition: vtkPoints.h:40
vtkStructuredGridConnectivity is a concrete instance of vtkObject that implements functionality for c...
An internal, light-weight class used to store neighbor information.
dynamic, self-adjusting array of unsigned char
@ size
Definition: vtkX3D.h:253
vtkSetMacro(IgnoreDriverBugs, bool)
Updates the extensions string.
int vtkIdType
Definition: vtkType.h:287