24#if BITPIT_ENABLE_MPI==1
27#include <unordered_set>
29#include "voloctree.hpp"
41void VolOctree::initializeTreePartitioning()
48 std::vector<double> octantWeightStorage;
49 const std::vector<double> *octantWeights;
51 std::size_t nOctants = m_tree->getNumOctants();
53 octantWeightStorage.assign(nOctants, 0.);
54 octantWeightStorage[nOctants - 1] = 1.;
55 octantWeights = &octantWeightStorage;
57 octantWeights =
nullptr;
60 m_tree->loadBalance(octantWeights);
70void VolOctree::initializeTreeHaloSize(std::size_t haloSize)
72 m_tree->setNofGhostLayers(haloSize);
85 m_tree->setComm(communicator);
97 return std::numeric_limits<uint32_t>::max();
109 initializeTreeHaloSize(haloSize);
129 computePartitioningOctantWeights(cellWeights, defaultWeight);
132 std::vector<adaption::Info> partitioningData;
133 if (trackPartitioning) {
136 for (
const auto &entry : loadBalanceRanges.sendRanges) {
137 int receiver = entry.first;
138 if (receiver == currentRank) {
142 adaption::Type adaptionType;
143 if (loadBalanceRanges.sendAction == PabloUniform::LoadBalanceRanges::ACTION_DELETE) {
144 adaptionType = adaption::TYPE_DELETION;
146 adaptionType = adaption::TYPE_PARTITION_SEND;
149 partitioningData.emplace_back();
151 partitioningInfo.entity = adaption::ENTITY_CELL;
152 partitioningInfo.type = adaptionType;
153 partitioningInfo.rank = receiver;
155 const std::array<uint32_t, 2> &sendRange = entry.second;
156 uint32_t beginTreeId = sendRange[0];
157 uint32_t endTreeId = sendRange[1];
158 partitioningInfo.previous.reserve(endTreeId - beginTreeId);
159 for (uint32_t treeId = beginTreeId; treeId < endTreeId; ++treeId) {
161 partitioningInfo.previous.emplace_back();
162 long &cellId = partitioningInfo.previous.back();
168 return partitioningData;
184 std::vector<adaption::Info> partitioningData;
187 if (m_tree->getDim() == 0) {
188 return partitioningData;
192 m_tree->loadBalance(m_partitioningOctantWeights.get());
195 partitioningData = sync(trackPartitioning);
200 return partitioningData;
209 clearPartitioningOctantWeights();
221 const std::vector<uint32_t> &ghostOctantSources = m_tree->getBordersPerProc().at(rank);
222 std::size_t nGhostSources = ghostOctantSources.size();
224 std::vector<long> ghostCellSources(nGhostSources);
225 for (std::size_t k = 0; k < nGhostSources; ++k) {
226 OctantInfo octantInfo(ghostOctantSources[k],
true);
230 return ghostCellSources;
242void VolOctree::computePartitioningOctantWeights(
const std::unordered_map<long, double> &cellWeights,
double defaultWeight)
244 bool useWeights = !cellWeights.empty();
245 MPI_Allreduce(MPI_IN_PLACE, &useWeights, 1, MPI_C_BOOL, MPI_LOR,
getCommunicator());
247 clearPartitioningOctantWeights();
254 std::size_t nOctants = m_tree->getNumOctants();
255 m_partitioningOctantWeights = std::unique_ptr<std::vector<double>>(
new std::vector<double>(nOctants, defaultWeight));
256 for (CellConstIterator cellItr = beginItr; cellItr != endItr; ++cellItr) {
257 long cellId = cellItr.getId();
258 auto weightItr = cellWeights.find(cellId);
259 if (weightItr != cellWeights.end()) {
261 uint32_t treeId = octantInfo.id;
262 (*m_partitioningOctantWeights)[treeId] = weightItr->second;
270void VolOctree::clearPartitioningOctantWeights()
272 m_partitioningOctantWeights.reset();
CellConstIterator internalCellConstEnd() const
CellConstIterator internalCellConstBegin() const
const MPI_Comm & getCommunicator() const
virtual void setCommunicator(MPI_Comm communicator)
std::vector< long > _findGhostCellExchangeSources(int rank) override
OctantInfo getCellOctant(long id) const
void _setHaloSize(std::size_t haloSize) override
std::size_t _getMaxHaloSize() override
std::vector< adaption::Info > _partitioningAlter(bool trackPartitioning) override
void _partitioningCleanup() override
std::vector< adaption::Info > _partitioningPrepare(const std::unordered_map< long, double > &cellWeights, double defaultWeight, bool trackPartitioning) override
void setCommunicator(MPI_Comm communicator) override
long getOctantId(const OctantInfo &octantInfo) const
The Info struct defines the information associated to an adaption.