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 ) VTK_OVERRIDE;
55 
57 
61  vtkGetMacro( Controller,vtkMultiProcessController* );
63 
67  void SetNumberOfGrids( const unsigned int N ) VTK_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 ) VTK_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() VTK_OVERRIDE;
117 
122  virtual void CreateGhostLayers( const int N=1 ) VTK_OVERRIDE;
123 
124 protected:
127 
129  int Rank;
130  bool Initialized;
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 
150  int TotalNumberOfSends;
151  int TotalNumberOfRcvs;
152  int TotalNumberOfMsgs;
153 
154  // Array of MPI requests
155  vtkMPICommunicator::Request *MPIRequests;
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) VTK_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& ) VTK_DELETE_FUNCTION;
397 };
398 
399 //=============================================================================
400 // INLINE METHODS
401 //=============================================================================
402 
403 
404 inline bool vtkPStructuredGridConnectivity::GridExtentsAreEqual(
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] != NULL) &&
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] != NULL) &&
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] != NULL )
455  {
456  return true;
457  }
458  return false;
459 }
460 
461 //------------------------------------------------------------------------------
463 {
464  this->TotalNumberOfMsgs=this->TotalNumberOfRcvs=this->TotalNumberOfSends=0;
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 ] != NULL )
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 ] != NULL )
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 ] != NULL )
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 */
vtkPStructuredGridConnectivity inherits from vtkStructuredGridConnectivity and implements functionali...
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
represent and manipulate point attribute data
Definition: vtkPointData.h:31
stream used to pass data across processes using vtkMultiProcessController.
int GetNumberOfLocalGrids()
Returns the number of local grids registers by the process that owns the current vtkPStructuredGridCo...
Class for creating user defined MPI communicators.
represent and manipulate cell attribute data
Definition: vtkCellData.h:32
bool HasCellData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has cell data.
bool HasPointData(const int gridIdx)
Returns true iff the grid corresponding to the given ID has point data.
bool HasPoints(const int gridIdx)
Returns true iff the grid corresponding to the given ID has points.
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.
int vtkIdType
Definition: vtkType.h:345
void ClearRemoteData()
Clears all internal VTK data-structures that are used to store the remote ghost data.
void ComputeNeighbors() override
Computes neighboring information.
void SetNumberOfGrids(const unsigned int N) override
Set/Get the total number of domains distributed among processors.
vtkStructuredGridConnectivity is a concrete instance of vtkObject that implements functionality for c...
a simple class to control print indentation
Definition: vtkIndent.h:33
int GetGridRank(const int gridID)
Returns the rank of the given gridID.
static vtkStructuredGridConnectivity * New()
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:48
bool IsGridRemote(const int gridID)
Returns true iff the grid is remote, otherwise false.
Process communication using MPI.
void ClearRawBuffers()
Clears all raw send/rcv buffers.
dynamic, self-adjusting array of unsigned char
vtkSetMacro(IgnoreDriverBugs, bool)
When set known driver bugs are ignored during driver feature detection.
An internal, light-weight class used to store neighbor information.
void InitializeMessageCounters()
Sets all message counters to 0.
bool IsGridLocal(const int gridID)
Returns true iff the grid corresponding to the given gridID is local.
represent and manipulate 3D points
Definition: vtkPoints.h:33
represent and manipulate fields of data
Definition: vtkFieldData.h:53
Multiprocessing communication superclass.