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  =========================================================================*/
31 #ifndef vtkPStructuredGridConnectivity_h
32 #define vtkPStructuredGridConnectivity_h
33 
34 // VTK include directives
35 #include "vtkFiltersParallelGeometryModule.h" // For export macro
37 #include "vtkMPICommunicator.h" // Needed for vtkMPICommunicator::Request
38 
39 // C++ include directives
40 #include <vector> // For STL vector
41 
42 // Forward declarations
44 class vtkMPIController;
46 //class vtkMPICommunicator::Request;
47 
48 class VTKFILTERSPARALLELGEOMETRY_EXPORT vtkPStructuredGridConnectivity :
50 {
51 public:
54  void PrintSelf(ostream& os, vtkIndent indent ) override;
55 
57 
60  vtkSetMacro( Controller,vtkMultiProcessController* );
61  vtkGetMacro( Controller,vtkMultiProcessController* );
63 
67  void SetNumberOfGrids( const unsigned int N ) override;
68 
72  void RegisterGrid( const int gridID, int extents[6],
73  vtkUnsignedCharArray* nodesGhostArray,
74  vtkUnsignedCharArray* cellGhostArray,
75  vtkPointData* pointData,
76  vtkCellData* cellData,
77  vtkPoints* gridNodes ) override;
78 
84  { return static_cast<int>(this->GridIds.size()); };
85 
92  int GetGridRank( const int gridID );
93 
97  bool IsGridRemote( const int gridID );
98 
102  bool IsGridLocal( const int gridID );
103 
109  void Initialize();
110 
116  void ComputeNeighbors() override;
117 
122  virtual void CreateGhostLayers( const int N=1 ) override;
123 
124 protected:
126  ~vtkPStructuredGridConnectivity() override;
127 
129  int Rank;
131 
132  std::vector< int > GridRanks; // Corresponding rank for each grid
133  std::vector< int > GridIds; // List of GridIds, owned by this process
134 
135  // Data structures to store the remote ghost data of each grid for each one
136  // of its neighbors. The first index is the global grid index. The second
137  // is the neighbor index.
138  std::vector< std::vector< vtkPoints* > > RemotePoints;
139  std::vector< std::vector< vtkPointData* > > RemotePointData;
140  std::vector< std::vector< vtkCellData* > > RemoteCellData;
141 
142  // Data structures to store the send/receive buffer sizes and corresponding
143  // persistent buffers. The first index is the global grid index. The second
144  // index is the neighbor index for the given grid.
145  std::vector< std::vector< unsigned int > > SendBufferSizes;
146  std::vector< std::vector< unsigned int > > RcvBufferSizes;
147  std::vector< std::vector< unsigned char* > > SendBuffers;
148  std::vector< std::vector< unsigned char* > > RcvBuffers;
149 
153 
154  // Array of MPI requests
156 
160  bool GridExtentsAreEqual( int rhs[6], int lhs[6] );
161 
165  bool HasPointData(const int gridIdx);
166 
170  bool HasCellData(const int gridIdx);
171 
175  bool HasPoints(const int gridIdx);
176 
180  void InitializeMessageCounters();
181 
186  void ClearRemoteData();
187 
191  void ClearRawBuffers();
192 
197  void RegisterRemoteGrid( const int gridID, int extents[6], int process );
198 
203  void TransferRemoteNeighborData(
204  const int gridIdx,const int nei,const vtkStructuredNeighbor& Neighbor );
205 
211  virtual void TransferGhostDataFromNeighbors(const int gridID) override;
212 
216  void PackGhostData();
217 
222  void UnpackGhostData();
223 
228  void DeserializeBufferSizesForProcess(
229  int *buffersizes, vtkIdType N, const int processId );
230 
235  void SerializeBufferSizes(int *&sizesbuf, vtkIdType &N);
236 
241  void ExchangeBufferSizes();
242 
248  void ExchangeGhostDataInit();
249 
254  void PostReceives();
255 
260  void PostSends();
261 
267  void CommunicateGhostData();
268 
274  void ExchangeGhostDataPost();
275 
279  void ExchangeGhostData();
280 
285  void SerializeGhostPoints(
286  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
287 
291  void SerializeDataArray(
292  vtkDataArray *dataArray, vtkMultiProcessStream& bytestream );
293 
298  void SerializeFieldData(
299  int sourceExtent[6], int targetExtent[6], vtkFieldData *fieldData,
300  vtkMultiProcessStream& bytestream );
301 
306  void SerializeGhostPointData(
307  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
308 
313  void SerializeGhostCellData(
314  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
315 
320  void DeserializeGhostPoints(
321  const int gridIdx, const int nei,
322  int ext[6], vtkMultiProcessStream& bytestream );
323 
327  void DeserializeDataArray(
328  vtkDataArray *&dataArray,const int dataType,
329  const int numberOfTuples, const int numberOfComponents,
330  vtkMultiProcessStream& bytestream );
331 
336  void DeserializeFieldData(
337  int ext[6], vtkFieldData *fieldData,
338  vtkMultiProcessStream &bytestream );
339 
344  void DeserializeGhostPointData(
345  const int gridIdx, const int nei,
346  int ext[6], vtkMultiProcessStream& bytestream );
347 
352  void DeserializeGhostCellData(
353  const int gridIdx, const int nei,
354  int ext[6], vtkMultiProcessStream& bytestream );
355 
362  void SerializeGhostData(
363  const int sndGridID, const int rcvGrid, int sndext[6],
364  unsigned char*& buffer, unsigned int &size);
365 
370  void DeserializeGhostData(
371  const int gridID, const int neiListID,
372  const int neiGridIdx, int rcvext[6],
373  unsigned char *buffer, unsigned int size );
374 
379  void ExchangeGridExtents();
380 
385  void SerializeGridExtents( int *&sndbuffer, vtkIdType &N );
386 
391  void DeserializeGridExtentForProcess(
392  int *rcvbuffer, vtkIdType &N, const int processId );
393 
394 private:
396  void operator=(const vtkPStructuredGridConnectivity& ) = delete;
397 };
398 
399 //=============================================================================
400 // INLINE METHODS
401 //=============================================================================
402 
403 
405  int rhs[6], int lhs[6] )
406 {
407  for( int i=0; i < 6; ++i )
408  {
409  if( rhs[i] != lhs[i] )
410  {
411  return false;
412  }
413  }
414  return true;
415 }
416 
417 //------------------------------------------------------------------------------
418 inline bool vtkPStructuredGridConnectivity::HasPointData(const int gridIdx)
419 {
420  // Sanity check
421  assert("pre: grid index is out-of-bounds!" &&
422  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
423 
424  if( (this->GridPointData[gridIdx] != nullptr) &&
425  (this->GridPointData[gridIdx]->GetNumberOfArrays() > 0) )
426  {
427  return true;
428  }
429  return false;
430 }
431 
432 //------------------------------------------------------------------------------
433 inline bool vtkPStructuredGridConnectivity::HasCellData(const int gridIdx)
434 {
435  // Sanity check
436  assert("pre: grid index is out-of-bounds!" &&
437  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
438 
439  if( (this->GridCellData[gridIdx] != nullptr) &&
440  (this->GridCellData[gridIdx]->GetNumberOfArrays( ) > 0) )
441  {
442  return true;
443  }
444  return false;
445 }
446 
447 //------------------------------------------------------------------------------
448 inline bool vtkPStructuredGridConnectivity::HasPoints(const int gridIdx)
449 {
450  // Sanity check
451  assert("pre: grid index is out-of-bounds!" &&
452  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
453 
454  if( this->GridPoints[gridIdx] != nullptr )
455  {
456  return true;
457  }
458  return false;
459 }
460 
461 //------------------------------------------------------------------------------
463 {
465 }
466 
467 //------------------------------------------------------------------------------
469 {
470  this->SendBufferSizes.clear();
471  this->RcvBufferSizes.clear();
472 
473  // STEP 0: Clear send buffers
474  for( unsigned int i=0; i < this->SendBuffers.size(); ++i )
475  {
476  for( unsigned int j=0; j < this->SendBuffers[i].size(); ++j )
477  {
478  delete [] this->SendBuffers[i][j];
479  } // END for all neighbors
480  this->SendBuffers[i].clear();
481  } // END for all grids
482  this->SendBuffers.clear();
483 
484  // STEP 1: Clear rcv buffers
485  for( unsigned int i=0; i < this->RcvBuffers.size(); ++i )
486  {
487  for( unsigned int j=0; j < this->RcvBuffers[i].size(); ++j )
488  {
489  delete [] this->RcvBuffers[i][j];
490  } // END for all neighbors
491  this->RcvBuffers[i].clear();
492  } // END for all grids
493  this->RcvBuffers.clear();
494 }
495 
496 //------------------------------------------------------------------------------
498 {
499  // STEP 0: Clear remote points
500  for( unsigned int i=0; i < this->RemotePoints.size(); ++i )
501  {
502  for( unsigned int j=0; j < this->RemotePoints[i].size(); ++j )
503  {
504  if( this->RemotePoints[ i ][ j ] != nullptr )
505  {
506  this->RemotePoints[ i ][ j ]->Delete();
507  }
508  } // END for all j
509  this->RemotePoints[ i ].clear();
510  } // END for all i
511  this->RemotePoints.clear();
512 
513  // STEP 1: Clear remote point data
514  for( unsigned int i=0; i < this->RemotePointData.size(); ++i )
515  {
516  for( unsigned int j=0; j < this->RemotePointData[i].size(); ++j )
517  {
518  if( this->RemotePointData[ i ][ j ] != nullptr )
519  {
520  this->RemotePointData[ i ][ j ]->Delete();
521  }
522  } // END for all j
523  this->RemotePointData[ i ].clear();
524  } // END for all i
525  this->RemotePointData.clear();
526 
527  // STEP 2: Clear remote cell data
528  for( unsigned int i=0; i < this->RemoteCellData.size(); ++i )
529  {
530  for( unsigned int j=0; j < this->RemoteCellData[i].size(); ++j )
531  {
532  if( this->RemoteCellData[ i ][ j ] != nullptr )
533  {
534  this->RemoteCellData[ i ][ j ]->Delete();
535  }
536  } // END for all j
537  this->RemoteCellData[ i ].clear();
538  }
539  this->RemoteCellData.clear();
540 }
541 
542 //------------------------------------------------------------------------------
543 inline bool vtkPStructuredGridConnectivity::IsGridRemote(const int gridID )
544 {
545  return( !this->IsGridLocal(gridID) );
546 }
547 
548 //------------------------------------------------------------------------------
549 inline bool vtkPStructuredGridConnectivity::IsGridLocal(const int gridID)
550 {
551  assert( "pre: Instance has not been initialized!" && this->Initialized );
552  assert( "pre: gridID is out-of-bounds" &&
553  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
554  assert( "pre: GridRanks is not properly allocated" &&
555  this->NumberOfGrids == this->GridRanks.size() );
556  return( (this->GridRanks[ gridID ] == this->Rank) );
557 }
558 
559 //------------------------------------------------------------------------------
560 inline int vtkPStructuredGridConnectivity::GetGridRank( const int gridID )
561 {
562  assert( "pre: Instance has not been initialized!" && this->Initialized );
563  assert( "pre: gridID out-of-bounds!" &&
564  (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
565  return( this->GridRanks[ gridID ] );
566 }
567 #endif /* vtkPStructuredGridConnectivity_h */
vtkPoints
represent and manipulate 3D points
Definition: vtkPoints.h:33
vtkPStructuredGridConnectivity::HasPoints
bool HasPoints(const int gridIdx)
Returns true iff the grid corresponding to the given ID has points.
Definition: vtkPStructuredGridConnectivity.h:448
vtkAbstractGridConnectivity::GridCellData
std::vector< vtkCellData * > GridCellData
Definition: vtkAbstractGridConnectivity.h:201
vtkPStructuredGridConnectivity::IsGridLocal
bool IsGridLocal(const int gridID)
Returns true iff the grid corresponding to the given gridID is local.
Definition: vtkPStructuredGridConnectivity.h:549
vtkMPICommunicator::Request
Definition: vtkMPICommunicator.h:53
vtkPStructuredGridConnectivity
Definition: vtkPStructuredGridConnectivity.h:48
vtkPointData
represent and manipulate point attribute data
Definition: vtkPointData.h:31
vtkStructuredGridConnectivity::SetNumberOfGrids
void SetNumberOfGrids(const unsigned int N) override
Set/Get the total number of domains distributed among processors.
Definition: vtkStructuredGridConnectivity.h:1039
vtkIdType
int vtkIdType
Definition: vtkType.h:347
vtkPStructuredGridConnectivity::SendBuffers
std::vector< std::vector< unsigned char * > > SendBuffers
Definition: vtkPStructuredGridConnectivity.h:147
vtkMultiProcessStream
stream used to pass data across processes using vtkMultiProcessController.
Definition: vtkMultiProcessStream.h:37
vtkStructuredGridConnectivity::ComputeNeighbors
void ComputeNeighbors() override
Computes neighboring information.
vtkPStructuredGridConnectivity::GetGridRank
int GetGridRank(const int gridID)
Returns the rank of the given gridID.
Definition: vtkPStructuredGridConnectivity.h:560
vtkUnsignedCharArray
dynamic, self-adjusting array of unsigned char
Definition: vtkUnsignedCharArray.h:35
vtkPStructuredGridConnectivity::Rank
int Rank
Definition: vtkPStructuredGridConnectivity.h:129
vtkPStructuredGridConnectivity::RemoteCellData
std::vector< std::vector< vtkCellData * > > RemoteCellData
Definition: vtkPStructuredGridConnectivity.h:140
vtkPStructuredGridConnectivity::GridExtentsAreEqual
bool GridExtentsAreEqual(int rhs[6], int lhs[6])
Returns true if the two extents are equal, otherwise false.
Definition: vtkPStructuredGridConnectivity.h:404
vtkPStructuredGridConnectivity::Initialized
bool Initialized
Definition: vtkPStructuredGridConnectivity.h:130
vtkDataArray
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
vtkPStructuredGridConnectivity::ClearRawBuffers
void ClearRawBuffers()
Clears all raw send/rcv buffers.
Definition: vtkPStructuredGridConnectivity.h:468
vtkStructuredGridConnectivity::PrintSelf
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
vtkPStructuredGridConnectivity::RemotePointData
std::vector< std::vector< vtkPointData * > > RemotePointData
Definition: vtkPStructuredGridConnectivity.h:139
vtkPStructuredGridConnectivity::HasPointData
bool HasPointData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has point data.
Definition: vtkPStructuredGridConnectivity.h:418
vtkPStructuredGridConnectivity::RemotePoints
std::vector< std::vector< vtkPoints * > > RemotePoints
Definition: vtkPStructuredGridConnectivity.h:138
vtkFieldData
represent and manipulate fields of data
Definition: vtkFieldData.h:53
vtkAbstractGridConnectivity::GridPoints
std::vector< vtkPoints * > GridPoints
Definition: vtkAbstractGridConnectivity.h:202
vtkPStructuredGridConnectivity::RcvBufferSizes
std::vector< std::vector< unsigned int > > RcvBufferSizes
Definition: vtkPStructuredGridConnectivity.h:146
vtkPStructuredGridConnectivity::MPIRequests
vtkMPICommunicator::Request * MPIRequests
Definition: vtkPStructuredGridConnectivity.h:155
vtkMultiProcessController
Multiprocessing communication superclass.
Definition: vtkMultiProcessController.h:76
vtkPStructuredGridConnectivity::GetNumberOfLocalGrids
int GetNumberOfLocalGrids()
Returns the number of local grids registers by the process that owns the current vtkPStructuredGridCo...
Definition: vtkPStructuredGridConnectivity.h:83
vtkAbstractGridConnectivity::NumberOfGrids
unsigned int NumberOfGrids
Definition: vtkAbstractGridConnectivity.h:194
vtkPStructuredGridConnectivity::TotalNumberOfRcvs
int TotalNumberOfRcvs
Definition: vtkPStructuredGridConnectivity.h:151
vtkPStructuredGridConnectivity::IsGridRemote
bool IsGridRemote(const int gridID)
Returns true iff the grid is remote, otherwise false.
Definition: vtkPStructuredGridConnectivity.h:543
vtkCellData
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
vtkPStructuredGridConnectivity::InitializeMessageCounters
void InitializeMessageCounters()
Sets all message counters to 0.
Definition: vtkPStructuredGridConnectivity.h:462
vtkStructuredGridConnectivity
Definition: vtkStructuredGridConnectivity.h:57
vtkStructuredGridConnectivity::RegisterGrid
virtual void RegisterGrid(const int gridID, int extents[6], vtkUnsignedCharArray *nodesGhostArray, vtkUnsignedCharArray *cellGhostArray, vtkPointData *pointData, vtkCellData *cellData, vtkPoints *gridNodes)
Registers the current grid corresponding to the grid ID by its global extent w.r.t.
vtkIndent
a simple class to control print indentation
Definition: vtkIndent.h:33
vtkPStructuredGridConnectivity::HasCellData
bool HasCellData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has cell data.
Definition: vtkPStructuredGridConnectivity.h:433
vtkPStructuredGridConnectivity::ClearRemoteData
void ClearRemoteData()
Clears all internal VTK data-structures that are used to store the remote ghost data.
Definition: vtkPStructuredGridConnectivity.h:497
vtkX3D::size
Definition: vtkX3D.h:253
vtkStructuredNeighbor
Definition: vtkStructuredNeighbor.h:28
vtkStructuredGridConnectivity::TransferGhostDataFromNeighbors
virtual void TransferGhostDataFromNeighbors(const int gridID)
This method transfers the fields (point data and cell data) to the ghost extents from the neighboring...
vtkPStructuredGridConnectivity::TotalNumberOfSends
int TotalNumberOfSends
Definition: vtkPStructuredGridConnectivity.h:150
vtkPStructuredGridConnectivity::Controller
vtkMultiProcessController * Controller
Definition: vtkPStructuredGridConnectivity.h:128
vtkStructuredGridConnectivity::New
static vtkStructuredGridConnectivity * New()
vtkAbstractGridConnectivity::GridPointData
std::vector< vtkPointData * > GridPointData
Definition: vtkAbstractGridConnectivity.h:200
vtkPStructuredGridConnectivity::SendBufferSizes
std::vector< std::vector< unsigned int > > SendBufferSizes
Definition: vtkPStructuredGridConnectivity.h:145
vtkStructuredGridConnectivity::CreateGhostLayers
void CreateGhostLayers(const int N=1) override
Creates ghost layers.
vtkMPIController
Process communication using MPI.
Definition: vtkMPIController.h:55
vtkPStructuredGridConnectivity::TotalNumberOfMsgs
int TotalNumberOfMsgs
Definition: vtkPStructuredGridConnectivity.h:152
vtkStructuredGridConnectivity.h
vtkPStructuredGridConnectivity::RcvBuffers
std::vector< std::vector< unsigned char * > > RcvBuffers
Definition: vtkPStructuredGridConnectivity.h:148
vtkPStructuredGridConnectivity::GridIds
std::vector< int > GridIds
Definition: vtkPStructuredGridConnectivity.h:133
vtkMPICommunicator.h
vtkPStructuredGridConnectivity::GridRanks
std::vector< int > GridRanks
Definition: vtkPStructuredGridConnectivity.h:132