VTK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 
52 {
53 public:
56  void PrintSelf(ostream& os, vtkIndent indent );
57 
59 
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  if( this->SendBuffers[i][j] != NULL )
429  {
430  delete [] this->SendBuffers[i][j];
431  }
432  } // END for all neighbors
433  this->SendBuffers[i].clear();
434  } // END for all grids
435  this->SendBuffers.clear();
436 
437  // STEP 1: Clear rcv buffers
438  for( unsigned int i=0; i < this->RcvBuffers.size(); ++i )
439  {
440  for( unsigned int j=0; j < this->RcvBuffers[i].size(); ++j )
441  {
442  if( this->RcvBuffers[i][j] != NULL )
443  {
444  delete [] this->RcvBuffers[i][j];
445  }
446  } // END for all neighbors
447  this->RcvBuffers[i].clear();
448  } // END for all grids
449  this->RcvBuffers.clear();
450 }
451 
452 //------------------------------------------------------------------------------
454 {
455  // STEP 0: Clear remote points
456  for( unsigned int i=0; i < this->RemotePoints.size(); ++i )
457  {
458  for( unsigned int j=0; j < this->RemotePoints[i].size(); ++j )
459  {
460  if( this->RemotePoints[ i ][ j ] != NULL )
461  {
462  this->RemotePoints[ i ][ j ]->Delete();
463  }
464  } // END for all j
465  this->RemotePoints[ i ].clear();
466  } // END for all i
467  this->RemotePoints.clear();
468 
469  // STEP 1: Clear remote point data
470  for( unsigned int i=0; i < this->RemotePointData.size(); ++i )
471  {
472  for( unsigned int j=0; j < this->RemotePointData[i].size(); ++j )
473  {
474  if( this->RemotePointData[ i ][ j ] != NULL )
475  {
476  this->RemotePointData[ i ][ j ]->Delete();
477  }
478  } // END for all j
479  this->RemotePointData[ i ].clear();
480  } // END for all i
481  this->RemotePointData.clear();
482 
483  // STEP 2: Clear remote cell data
484  for( unsigned int i=0; i < this->RemoteCellData.size(); ++i )
485  {
486  for( unsigned int j=0; j < this->RemoteCellData[i].size(); ++j )
487  {
488  if( this->RemoteCellData[ i ][ j ] != NULL )
489  {
490  this->RemoteCellData[ i ][ j ]->Delete();
491  }
492  } // END for all j
493  this->RemoteCellData[ i ].clear();
494  }
495  this->RemoteCellData.clear();
496 }
497 
498 //------------------------------------------------------------------------------
499 inline bool vtkPStructuredGridConnectivity::IsGridRemote(const int gridID )
500 {
501  return( !this->IsGridLocal(gridID) );
502 }
503 
504 //------------------------------------------------------------------------------
505 inline bool vtkPStructuredGridConnectivity::IsGridLocal(const int gridID)
506 {
507  assert( "pre: Instance has not been intialized!" && this->Initialized );
508  assert( "pre: gridID is out-of-bounds" &&
509  (gridID >= 0) && (gridID < static_cast<int>(this->NumberOfGrids) ) );
510  assert( "pre: GridRanks is not properly allocated" &&
511  this->NumberOfGrids == this->GridRanks.size() );
512  return( (this->GridRanks[ gridID ] == this->Rank) );
513 }
514 
515 //------------------------------------------------------------------------------
516 inline int vtkPStructuredGridConnectivity::GetGridRank( const int gridID )
517 {
518  assert( "pre: Instance has not been intialized!" && this->Initialized );
519  assert( "pre: gridID out-of-bounds!" &&
520  (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
521  return( this->GridRanks[ gridID ] );
522 }
523 #endif /* VTKPSTRUCTUREDGRIDCONNECTIVITY_H_ */
GLsizeiptr size
Definition: vtkgl.h:11843
represent and manipulate point attribute data
Definition: vtkPointData.h:36
stream used to pass data across processes using vtkMultiProcessController.
GLuint buffer
Definition: vtkgl.h:11839
std::vector< std::vector< unsigned int > > RcvBufferSizes
#define vtkGetMacro(name, type)
Definition: vtkSetGet.h:83
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:268
vtkMPICommunicator::Request * MPIRequests
#define vtkTypeMacro(thisClass, superclass)
Definition: vtkSetGet.h:619
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:53
Process communication using MPI.
dynamic, self-adjusting array of unsigned char
virtual void CreateGhostLayers(const int N=1)
virtual void TransferGhostDataFromNeighbors(const int gridID)
#define VTKFILTERSPARALLELGEOMETRY_EXPORT
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:39
virtual void SetNumberOfGrids(const unsigned int N)
std::vector< vtkCellData * > GridCellData
represent and manipulate fields of data
Definition: vtkFieldData.h:55
#define vtkSetMacro(name, type)
Definition: vtkSetGet.h:69
Multiprocessing communication superclass.