VTK  9.3.20241008
vtkBlockDistribution.h
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2// SPDX-FileCopyrightText: Copyright (C) 2008 The Trustees of Indiana University.
3// SPDX-License-Identifier: BSD-3-Clause AND BSL-1.0
12#ifndef vtkBlockDistribution_h
13#define vtkBlockDistribution_h
14
15#include "vtkABINamespace.h"
16
17VTK_ABI_NAMESPACE_BEGIN
19{
20public:
25
30 vtkIdType GetNumElements() { return this->NumElements; }
31
36 vtkIdType GetNumProcessors() { return this->NumProcessors; }
37
43
49
55
61
67
68private:
69 vtkIdType NumElements;
70 vtkIdType NumProcessors;
71};
72
73// ----------------------------------------------------------------------
74
76 : NumElements(N)
77 , NumProcessors(P)
78{
79}
80
81// ----------------------------------------------------------------------
82
84{
85 return (this->NumElements / this->NumProcessors) +
86 (rank < this->NumElements % this->NumProcessors ? 1 : 0);
87}
88
89// ----------------------------------------------------------------------
90
92{
93 vtkIdType smallBlockSize = this->NumElements / this->NumProcessors;
94 vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
95 vtkIdType cutoffIndex = cutoffProcessor * (smallBlockSize + 1);
96
97 if (globalIndex < cutoffIndex)
98 {
99 return globalIndex / (smallBlockSize + 1);
100 }
101 else
102 {
103 return cutoffProcessor + (globalIndex - cutoffIndex) / smallBlockSize;
104 }
105}
106
107// ----------------------------------------------------------------------
108
110{
111 vtkIdType rank = this->GetProcessorOfElement(globalIndex);
112 return globalIndex - this->GetFirstGlobalIndexOnProcessor(rank);
113}
114
115// ----------------------------------------------------------------------
116
118{
119 vtkIdType estimate = rank * (this->NumElements / this->NumProcessors + 1);
120 vtkIdType cutoffProcessor = this->NumElements % this->NumProcessors;
121 if (rank < cutoffProcessor)
122 {
123 return estimate;
124 }
125 else
126 {
127 return estimate - (rank - cutoffProcessor);
128 }
129}
130
131// ----------------------------------------------------------------------
132
134{
135 return this->GetFirstGlobalIndexOnProcessor(rank) + localIndex;
136}
137
138VTK_ABI_NAMESPACE_END
139#endif
140// VTK-HeaderTest-Exclude: vtkBlockDistribution.h
A helper class that manages a block distribution of N elements of data.
vtkIdType GetGlobalIndex(vtkIdType localIndex, vtkIdType rank)
Retrieve the global index associated with the given local index on the processor with the given rank.
vtkIdType GetNumElements()
Retrieves the number of elements for which this block distribution was built.
vtkIdType GetLocalIndexOfElement(vtkIdType globalIndex)
Retrieve the local index (offset) on the processor determined by GetProcessorOfElement that refers to...
vtkIdType GetProcessorOfElement(vtkIdType globalIndex)
Retrieve the process number in [0, GetNumProcessors()) where the element with the given global index ...
vtkIdType GetNumProcessors()
Retrieves the number of processors for which this block distribution was built.
vtkIdType GetFirstGlobalIndexOnProcessor(vtkIdType rank)
Retrieve the first global index stored on the processor with the given rank.
vtkBlockDistribution(vtkIdType N, vtkIdType P)
Create a block distribution with N elements on P processors.
vtkIdType GetBlockSize(vtkIdType rank)
Get the block size for the processor with the given rank.
int vtkIdType
Definition vtkType.h:315