Skip to content

Commit

Permalink
Merge Pull Request #8873 from trilinos/Trilinos/stk-snapshot
Browse files Browse the repository at this point in the history
Automatically Merged using Trilinos Pull Request AutoTester
PR Title: STK: Snapshot 03-12-21 10:28
PR Author: tasmith4
  • Loading branch information
trilinos-autotester authored Mar 13, 2021
2 parents 059b6e8 + b73cdad commit d130f4e
Show file tree
Hide file tree
Showing 124 changed files with 6,409 additions and 1,463 deletions.
5 changes: 1 addition & 4 deletions packages/stk/stk_balance/stk_balance/balance.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,7 @@ std::string construct_coloring_part_name(const int color, const stk::mesh::Part&

bool colorMesh(const BalanceSettings& balanceSettings, stk::mesh::BulkData& bulk, const stk::mesh::PartVector& parts)
{
ThrowRequireMsg(balanceSettings.getGraphOption() == BalanceSettings::COLOR_MESH ||
balanceSettings.getGraphOption() == BalanceSettings::COLOR_MESH_BY_TOPOLOGY ||
balanceSettings.getGraphOption() == BalanceSettings::COLOR_MESH_AND_OUTPUT_COLOR_FIELDS,
"colorMesh must be called with COLOR_MESH or COLOR_MESH_BY_TOPOLOGY Setting");
ThrowRequireMsg(balanceSettings.usingColoring(), "colorMesh must be called with COLOR_MESH or COLOR_MESH_BY_TOPOLOGY Setting");

internal::logMessage(bulk.parallel(), "Start Coloring Mesh");

Expand Down
14 changes: 8 additions & 6 deletions packages/stk/stk_balance/stk_balance/balanceUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,19 +117,21 @@ bool BalanceSettings::isMultiCriteriaRebalance() const
return false;
}

bool BalanceSettings::areVertexWeightsProvidedInAVector() const
#ifndef STK_HIDE_DEPRECATED_CODE // Delete after April 2021
STK_DEPRECATED bool BalanceSettings::areVertexWeightsProvidedInAVector() const
{
return false;
}

bool BalanceSettings::areVertexWeightsProvidedViaFields() const
STK_DEPRECATED std::vector<double> BalanceSettings::getVertexWeightsViaVector() const
{
return false;
return std::vector<double>();
}
#endif

std::vector<double> BalanceSettings::getVertexWeightsViaVector() const
bool BalanceSettings::areVertexWeightsProvidedViaFields() const
{
return std::vector<double>();
return false;
}

double BalanceSettings::getImbalanceTolerance() const
Expand Down Expand Up @@ -216,7 +218,7 @@ const stk::mesh::Field<int> * BalanceSettings::getSpiderVolumeConnectivityCountF
return nullptr;
}

bool BalanceSettings::useLocalIds() const
bool BalanceSettings::usingColoring() const
{
return getGraphOption() == stk::balance::BalanceSettings::COLOR_MESH ||
getGraphOption() == stk::balance::BalanceSettings::COLOR_MESH_BY_TOPOLOGY ||
Expand Down
23 changes: 15 additions & 8 deletions packages/stk/stk_balance/stk_balance/balanceUtils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,11 @@ class BalanceSettings
virtual bool isIncrementalRebalance() const;
virtual bool isMultiCriteriaRebalance() const;

virtual bool areVertexWeightsProvidedInAVector() const;
virtual std::vector<double> getVertexWeightsViaVector() const;
#ifndef STK_HIDE_DEPRECATED_CODE // Delete after April 2021
STK_DEPRECATED virtual bool areVertexWeightsProvidedInAVector() const;
STK_DEPRECATED virtual std::vector<double> getVertexWeightsViaVector() const;
#endif

virtual bool areVertexWeightsProvidedViaFields() const;

virtual double getImbalanceTolerance() const;
Expand Down Expand Up @@ -151,7 +154,7 @@ class BalanceSettings
virtual std::string getSpiderVolumeConnectivityCountFieldName() const;
virtual const stk::mesh::Field<int> * getSpiderBeamConnectivityCountField(const stk::mesh::BulkData & stkMeshBulkData) const;
virtual const stk::mesh::Field<int> * getSpiderVolumeConnectivityCountField(const stk::mesh::BulkData & stkMeshBulkData) const;
virtual bool useLocalIds() const;
virtual bool usingColoring() const;

virtual bool useNodeBalancer() const;
virtual double getNodeBalancerTargetLoadBalance() const;
Expand Down Expand Up @@ -322,15 +325,17 @@ class BasicZoltan2Settings : public GraphCreationSettings
class UserSpecifiedVertexWeightsSetting : public GraphCreationSettings
{
public:
UserSpecifiedVertexWeightsSetting()
#ifndef STK_HIDE_DEPRECATED_CODE // Delete after April 2021
STK_DEPRECATED UserSpecifiedVertexWeightsSetting()
{
method = "parmetis";
m_includeSearchResultInGraph = false;
}
STK_DEPRECATED virtual bool areVertexWeightsProvidedInAVector() const { return true; }
STK_DEPRECATED void setVertexWeights(const std::vector<double>& weights) { vertex_weights = weights; }
STK_DEPRECATED virtual std::vector<double> getVertexWeightsViaVector() const { return vertex_weights; }
#endif
virtual double getGraphEdgeWeight(stk::topology element1Topology, stk::topology element2Topology) const { return 1.0; }
virtual bool areVertexWeightsProvidedInAVector() const { return true; }
void setVertexWeights(const std::vector<double>& weights) { vertex_weights = weights; }
virtual std::vector<double> getVertexWeightsViaVector() const { return vertex_weights; }
virtual int getGraphVertexWeight(stk::topology type) const { return 1; }
virtual double getGraphVertexWeight(stk::mesh::Entity entity, int criteria_index) const { return 1.0; }
//virtual double getImbalanceTolerance() const { return 1.05; }
Expand Down Expand Up @@ -367,7 +372,9 @@ class FieldVertexWeightSettings : public GraphCreationSettings
virtual ~FieldVertexWeightSettings() = default;

virtual double getGraphEdgeWeight(stk::topology element1Topology, stk::topology element2Topology) const { return 1.0; }
virtual bool areVertexWeightsProvidedInAVector() const { return false; }
#ifndef STK_HIDE_DEPRECATED_CODE // Delete after April 2021
STK_DEPRECATED virtual bool areVertexWeightsProvidedInAVector() const { return false; }
#endif
virtual bool areVertexWeightsProvidedViaFields() const { return true; }
virtual int getGraphVertexWeight(stk::topology type) const { return 1; }
virtual double getImbalanceTolerance() const { return 1.05; }
Expand Down
2 changes: 1 addition & 1 deletion packages/stk/stk_balance/stk_balance/internal/Balancer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ Balancer::Balancer(const BalanceSettings& settings)

bool Balancer::balance(BalanceMesh& mesh) const
{
std::vector<stk::mesh::Selector> selectors = {mesh.get_bulk().mesh_meta_data().locally_owned_part()};
std::vector<stk::mesh::Selector> selectors = {mesh.get_bulk().mesh_meta_data().universal_part()};
return balance(mesh, selectors);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ bool detectAndFixMechanisms(const stk::balance::BalanceSettings& graphSettings,
stk::mesh::impl::LocalIdMapper localIds(bulk, stk::topology::ELEM_RANK);

Zoltan2ParallelGraph zoltan2Graph;
fill_zoltan2_parallel_graph(bulk, graphSettings, localIds, zoltan2Graph);
fill_zoltan2_parallel_graph(bulk, graphSettings, zoltan2Graph);

std::vector<BalanceLocalNumber> tmpOffsets;
std::vector<BalanceGlobalNumber> tmpAdj;
Expand Down Expand Up @@ -65,11 +65,12 @@ bool detectAndFixMechanisms(const stk::balance::BalanceSettings& graphSettings,
}


void fill_zoltan2_parallel_graph(stk::mesh::BulkData& bulk, const stk::balance::BalanceSettings& graphSettings, const stk::mesh::impl::LocalIdMapper& localIds, Zoltan2ParallelGraph &zoltan2Graph)
void fill_zoltan2_parallel_graph(stk::mesh::BulkData& bulk, const stk::balance::BalanceSettings& graphSettings,
Zoltan2ParallelGraph &zoltan2Graph)
{
stk::mesh::Selector sel = bulk.mesh_meta_data().locally_owned_part();
stk::mesh::Selector sel = bulk.mesh_meta_data().universal_part();
zoltan2Graph.setMechanismCheckFlag();
stk::balance::internal::createZoltanParallelGraph(graphSettings, bulk, std::vector<stk::mesh::Selector>{sel}, localIds, zoltan2Graph);
stk::balance::internal::createZoltanParallelGraph(graphSettings, bulk, sel, zoltan2Graph);
}

size_t one_based(size_t input)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ void move_components(const Zoltan2ParallelGraph &zoltan2Graph,
const std::vector<stk::mesh::EntityVector>& elementsToMove,
const std::vector<int>& componentsToMove);

void fill_zoltan2_parallel_graph(stk::mesh::BulkData& bulk, const stk::balance::BalanceSettings& graphSettings, const stk::mesh::impl::LocalIdMapper& localIds, Zoltan2ParallelGraph &zoltan2Graph);
void fill_zoltan2_parallel_graph(stk::mesh::BulkData& bulk, const stk::balance::BalanceSettings& graphSettings,
Zoltan2ParallelGraph &zoltan2Graph);

}}} // end of namespaces

Expand Down
165 changes: 165 additions & 0 deletions packages/stk/stk_balance/stk_balance/internal/M2NDecomposer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,165 @@
// Copyright 2002 - 2008, 2010, 2011 National Technology Engineering
// Solutions of Sandia, LLC (NTESS). Under the terms of Contract
// DE-NA0003525 with NTESS, the U.S. Government retains certain rights
// in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following
// disclaimer in the documentation and/or other materials provided
// with the distribution.
//
// * Neither the name of NTESS nor the names of its contributors
// may be used to endorse or promote products derived from this
// software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
#include "M2NDecomposer.hpp"
#include <stk_mesh/base/BulkData.hpp>
#include <stk_mesh/base/Selector.hpp>
#include <stk_balance/balanceUtils.hpp>
#include <stk_balance/setup/M2NParser.hpp>
#include <stk_balance/internal/privateDeclarations.hpp>

namespace stk {
namespace balance {
namespace internal {

M2NDecomposer::M2NDecomposer(stk::mesh::BulkData & bulkData,
const stk::balance::BalanceSettings & balanceSettings,
const stk::balance::M2NParsedOptions & parsedOptions)
: m_bulkData(bulkData),
m_balanceSettings(balanceSettings),
m_parsedOptions(parsedOptions)
{
}

stk::mesh::EntityProcVec
M2NDecomposer::get_partition()
{
stk::mesh::EntityProcVec decomp;
std::vector<stk::mesh::Selector> selectors = { m_bulkData.mesh_meta_data().universal_part() };
stk::balance::internal::calculateGeometricOrGraphBasedDecomp(m_balanceSettings, m_parsedOptions.targetNumProcs,
decomp, m_bulkData, selectors);
return decomp;
}

std::vector<unsigned>
M2NDecomposer::map_new_subdomains_to_original_processors()
{
const unsigned numInitialSubdomains = m_bulkData.parallel_size();
const unsigned numFinalSubdomains = m_parsedOptions.targetNumProcs;

std::vector<unsigned> targetSubdomainsToProc(numFinalSubdomains, std::numeric_limits<unsigned>::max());
for (unsigned i = 0; i < numFinalSubdomains; ++i) {
targetSubdomainsToProc[i] = i % numInitialSubdomains;
}
return targetSubdomainsToProc;
}


M2NDecomposerNested::M2NDecomposerNested(stk::mesh::BulkData & bulkData,
const stk::balance::BalanceSettings & balanceSettings,
const stk::balance::M2NParsedOptions & parsedOptions)
: M2NDecomposer(bulkData, balanceSettings, parsedOptions)
{
const int numInitialSubdomains = m_bulkData.parallel_size();
const int numFinalSubdomains = m_parsedOptions.targetNumProcs;
ThrowRequireMsg((numFinalSubdomains % numInitialSubdomains) == 0,
"Final subdomains (" << numFinalSubdomains << ") must be an integer multiple of initial subdomains ("
<< numInitialSubdomains << ")");

m_numFinalSubdomainsPerProc = numFinalSubdomains / numInitialSubdomains;
}

stk::mesh::EntityProcVec
M2NDecomposerNested::get_partition()
{
declare_all_initial_subdomain_parts();
move_entities_into_initial_subdomain_part();

const int numInitialSubdomains = m_bulkData.parallel_size();
stk::mesh::EntityProcVec decomp;

for (int initialSubdomain = 0; initialSubdomain < numInitialSubdomains; ++initialSubdomain) {
stk::mesh::EntityProcVec subdomainDecomp = get_partition_for_subdomain(initialSubdomain);
if (initialSubdomain == m_bulkData.parallel_rank()) {
decomp = subdomainDecomp;
for (stk::mesh::EntityProc & entityProc : decomp) {
int & targetProc = entityProc.second;
targetProc += initialSubdomain*m_numFinalSubdomainsPerProc;
}
}
}

return decomp;
}

stk::mesh::EntityProcVec
M2NDecomposerNested::get_partition_for_subdomain(int subdomainId)
{
stk::mesh::EntityProcVec decomp;
std::vector<stk::mesh::Selector> selectors = { *m_bulkData.mesh_meta_data().get_part(get_initial_subdomain_part_name(subdomainId)) };
stk::balance::internal::calculateGeometricOrGraphBasedDecomp(m_balanceSettings, m_numFinalSubdomainsPerProc,
decomp, m_bulkData, selectors);
return decomp;
}

std::vector<unsigned>
M2NDecomposerNested::map_new_subdomains_to_original_processors()
{
const unsigned numFinalSubdomains = m_parsedOptions.targetNumProcs;

std::vector<unsigned> targetSubdomainsToProc(numFinalSubdomains, std::numeric_limits<unsigned>::max());
for (unsigned i = 0; i < numFinalSubdomains; ++i) {
targetSubdomainsToProc[i] = i / m_numFinalSubdomainsPerProc;
}
return targetSubdomainsToProc;
}

void
M2NDecomposerNested::declare_all_initial_subdomain_parts()
{
for (int i = 0; i < m_bulkData.parallel_size(); ++i) {
std::string partNameForSubdomain = get_initial_subdomain_part_name(i);
m_bulkData.mesh_meta_data().declare_part(partNameForSubdomain, stk::topology::ELEMENT_RANK);
}
}

void
M2NDecomposerNested::move_entities_into_initial_subdomain_part()
{
stk::mesh::Part * subdomainPart = m_bulkData.mesh_meta_data().get_part(get_initial_subdomain_part_name(m_bulkData.parallel_rank()));
stk::mesh::EntityVector localEntities;
m_bulkData.get_entities(stk::topology::ELEM_RANK, m_bulkData.mesh_meta_data().locally_owned_part(), localEntities);
m_bulkData.batch_change_entity_parts(localEntities, {subdomainPart}, {});
}

std::string
M2NDecomposerNested::get_initial_subdomain_part_name(int subdomainId)
{
std::ostringstream out;
out << "initial_subdomain_" << subdomainId;
return out.str();
}

}
}
}
Loading

0 comments on commit d130f4e

Please sign in to comment.