VTK  9.5.20251113
vtkPStructuredGridConnectivity.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-License-Identifier: BSD-3-Clause
22#ifndef vtkPStructuredGridConnectivity_h
23#define vtkPStructuredGridConnectivity_h
24
25// VTK include directives
26#include "vtkDeprecation.h" // For VTK_DEPRECATED_IN_9_6_0
27#include "vtkFiltersParallelGeometryModule.h" // For export macro
28#include "vtkMPICommunicator.h" // Needed for vtkMPICommunicator::Request
30
31// C++ include directives
32#include <vector> // For STL vector
33
34// Forward declarations
35VTK_ABI_NAMESPACE_BEGIN
39// class vtkMPICommunicator::Request;
40
41class VTKFILTERSPARALLELGEOMETRY_EXPORT vtkPStructuredGridConnectivity
43{
44public:
47 void PrintSelf(ostream& os, vtkIndent indent) override;
48
50
54 vtkGetObjectMacro(Controller, vtkMultiProcessController);
56
60 void SetNumberOfGrids(unsigned int N) override;
61
65 void RegisterGrid(int gridID, int extents[6], vtkUnsignedCharArray* nodesGhostArray,
66 vtkUnsignedCharArray* cellGhostArray, vtkPointData* pointData, vtkCellData* cellData,
67 vtkPoints* gridNodes) override;
68
73 int GetNumberOfLocalGrids() { return static_cast<int>(this->GridIds.size()); }
74
81 int GetGridRank(int gridID);
82
86 bool IsGridRemote(int gridID);
87
91 bool IsGridLocal(int gridID);
92
98 void Initialize();
99
105 void ComputeNeighbors() override;
106
111 void CreateGhostLayers(int N = 1) override;
112
113protected:
116
118 int Rank;
120
121 std::vector<int> GridRanks; // Corresponding rank for each grid
122 std::vector<int> GridIds; // List of GridIds, owned by this process
123
124 // Data structures to store the remote ghost data of each grid for each one
125 // of its neighbors. The first index is the global grid index. The second
126 // is the neighbor index.
127 std::vector<std::vector<vtkPoints*>> RemotePoints;
128 std::vector<std::vector<vtkPointData*>> RemotePointData;
129 std::vector<std::vector<vtkCellData*>> RemoteCellData;
130
131 // Data structures to store the send/receive buffer sizes and corresponding
132 // persistent buffers. The first index is the global grid index. The second
133 // index is the neighbor index for the given grid.
134 std::vector<std::vector<unsigned int>> SendBufferSizes;
135 std::vector<std::vector<unsigned int>> RcvBufferSizes;
136 std::vector<std::vector<unsigned char*>> SendBuffers;
137 std::vector<std::vector<unsigned char*>> RcvBuffers;
138
142
143 // Array of MPI requests
145
149 bool GridExtentsAreEqual(int rhs[6], int lhs[6]);
150
154 bool HasPointData(int gridIdx);
155
159 bool HasCellData(int gridIdx);
160
164 bool HasPoints(int gridIdx);
165
169 void InitializeMessageCounters();
170
175 void ClearRemoteData();
176
180 void ClearRawBuffers();
181
186 void RegisterRemoteGrid(int gridID, int extents[6], int process);
187
192 void TransferRemoteNeighborData(int gridIdx, int nei, const vtkStructuredNeighbor& Neighbor);
193
199 void TransferGhostDataFromNeighbors(int gridID) override;
200
205
211
216 void DeserializeBufferSizesForProcess(int* buffersizes, vtkIdType N, int processId);
217
222 void SerializeBufferSizes(int*& sizesbuf, vtkIdType& N);
223
229
236
242
247 void PostSends();
248
255
262
267
272 void SerializeGhostPoints(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
273
277 VTK_DEPRECATED_IN_9_6_0("Use vtkMultiProcessStream::Push(vtkDataArray*) instead")
278 void SerializeDataArray(vtkDataArray*, vtkMultiProcessStream&);
279
284 void SerializeFieldData(int sourceExtent[6], int targetExtent[6], vtkFieldData* fieldData,
285 vtkMultiProcessStream& bytestream);
286
291 void SerializeGhostPointData(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
292
297 void SerializeGhostCellData(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
298
303 void DeserializeGhostPoints(int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
304
309 void DeserializeDataArray(vtkDataArray*&, int, int, int, vtkMultiProcessStream&);
310
315 VTK_DEPRECATED_IN_9_6_0("Use vtkFieldDataSerializer::Deserialize() instead.")
316 void DeserializeFieldData(int ext[6], vtkFieldData* fieldData, vtkMultiProcessStream& bytestream);
317
322 void DeserializeGhostPointData(
323 int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
324
329 void DeserializeGhostCellData(
330 int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
331
338 void SerializeGhostData(
339 int sndGridID, int rcvGrid, int sndext[6], unsigned char*& buffer, unsigned int& size);
340
345 void DeserializeGhostData(int gridID, int neiListID, int neiGridIdx, int rcvext[6],
346 unsigned char* buffer, unsigned int size);
347
352 void ExchangeGridExtents();
353
358 void SerializeGridExtents(int*& sndbuffer, vtkIdType& N);
359
364 void DeserializeGridExtentForProcess(int* rcvbuffer, vtkIdType& N, int processId);
365
366private:
368 void operator=(const vtkPStructuredGridConnectivity&) = delete;
369};
370
371//=============================================================================
372// INLINE METHODS
373//=============================================================================
374
375inline bool vtkPStructuredGridConnectivity::GridExtentsAreEqual(int rhs[6], int lhs[6])
376{
377 for (int i = 0; i < 6; ++i)
378 {
379 if (rhs[i] != lhs[i])
380 {
381 return false;
382 }
383 }
384 return true;
385}
386
387//------------------------------------------------------------------------------
389{
390 // Sanity check
391 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
392 (gridIdx < static_cast<int>(this->NumberOfGrids)));
393
394 if ((this->GridPointData[gridIdx] != nullptr) &&
395 (this->GridPointData[gridIdx]->GetNumberOfArrays() > 0))
396 {
397 return true;
398 }
399 return false;
400}
401
402//------------------------------------------------------------------------------
404{
405 // Sanity check
406 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
407 (gridIdx < static_cast<int>(this->NumberOfGrids)));
408
409 if ((this->GridCellData[gridIdx] != nullptr) &&
410 (this->GridCellData[gridIdx]->GetNumberOfArrays() > 0))
411 {
412 return true;
413 }
414 return false;
415}
416
417//------------------------------------------------------------------------------
419{
420 // Sanity check
421 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
422 (gridIdx < static_cast<int>(this->NumberOfGrids)));
423
424 if (this->GridPoints[gridIdx] != nullptr)
425 {
426 return true;
427 }
428 return false;
429}
430
431//------------------------------------------------------------------------------
433{
434 this->TotalNumberOfMsgs = this->TotalNumberOfRcvs = this->TotalNumberOfSends = 0;
435}
436
437//------------------------------------------------------------------------------
439{
440 this->SendBufferSizes.clear();
441 this->RcvBufferSizes.clear();
442
443 // STEP 0: Clear send buffers
444 for (unsigned int i = 0; i < this->SendBuffers.size(); ++i)
445 {
446 for (unsigned int j = 0; j < this->SendBuffers[i].size(); ++j)
447 {
448 delete[] this->SendBuffers[i][j];
449 } // END for all neighbors
450 this->SendBuffers[i].clear();
451 } // END for all grids
452 this->SendBuffers.clear();
453
454 // STEP 1: Clear rcv buffers
455 for (unsigned int i = 0; i < this->RcvBuffers.size(); ++i)
456 {
457 for (unsigned int j = 0; j < this->RcvBuffers[i].size(); ++j)
458 {
459 delete[] this->RcvBuffers[i][j];
460 } // END for all neighbors
461 this->RcvBuffers[i].clear();
462 } // END for all grids
463 this->RcvBuffers.clear();
464}
465
466//------------------------------------------------------------------------------
468{
469 // STEP 0: Clear remote points
470 for (unsigned int i = 0; i < this->RemotePoints.size(); ++i)
471 {
472 for (unsigned int j = 0; j < this->RemotePoints[i].size(); ++j)
473 {
474 if (this->RemotePoints[i][j] != nullptr)
475 {
476 this->RemotePoints[i][j]->Delete();
477 }
478 } // END for all j
479 this->RemotePoints[i].clear();
480 } // END for all i
481 this->RemotePoints.clear();
482
483 // STEP 1: Clear remote point data
484 for (unsigned int i = 0; i < this->RemotePointData.size(); ++i)
485 {
486 for (unsigned int j = 0; j < this->RemotePointData[i].size(); ++j)
487 {
488 if (this->RemotePointData[i][j] != nullptr)
489 {
490 this->RemotePointData[i][j]->Delete();
491 }
492 } // END for all j
493 this->RemotePointData[i].clear();
494 } // END for all i
495 this->RemotePointData.clear();
496
497 // STEP 2: Clear remote cell data
498 for (unsigned int i = 0; i < this->RemoteCellData.size(); ++i)
499 {
500 for (unsigned int j = 0; j < this->RemoteCellData[i].size(); ++j)
501 {
502 if (this->RemoteCellData[i][j] != nullptr)
503 {
504 this->RemoteCellData[i][j]->Delete();
505 }
506 } // END for all j
507 this->RemoteCellData[i].clear();
508 }
509 this->RemoteCellData.clear();
510}
511
512//------------------------------------------------------------------------------
514{
515 return (!this->IsGridLocal(gridID));
516}
517
518//------------------------------------------------------------------------------
520{
521 assert("pre: Instance has not been initialized!" && this->Initialized);
522 assert("pre: gridID is out-of-bounds" && (gridID >= 0) &&
523 (gridID < static_cast<int>(this->NumberOfGrids)));
524 assert(
525 "pre: GridRanks is not properly allocated" && this->NumberOfGrids == this->GridRanks.size());
526 return ((this->GridRanks[gridID] == this->Rank));
527}
528
529//------------------------------------------------------------------------------
531{
532 assert("pre: Instance has not been initialized!" && this->Initialized);
533 assert("pre: gridID out-of-bounds!" &&
534 (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
535 return (this->GridRanks[gridID]);
536}
537VTK_ABI_NAMESPACE_END
538#endif /* vtkPStructuredGridConnectivity_h */
represent and manipulate cell attribute data
abstract superclass for arrays of numeric data
A concrete instance of vtkObject which provides functionality for serializing and de-serializing fiel...
Represents and manipulates a collection of data arrays.
a simple class to control print indentation
Definition vtkIndent.h:108
Process communication using MPI.
Multiprocessing communication superclass.
stream used to pass data across processes using vtkMultiProcessController.
vtkPStructuredGridConnectivity inherits from vtkStructuredGridConnectivity and implements functionali...
int GetNumberOfLocalGrids()
Returns the number of local grids registers by the process that owns the current vtkPStructuredGridCo...
~vtkPStructuredGridConnectivity() override
std::vector< std::vector< unsigned int > > RcvBufferSizes
void TransferRemoteNeighborData(int gridIdx, int nei, const vtkStructuredNeighbor &Neighbor)
This method transfers all the remote neighbor data to the ghosted grid instance of the grid correspon...
virtual void SetController(vtkMultiProcessController *)
Set & Get the process controller.
bool IsGridLocal(int gridID)
Returns true iff the grid corresponding to the given gridID is local.
void PrintSelf(ostream &os, vtkIndent indent) override
Methods invoked by print to print information about the object including superclasses.
void SetNumberOfGrids(unsigned int N) override
Sets the total number of domains distributed among processors.
static vtkPStructuredGridConnectivity * New()
void RegisterRemoteGrid(int gridID, int extents[6], int process)
Registers a remote grid with the given grid Id, structured extents and process.
void ClearRawBuffers()
Clears all raw send/rcv buffers.
void ExchangeGhostDataPost()
Helper method for exchanging ghost data.
bool HasPoints(int gridIdx)
Returns true iff the grid corresponding to the given ID has points.
std::vector< std::vector< unsigned char * > > SendBuffers
bool IsGridRemote(int gridID)
Returns true iff the grid is remote, otherwise false.
std::vector< std::vector< vtkPoints * > > RemotePoints
int GetGridRank(int gridID)
Returns the rank of the given gridID.
void ExchangeGhostData()
Exchanges ghost data of the grids owned by this process.
void CreateGhostLayers(int N=1) override
Creates ghost layers on the grids owned by this process using data from both local and remote block n...
void SerializeGhostPoints(int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize the ghost points to send to a remote process.
void PostSends()
Helper method to communicate ghost data.
void CommunicateGhostData()
Helper method for exchanging ghost data.
bool HasCellData(int gridIdx)
Returns true iff the grid corresponding to the given ID has cell data.
void TransferGhostDataFromNeighbors(int gridID) override
This method transfers the fields (point data and cell data) to the ghost extents from the neighboring...
void DeserializeBufferSizesForProcess(int *buffersizes, vtkIdType N, int processId)
Helper method to deserialize the buffer sizes coming from the given process.
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 UnpackGhostData()
Helper method to unpack the raw ghost data from the receive buffers in to the VTK remote point data-s...
void RegisterGrid(int gridID, int extents[6], vtkUnsignedCharArray *nodesGhostArray, vtkUnsignedCharArray *cellGhostArray, vtkPointData *pointData, vtkCellData *cellData, vtkPoints *gridNodes) override
See vtkStructuredGridConnectivity::RegisterGrid.
void SerializeBufferSizes(int *&sizesbuf, vtkIdType &N)
Helper method to serialize the buffer sizes for the grids of this process to neighboring grids.
bool HasPointData(int gridIdx)
Returns true iff the grid corresponding to the given ID has point data.
std::vector< std::vector< unsigned int > > SendBufferSizes
void ExchangeGhostDataInit()
Helper method for exchanging ghost data.
std::vector< std::vector< vtkCellData * > > RemoteCellData
void ComputeNeighbors() override
Computes the neighboring topology of a distributed structured grid data-set.
void PostReceives()
Helper method to communicate ghost data.
void Initialize()
Initializes this instance of vtkPStructuredGridConnectivity, essentially, the acquires the local proc...
void InitializeMessageCounters()
Sets all message counters to 0.
std::vector< std::vector< vtkPointData * > > RemotePointData
std::vector< std::vector< unsigned char * > > RcvBuffers
represent and manipulate point attribute data
represent and manipulate 3D points
Definition vtkPoints.h:139
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
#define VTK_DEPRECATED_IN_9_6_0(reason)
int vtkIdType
Definition vtkType.h:367