Documentation 6b54b78464
Loading...
Searching...
No Matches
CLinearPartitioner.hpp
Go to the documentation of this file.
1/*!
2 * \file CLinearPartitioner.hpp
3 * \brief Header file for the class CLinearPartitioner.
4 * The implementations are in the <i>CLinearPartitioner.cpp</i> file.
5 * \author T. Economon
6 * \version 8.5.0 "Harrier"
7 *
8 * SU2 Project Website: https://su2code.github.io
9 *
10 * The SU2 Project is maintained by the SU2 Foundation
11 * (http://su2foundation.org)
12 *
13 * Copyright 2012-2026, SU2 Contributors (cf. AUTHORS.md)
14 *
15 * SU2 is free software; you can redistribute it and/or
16 * modify it under the terms of the GNU Lesser General Public
17 * License as published by the Free Software Foundation; either
18 * version 2.1 of the License, or (at your option) any later version.
19 *
20 * SU2 is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 * Lesser General Public License for more details.
24 *
25 * You should have received a copy of the GNU Lesser General Public
26 * License along with SU2. If not, see <http://www.gnu.org/licenses/>.
27 */
28
29#pragma once
30
31#include "../parallelization/mpi_structure.hpp"
32
33#include <vector>
34
35using namespace std;
36
37/*!
38 * \class CLinearPartitioner
39 * \brief Helper class that provides the counts for each rank in a linear
40 * partitioning given the global count as input.
41 * \author T. Economon
42 */
44 protected:
45 int size; /*!< \brief MPI Size. */
46
47 vector<unsigned long> firstIndex; /*!< \brief Vector containing the first index on each rank due to a linear
48 partitioning by global count. */
49 vector<unsigned long> lastIndex; /*!< \brief Vector containing the last index on each rank due to a linear
50 partitioning by global count. */
51 vector<unsigned long>
52 sizeOnRank; /*!< \brief Vector containing the total size of the current rank's linear partition. */
53 vector<unsigned long> cumulativeSizeBeforeRank; /*!< \brief Vector containing the cumulative size of all linear
54 partitions before the current rank. */
55
56 public:
57 CLinearPartitioner() = default;
58
59 /*!
60 * \brief Constructor of the CLinearPartitioner class, see Initialize.
61 */
62 CLinearPartitioner(unsigned long global_count, unsigned long offset, bool isDisjoint = false) {
63 Initialize(global_count, offset, isDisjoint);
64 }
65
66 /*!
67 * \brief Initialize the CLinearPartitioner class.
68 * \param[in] global_count - global count to be linearly partitioned.
69 * \param[in] offset - offset from 0 for the first index on rank 0 (typically 0).
70 * \param[in] isDisjoint - boolean controlling whether the linear partitions should be disjoint (default is false).
71 */
72 void Initialize(unsigned long global_count, unsigned long offset, bool isDisjoint = false);
73
74 /*!
75 * \brief Get the rank that owns the index based on the linear partitioning.
76 * \param[in] index - Current index.
77 * \returns Owning rank for the current index based on linear partitioning.
78 */
79 unsigned long GetRankContainingIndex(unsigned long index) const;
80
81 /*!
82 * \brief Get the first index of the current rank's linear partition.
83 * \param[in] rank - MPI rank identifier.
84 * \returns First index of the current rank's linear partition.
85 */
86 inline unsigned long GetFirstIndexOnRank(int rank) const { return firstIndex[rank]; }
87
88 /*!
89 * \brief Get the last index of the current rank's linear partition.
90 * \param[in] rank - MPI rank identifier.
91 * \returns Last index of the current rank's linear partition.
92 */
93 inline unsigned long GetLastIndexOnRank(int rank) const { return lastIndex[rank]; }
94
95 /*!
96 * \brief Get the total size of the current rank's linear partition.
97 * \param[in] rank - MPI rank identifier.
98 * \returns Size of the current rank's linear partition.
99 */
100 inline unsigned long GetSizeOnRank(int rank) const { return sizeOnRank[rank]; }
101
102 /*!
103 * \brief Get the cumulative size of all linear partitions before the current rank.
104 * \param[in] rank - MPI rank identifier.
105 * \returns Cumulative size of all linear partitions before the current rank.
106 */
107 inline unsigned long GetCumulativeSizeBeforeRank(int rank) const { return cumulativeSizeBeforeRank[rank]; }
108
109 /*!
110 * \brief Checks if an index belongs to a rank.
111 * \param[in] index - Current index.
112 * \param[in] rank - MPI rank identifier.
113 * \returns True if index is owned by rank.
114 */
115 bool IndexBelongsToRank(unsigned long index, int rank) const {
116 return index >= cumulativeSizeBeforeRank[rank] && index < cumulativeSizeBeforeRank[rank + 1];
117 }
118};
Helper class that provides the counts for each rank in a linear partitioning given the global count a...
Definition CLinearPartitioner.hpp:43
unsigned long GetCumulativeSizeBeforeRank(int rank) const
Get the cumulative size of all linear partitions before the current rank.
Definition CLinearPartitioner.hpp:107
unsigned long GetRankContainingIndex(unsigned long index) const
Get the rank that owns the index based on the linear partitioning.
Definition CLinearPartitioner.cpp:73
unsigned long GetLastIndexOnRank(int rank) const
Get the last index of the current rank's linear partition.
Definition CLinearPartitioner.hpp:93
void Initialize(unsigned long global_count, unsigned long offset, bool isDisjoint=false)
Initialize the CLinearPartitioner class.
Definition CLinearPartitioner.cpp:31
bool IndexBelongsToRank(unsigned long index, int rank) const
Checks if an index belongs to a rank.
Definition CLinearPartitioner.hpp:115
vector< unsigned long > firstIndex
Vector containing the first index on each rank due to a linear partitioning by global count.
Definition CLinearPartitioner.hpp:47
unsigned long GetFirstIndexOnRank(int rank) const
Get the first index of the current rank's linear partition.
Definition CLinearPartitioner.hpp:86
vector< unsigned long > cumulativeSizeBeforeRank
Vector containing the cumulative size of all linear partitions before the current rank.
Definition CLinearPartitioner.hpp:53
vector< unsigned long > sizeOnRank
Vector containing the total size of the current rank's linear partition.
Definition CLinearPartitioner.hpp:52
CLinearPartitioner(unsigned long global_count, unsigned long offset, bool isDisjoint=false)
Constructor of the CLinearPartitioner class, see Initialize.
Definition CLinearPartitioner.hpp:62
unsigned long GetSizeOnRank(int rank) const
Get the total size of the current rank's linear partition.
Definition CLinearPartitioner.hpp:100
CLinearPartitioner()=default
int size
MPI Size.
Definition CLinearPartitioner.hpp:45
vector< unsigned long > lastIndex
Vector containing the last index on each rank due to a linear partitioning by global count.
Definition CLinearPartitioner.hpp:49