VTK  9.7.20260727
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
21
22#ifndef vtkPStructuredGridConnectivity_h
23#define vtkPStructuredGridConnectivity_h
24
25// VTK include directives
26#include "vtkFiltersParallelGeometryModule.h" // For export macro
27#include "vtkMPICommunicator.h" // Needed for vtkMPICommunicator::Request
29
30// C++ include directives
31#include <vector> // For STL vector
32
33// Forward declarations
34VTK_ABI_NAMESPACE_BEGIN
38// class vtkMPICommunicator::Request;
39
40class VTKFILTERSPARALLELGEOMETRY_EXPORT vtkPStructuredGridConnectivity
42{
43public:
46 void PrintSelf(ostream& os, vtkIndent indent) override;
47
49
55
59 void SetNumberOfGrids(unsigned int N) override;
60
64 void RegisterGrid(int gridID, int extents[6], vtkUnsignedCharArray* nodesGhostArray,
65 vtkUnsignedCharArray* cellGhostArray, vtkPointData* pointData, vtkCellData* cellData,
66 vtkPoints* gridNodes) override;
67
72 int GetNumberOfLocalGrids() { return static_cast<int>(this->GridIds.size()); }
73
80 int GetGridRank(int gridID);
81
85 bool IsGridRemote(int gridID);
86
90 bool IsGridLocal(int gridID);
91
97 void Initialize();
98
104 void ComputeNeighbors() override;
105
110 void CreateGhostLayers(int N = 1) override;
111
112protected:
115
117 int Rank;
119
120 std::vector<int> GridRanks; // Corresponding rank for each grid
121 std::vector<int> GridIds; // List of GridIds, owned by this process
122
123 // Data structures to store the remote ghost data of each grid for each one
124 // of its neighbors. The first index is the global grid index. The second
125 // is the neighbor index.
126 std::vector<std::vector<vtkPoints*>> RemotePoints;
127 std::vector<std::vector<vtkPointData*>> RemotePointData;
128 std::vector<std::vector<vtkCellData*>> RemoteCellData;
129
130 // Data structures to store the send/receive buffer sizes and corresponding
131 // persistent buffers. The first index is the global grid index. The second
132 // index is the neighbor index for the given grid.
133 std::vector<std::vector<unsigned int>> SendBufferSizes;
134 std::vector<std::vector<unsigned int>> RcvBufferSizes;
135 std::vector<std::vector<unsigned char*>> SendBuffers;
136 std::vector<std::vector<unsigned char*>> RcvBuffers;
137
141
142 // Array of MPI requests
144
148 bool GridExtentsAreEqual(int rhs[6], int lhs[6]);
149
153 bool HasPointData(int gridIdx);
154
158 bool HasCellData(int gridIdx);
159
163 bool HasPoints(int gridIdx);
164
169
174 void ClearRemoteData();
175
179 void ClearRawBuffers();
180
185 void RegisterRemoteGrid(int gridID, int extents[6], int process);
186
191 void TransferRemoteNeighborData(int gridIdx, int nei, const vtkStructuredNeighbor& Neighbor);
192
198 void TransferGhostDataFromNeighbors(int gridID) override;
199
204
210
215 void DeserializeBufferSizesForProcess(int* buffersizes, vtkIdType N, int processId);
216
221 void SerializeBufferSizes(int*& sizesbuf, vtkIdType& N);
222
228
235
241
246 void PostSends();
247
254
261
266
271 void SerializeGhostPoints(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
272
277 void SerializeFieldData(int sourceExtent[6], int targetExtent[6], vtkFieldData* fieldData,
278 vtkMultiProcessStream& bytestream);
279
284 void SerializeGhostPointData(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
285
290 void SerializeGhostCellData(int gridIdx, int ext[6], vtkMultiProcessStream& bytestream);
291
296 void DeserializeGhostPoints(int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
297
303 int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
304
310 int gridIdx, int nei, int ext[6], vtkMultiProcessStream& bytestream);
311
319 int sndGridID, int rcvGrid, int sndext[6], unsigned char*& buffer, unsigned int& size);
320
325 void DeserializeGhostData(int gridID, int neiListID, int neiGridIdx, int rcvext[6],
326 unsigned char* buffer, unsigned int size);
327
333
338 void SerializeGridExtents(int*& sndbuffer, vtkIdType& N);
339
344 void DeserializeGridExtentForProcess(int* rcvbuffer, vtkIdType& N, int processId);
345
346private:
348 void operator=(const vtkPStructuredGridConnectivity&) = delete;
349};
350
351//=============================================================================
352// INLINE METHODS
353//=============================================================================
354
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//------------------------------------------------------------------------------
369{
370 // Sanity check
371 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
372 (gridIdx < static_cast<int>(this->NumberOfGrids)));
373
374 if ((this->GridPointData[gridIdx] != nullptr) &&
375 (this->GridPointData[gridIdx]->GetNumberOfArrays() > 0))
376 {
377 return true;
378 }
379 return false;
380}
381
382//------------------------------------------------------------------------------
384{
385 // Sanity check
386 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
387 (gridIdx < static_cast<int>(this->NumberOfGrids)));
388
389 if ((this->GridCellData[gridIdx] != nullptr) &&
390 (this->GridCellData[gridIdx]->GetNumberOfArrays() > 0))
391 {
392 return true;
393 }
394 return false;
395}
396
397//------------------------------------------------------------------------------
399{
400 // Sanity check
401 assert("pre: grid index is out-of-bounds!" && (gridIdx >= 0) &&
402 (gridIdx < static_cast<int>(this->NumberOfGrids)));
403
404 if (this->GridPoints[gridIdx] != nullptr)
405 {
406 return true;
407 }
408 return false;
409}
410
411//------------------------------------------------------------------------------
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] != nullptr)
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] != nullptr)
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] != nullptr)
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//------------------------------------------------------------------------------
494{
495 return (!this->IsGridLocal(gridID));
496}
497
498//------------------------------------------------------------------------------
500{
501 assert("pre: Instance has not been initialized!" && this->Initialized);
502 assert("pre: gridID is out-of-bounds" && (gridID >= 0) &&
503 (gridID < static_cast<int>(this->NumberOfGrids)));
504 assert(
505 "pre: GridRanks is not properly allocated" && this->NumberOfGrids == this->GridRanks.size());
506 return ((this->GridRanks[gridID] == this->Rank));
507}
508
509//------------------------------------------------------------------------------
511{
512 assert("pre: Instance has not been initialized!" && this->Initialized);
513 assert("pre: gridID out-of-bounds!" &&
514 (gridID >= 0 && gridID < static_cast<int>(this->NumberOfGrids)));
515 return (this->GridRanks[gridID]);
516}
517VTK_ABI_NAMESPACE_END
518#endif /* vtkPStructuredGridConnectivity_h */
std::vector< vtkCellData * > GridCellData
std::vector< vtkPointData * > GridPointData
std::vector< vtkPoints * > GridPoints
represent and manipulate cell attribute data
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.
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 GridExtentsAreEqual(int rhs[6], int lhs[6])
Returns true if the two extents are equal, otherwise false.
bool IsGridLocal(int gridID)
Returns true iff the grid corresponding to the given gridID is local.
void DeserializeGhostPointData(int gridIdx, int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost point data received from a remote process.
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 SerializeGhostCellData(int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize ghost cell data.
void ExchangeGhostDataPost()
Helper method for exchanging ghost data.
void DeserializeGhostPoints(int gridIdx, int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost points received from a remote process.
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 DeserializeGhostCellData(int gridIdx, int nei, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to de-serialize the ghost cell data received from a remote process.
void SerializeGhostData(int sndGridID, int rcvGrid, int sndext[6], unsigned char *&buffer, unsigned int &size)
Given a grid ID and the corresponding send extent, this method serializes the grid and data within th...
void TransferGhostDataFromNeighbors(int gridID) override
This method transfers the fields (point data and cell data) to the ghost extents from the neighboring...
void ExchangeGridExtents()
Exchanges the grid extents among all processes and fully populates the GridExtents vector.
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 SerializeGridExtents(int *&sndbuffer, vtkIdType &N)
Serializes the grid extents and information in a buffer to send over MPI The data is serialized as fo...
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.
void DeserializeGhostData(int gridID, int neiListID, int neiGridIdx, int rcvext[6], unsigned char *buffer, unsigned int size)
Given the raw buffer consisting of ghost data, this method deserializes the object and returns the gr...
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 SerializeFieldData(int sourceExtent[6], int targetExtent[6], vtkFieldData *fieldData, vtkMultiProcessStream &bytestream)
Helper method to serialize field data.
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 DeserializeGridExtentForProcess(int *rcvbuffer, vtkIdType &N, int processId)
Deserializes the received grid extent information to the GridExtents internal data-structures.
void SerializeGhostPointData(int gridIdx, int ext[6], vtkMultiProcessStream &bytestream)
Helper method to serialize ghost point data.
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:140
An internal, light-weight class used to store neighbor information.
dynamic, self-adjusting array of unsigned char
int vtkIdType
Definition vtkType.h:363