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  =========================================================================*/
33 #ifndef VTKPSTRUCTUREDGRIDCONNECTIVITY_H_
34 #define VTKPSTRUCTUREDGRIDCONNECTIVITY_H_
35 
36 // VTK include directives
37 #include "vtkFiltersParallelGeometryModule.h" // For export macro
39 #include "vtkMPICommunicator.h" // Needed for vtkMPICommunicator::Request
40 
41 // C++ include directives
42 #include <vector> // For STL vector
43 
44 // Forward declarations
46 class vtkMPIController;
48 //class vtkMPICommunicator::Request;
49 
50 class VTKFILTERSPARALLELGEOMETRY_EXPORT vtkPStructuredGridConnectivity :
52 {
53 public:
56  void PrintSelf(ostream& os, vtkIndent indent );
57 
59 
60  vtkSetMacro( Controller,vtkMultiProcessController* );
61  vtkGetMacro( Controller,vtkMultiProcessController* );
63 
65  void SetNumberOfGrids( const unsigned int N );
66 
68 
69  void RegisterGrid( const int gridID, int extents[6],
70  vtkUnsignedCharArray* nodesGhostArray,
71  vtkUnsignedCharArray* cellGhostArray,
72  vtkPointData* pointData,
73  vtkCellData* cellData,
74  vtkPoints* gridNodes );
76 
78 
81  { return static_cast<int>(this->GridIds.size()); };
83 
88  int GetGridRank( const int gridID );
89 
91  bool IsGridRemote( const int gridID );
92 
94  bool IsGridLocal( const int gridID );
95 
100  void Initialize();
101 
104  void ComputeNeighbors();
105 
108  virtual void CreateGhostLayers( const int N=1 );
109 
110 protected:
113 
115  int Rank;
117 
118  // BTX
119  std::vector< int > GridRanks; // Corresponding rank for each grid
120  std::vector< int > GridIds; // List of GridIds, owned by this process
121 
122  // Data structures to store the remote ghost data of each grid for each one
123  // of its neighbors. The first index is the global grid index. The second
124  // is the neighbor index.
125  std::vector< std::vector< vtkPoints* > > RemotePoints;
126  std::vector< std::vector< vtkPointData* > > RemotePointData;
127  std::vector< std::vector< vtkCellData* > > RemoteCellData;
128 
129  // Data structures to store the send/receive buffer sizes and corresponding
130  // persistent buffers. The first index is the global grid index. The second
131  // index is the neighbor index for the given grid.
132  std::vector< std::vector< unsigned int > > SendBufferSizes;
133  std::vector< std::vector< unsigned int > > RcvBufferSizes;
134  std::vector< std::vector< unsigned char* > > SendBuffers;
135  std::vector< std::vector< unsigned char* > > RcvBuffers;
136 
140 
141  // Array of MPI requests
143  // ETX
144 
146  bool GridExtentsAreEqual( int rhs[6], int lhs[6] );
147 
150  bool HasPointData(const int gridIdx);
151 
154  bool HasCellData(const int gridIdx);
155 
157  bool HasPoints(const int gridIdx);
158 
160  void InitializeMessageCounters();
161 
164  void ClearRemoteData();
165 
167  void ClearRawBuffers();
168 
171  void RegisterRemoteGrid( const int gridID, int extents[6], int process );
172 
174 
176  void TransferRemoteNeighborData(
177  const int gridIdx,const int nei,const vtkStructuredNeighbor& Neighbor );
179 
183  virtual void TransferGhostDataFromNeighbors(const int gridID);
184 
186  void PackGhostData();
187 
190  void UnpackGhostData();
191 
193 
195  void DeserializeBufferSizesForProcess(
196  int *buffersizes, vtkIdType N, const int processId );
198 
201  void SerializeBufferSizes(int *&sizesbuf, vtkIdType &N);
202 
205  void ExchangeBufferSizes();
206 
210  void ExchangeGhostDataInit();
211 
214  void PostReceives();
215 
218  void PostSends();
219 
223  void CommunicateGhostData();
224 
228  void ExchangeGhostDataPost();
229 
231  void ExchangeGhostData();
232 
234 
236  void SerializeGhostPoints(
237  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
239 
241 
242  void SerializeDataArray(
243  vtkDataArray *dataArray, vtkMultiProcessStream& bytestream );
245 
247 
249  void SerializeFieldData(
250  int sourceExtent[6], int targetExtent[6], vtkFieldData *fieldData,
251  vtkMultiProcessStream& bytestream );
253 
255 
257  void SerializeGhostPointData(
258  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
260 
262 
264  void SerializeGhostCellData(
265  const int gridIdx, int ext[6], vtkMultiProcessStream& bytestream );
267 
269 
271  void DeserializeGhostPoints(
272  const int gridIdx, const int nei,
273  int ext[6], vtkMultiProcessStream& bytestream );
275 
277 
278  void DeserializeDataArray(
279  vtkDataArray *&dataArray,const int dataType,
280  const int numberOfTuples, const int numberOfComponents,
281  vtkMultiProcessStream& bytestream );
283 
285 
287  void DeserializeFieldData(
288  int ext[6], vtkFieldData *fieldData,
289  vtkMultiProcessStream &bytestream );
291 
293 
295  void DeserializeGhostPointData(
296  const int gridIdx, const int nei,
297  int ext[6], vtkMultiProcessStream& bytestream );
299 
301 
303  void DeserializeGhostCellData(
304  const int gridIdx, const int nei,
305  int ext[6], vtkMultiProcessStream& bytestream );
307 
309 
313  void SerializeGhostData(
314  const int sndGridID, const int rcvGrid, int sndext[6],
315  unsigned char*& buffer, unsigned int &size);
317 
319 
322  void DeserializeGhostData(
323  const int gridID, const int neiListID,
324  const int neiGridIdx, int rcvext[6],
325  unsigned char *buffer, unsigned int size );
327 
330  void ExchangeGridExtents();
331 
335  void SerializeGridExtents( int *&sndbuffer, vtkIdType &N );
336 
338 
340  void DeserializeGridExtentForProcess(
341  int *rcvbuffer, vtkIdType &N, const int processId );
343 
344 private:
346  void operator=(const vtkPStructuredGridConnectivity& ); // Not implemented
347 };
348 
349 //=============================================================================
350 // INLINE METHODS
351 //=============================================================================
352 
353 
355  int rhs[6], int lhs[6] )
356 {
357  for( int i=0; i < 6; ++i )
358  {
359  if( rhs[i] != lhs[i] )
360  {
361  return false;
362  }
363  }
364  return true;
365 }
366 
367 //------------------------------------------------------------------------------
368 inline bool vtkPStructuredGridConnectivity::HasPointData(const int gridIdx)
369 {
370  // Sanity check
371  assert("pre: grid index is out-of-bounds!" &&
372  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
373 
374  if( (this->GridPointData[gridIdx] != NULL) &&
375  (this->GridPointData[gridIdx]->GetNumberOfArrays() > 0) )
376  {
377  return true;
378  }
379  return false;
380 }
381 
382 //------------------------------------------------------------------------------
383 inline bool vtkPStructuredGridConnectivity::HasCellData(const int gridIdx)
384 {
385  // Sanity check
386  assert("pre: grid index is out-of-bounds!" &&
387  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
388 
389  if( (this->GridCellData[gridIdx] != NULL) &&
390  (this->GridCellData[gridIdx]->GetNumberOfArrays( ) > 0) )
391  {
392  return true;
393  }
394  return false;
395 }
396 
397 //------------------------------------------------------------------------------
398 inline bool vtkPStructuredGridConnectivity::HasPoints(const int gridIdx)
399 {
400  // Sanity check
401  assert("pre: grid index is out-of-bounds!" &&
402  (gridIdx >= 0) && (gridIdx < static_cast<int>(this->NumberOfGrids)));
403 
404  if( this->GridPoints[gridIdx] != NULL )
405  {
406  return true;
407  }
408  return false;
409 }
410 
411 //------------------------------------------------------------------------------
413 {
415 }
416 
417 //------------------------------------------------------------------------------
419 {
420  this->SendBufferSizes.clear();
421  this->RcvBufferSizes.clear();
422 
423  // STEP 0: Clear send buffers
424  for( unsigned int i=0; i < this->SendBuffers.size(); ++i )
425  {
426  for( unsigned int j=0; j < this->SendBuffers[i].size(); ++j )
427  {
428  delete [] this->SendBuffers[i][j];
429  } // END for all neighbors
430  this->SendBuffers[i].clear();
431  } // END for all grids
432  this->SendBuffers.clear();
433 
434  // STEP 1: Clear rcv buffers
435  for( unsigned int i=0; i < this->RcvBuffers.size(); ++i )
436  {
437  for( unsigned int j=0; j < this->RcvBuffers[i].size(); ++j )
438  {
439  delete [] this->RcvBuffers[i][j];
440  } // END for all neighbors
441  this->RcvBuffers[i].clear();
442  } // END for all grids
443  this->RcvBuffers.clear();
444 }
445 
446 //------------------------------------------------------------------------------
448 {
449  // STEP 0: Clear remote points
450  for( unsigned int i=0; i < this->RemotePoints.size(); ++i )
451  {
452  for( unsigned int j=0; j < this->RemotePoints[i].size(); ++j )
453  {
454  if( this->RemotePoints[ i ][ j ] != NULL )
455  {
456  this->RemotePoints[ i ][ j ]->Delete();
457  }
458  } // END for all j
459  this->RemotePoints[ i ].clear();
460  } // END for all i
461  this->RemotePoints.clear();
462 
463  // STEP 1: Clear remote point data
464  for( unsigned int i=0; i < this->RemotePointData.size(); ++i )
465  {
466  for( unsigned int j=0; j < this->RemotePointData[i].size(); ++j )
467  {
468  if( this->RemotePointData[ i ][ j ] != NULL )
469  {
470  this->RemotePointData[ i ][ j ]->Delete();
471  }
472  } // END for all j
473  this->RemotePointData[ i ].clear();
474  } // END for all i
475  this->RemotePointData.clear();
476 
477  // STEP 2: Clear remote cell data
478  for( unsigned int i=0; i < this->RemoteCellData.size(); ++i )
479  {
480  for( unsigned int j=0; j < this->RemoteCellData[i].size(); ++j )
481  {
482  if( this->RemoteCellData[ i ][ j ] != NULL )
483  {
484  this->RemoteCellData[ i ][ j ]->Delete();
485  }
486  } // END for all j
487  this->RemoteCellData[ i ].clear();
488  }
489  this->RemoteCellData.clear();
490 }
491 
492 //------------------------------------------------------------------------------
493 inline bool vtkPStructuredGridConnectivity::IsGridRemote(const int gridID )
494 {
495  return( !this->IsGridLocal(gridID) );
496 }
497 
498 //------------------------------------------------------------------------------
499 inline bool vtkPStructuredGridConnectivity::IsGridLocal(const int gridID)
500 {
501  assert( "pre: Instance has not been intialized!" && this->Initialized );
502  assert( "pre: gridID is out-of-bounds" &&
503  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
504  assert( "pre: GridRanks is not properly allocated" &&
505  this->NumberOfGrids == this->GridRanks.size() );
506  return( (this->GridRanks[ gridID ] == this->Rank) );
507 }
508 
509 //------------------------------------------------------------------------------
510 inline int vtkPStructuredGridConnectivity::GetGridRank( const int gridID )
511 {
512  assert( "pre: Instance has not been intialized!" && this->Initialized );
513  assert( "pre: gridID out-of-bounds!" &&
514  (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
515  return( this->GridRanks[ gridID ] );
516 }
517 #endif /* VTKPSTRUCTUREDGRIDCONNECTIVITY_H_ */
represent and manipulate point attribute data
Definition: vtkPointData.h:36
stream used to pass data across processes using vtkMultiProcessController.
std::vector< std::vector< unsigned int > > RcvBufferSizes
represent and manipulate cell attribute data
Definition: vtkCellData.h:37
std::vector< vtkPoints * > GridPoints
virtual void RegisterGrid(const int gridID, int extents[6], vtkUnsignedCharArray *nodesGhostArray, vtkUnsignedCharArray *cellGhostArray, vtkPointData *pointData, vtkCellData *cellData, vtkPoints *gridNodes)
std::vector< std::vector< vtkPoints * > > RemotePoints
int vtkIdType
Definition: vtkType.h:275
vtkMPICommunicator::Request * MPIRequests
bool GridExtentsAreEqual(int rhs[6], int lhs[6])
std::vector< std::vector< vtkPointData * > > RemotePointData
std::vector< std::vector< vtkCellData * > > RemoteCellData
a simple class to control print indentation
Definition: vtkIndent.h:38
static vtkStructuredGridConnectivity * New()
abstract superclass for arrays of numeric data
Definition: vtkDataArray.h:54
Process communication using MPI.
dynamic, self-adjusting array of unsigned char
virtual void CreateGhostLayers(const int N=1)
virtual void TransferGhostDataFromNeighbors(const int gridID)
std::vector< std::vector< unsigned char * > > RcvBuffers
void PrintSelf(ostream &os, vtkIndent indent)
std::vector< std::vector< unsigned char * > > SendBuffers
std::vector< std::vector< unsigned int > > SendBufferSizes
std::vector< vtkPointData * > GridPointData
represent and manipulate 3D points
Definition: vtkPoints.h:38
virtual void SetNumberOfGrids(const unsigned int N)
std::vector< vtkCellData * > GridCellData
represent and manipulate fields of data
Definition: vtkFieldData.h:55
Multiprocessing communication superclass.