| 1 |
// @HEADER |
| 2 |
// ***************************************************************************** |
| 3 |
// MueLu: A package for multigrid based preconditioning |
| 4 |
// |
| 5 |
// Copyright 2012 NTESS and the MueLu contributors. |
| 6 |
// SPDX-License-Identifier: BSD-3-Clause |
| 7 |
// ***************************************************************************** |
| 8 |
// @HEADER |
| 9 |
|
| 10 |
#include <Teuchos_UnitTestHarness.hpp> |
| 11 |
#include <Teuchos_DefaultComm.hpp> |
| 12 |
#include <Teuchos_VerboseObject.hpp> |
| 13 |
|
| 14 |
#include "Kokkos_StaticCrsGraph.hpp" |
| 15 |
#include "KokkosGraph_Distance2ColorHandle.hpp" |
| 16 |
#include "KokkosGraph_Distance2Color.hpp" |
| 17 |
|
| 18 |
#include <Xpetra_Matrix.hpp> |
| 19 |
#include <Galeri_XpetraParameters.hpp> |
| 20 |
#include <Galeri_XpetraProblemFactory.hpp> |
| 21 |
#include <Galeri_XpetraUtils.hpp> |
| 22 |
#include <Galeri_XpetraMaps.hpp> |
| 23 |
|
| 24 |
#include "MueLu_TestHelpers_kokkos.hpp" |
| 25 |
#include "MueLu_Version.hpp" |
| 26 |
|
| 27 |
#include "MueLu_Level.hpp" |
| 28 |
#include "MueLu_Aggregates.hpp" |
| 29 |
#include "MueLu_AggregationPhase1Algorithm.hpp" |
| 30 |
#include "MueLu_AggregationPhase2aAlgorithm.hpp" |
| 31 |
#include "MueLu_AggregationPhase2bAlgorithm.hpp" |
| 32 |
#include "MueLu_AggregationPhase3Algorithm.hpp" |
| 33 |
#include "MueLu_AmalgamationInfo.hpp" |
| 34 |
#include "MueLu_AmalgamationInfo.hpp" |
| 35 |
#include "MueLu_AmalgamationFactory.hpp" |
| 36 |
#include "MueLu_CoalesceDropFactory_kokkos.hpp" |
| 37 |
#include "MueLu_FactoryManagerBase.hpp" |
| 38 |
#include "MueLu_UncoupledAggregationFactory.hpp" |
| 39 |
|
| 40 |
//#include "MueLu_UseDefaultTypes.hpp" |
| 41 |
|
| 42 |
namespace MueLuTests { |
| 43 |
|
| 44 |
// Little utility to generate uncoupled aggregates. |
| 45 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 46 |
void gimmeUncoupledAggregates(const Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& A, |
| 47 |
RCP<MueLu::LWGraph_kokkos<LocalOrdinal, GlobalOrdinal, Node>>& graph, |
| 48 |
Teuchos::RCP<MueLu::Aggregates<LocalOrdinal, GlobalOrdinal, Node>>& aggregates, |
| 49 |
bool bPhase1 = true, bool bPhase2a = true, bool bPhase2b = true, bool bPhase3 = true) { |
| 50 |
#include "MueLu_UseShortNames.hpp" |
| 51 |
Level level; |
| 52 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 53 |
level.Set("A", A); |
| 54 |
|
| 55 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 56 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 57 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 58 |
|
| 59 |
level.Request("Graph", dropFact.get()); |
| 60 |
level.Request(*dropFact); |
| 61 |
dropFact->Build(level); |
| 62 |
graph = level.Get<RCP<LWGraph_kokkos>>("Graph", dropFact.get()); |
| 63 |
const LO numNodes = graph->GetNodeNumVertices(); |
| 64 |
aggregates = rcp(new Aggregates(*graph)); |
| 65 |
aggregates->setObjectLabel("UC"); |
| 66 |
|
| 67 |
using graph_t = typename LWGraph_kokkos::local_graph_type; |
| 68 |
using device_type = typename graph_t::device_type; |
| 69 |
using KernelHandle = KokkosKernels::Experimental:: |
| 70 |
KokkosKernelsHandle<typename graph_t::row_map_type::value_type, |
| 71 |
typename graph_t::entries_type::value_type, |
| 72 |
typename graph_t::entries_type::value_type, |
| 73 |
typename graph_t::device_type::execution_space, |
| 74 |
typename graph_t::device_type::memory_space, |
| 75 |
typename graph_t::device_type::memory_space>; |
| 76 |
KernelHandle kh; |
| 77 |
// Leave gc algorithm choice as the default: |
| 78 |
// COLORING_D2_SERIAL for Serial execspace, and COLORING_D2_NB_BIT otherwise. |
| 79 |
kh.create_distance2_graph_coloring_handle(); |
| 80 |
|
| 81 |
// get the distance-2 graph coloring handle |
| 82 |
auto coloringHandle = kh.get_distance2_graph_coloring_handle(); |
| 83 |
|
| 84 |
// Create device views for graph rowptrs/colinds |
| 85 |
typename graph_t::row_map_type aRowptrs = graph->getRowPtrs(); |
| 86 |
typename graph_t::entries_type aColinds = graph->getEntries(); |
| 87 |
|
| 88 |
// run d2 graph coloring |
| 89 |
// graph is symmetric so row map/entries and col map/entries are the same |
| 90 |
KokkosGraph::Experimental::graph_color_distance2(&kh, numNodes, aRowptrs, aColinds); |
| 91 |
|
| 92 |
// extract the colors and store them in the aggregates |
| 93 |
aggregates->SetGraphColors(coloringHandle->get_vertex_colors()); |
| 94 |
aggregates->SetGraphNumColors(static_cast<LO>(coloringHandle->get_num_colors())); |
| 95 |
|
| 96 |
LO numNonAggregatedNodes = 0; |
| 97 |
Kokkos::View<unsigned*, device_type> aggStat("aggStat", numNodes); |
| 98 |
Kokkos::deep_copy(aggStat, MueLu::READY); |
| 99 |
Teuchos::ParameterList params; |
| 100 |
params.set<int>("aggregation: min agg size", 1); |
| 101 |
params.set<int>("aggregation: max agg size", 3); |
| 102 |
params.set<bool>("aggregation: deterministic", false); |
| 103 |
|
| 104 |
params.set<bool>("aggregation: match ML phase2a", true); |
| 105 |
params.set<bool>("aggregation: match ML phase2b", false); |
| 106 |
params.set<bool>("aggregation: error on nodes with no on-rank neighbors", false); |
| 107 |
params.set<bool>("aggregation: phase3 avoid singletons", false); |
| 108 |
|
| 109 |
if (bPhase1) { |
| 110 |
RCP<MueLu::AggregationAlgorithmBase<LO, GO, NO>> phase1 = rcp(new AggregationPhase1Algorithm(dropFact)); |
| 111 |
phase1->BuildAggregates(params, *graph, *aggregates, aggStat, numNonAggregatedNodes); |
| 112 |
} |
| 113 |
if (bPhase2a) { |
| 114 |
RCP<MueLu::AggregationAlgorithmBase<LO, GO, NO>> phase2a = rcp(new AggregationPhase2aAlgorithm(dropFact)); |
| 115 |
phase2a->BuildAggregates(params, *graph, *aggregates, aggStat, numNonAggregatedNodes); |
| 116 |
} |
| 117 |
if (bPhase2b) { |
| 118 |
RCP<MueLu::AggregationAlgorithmBase<LO, GO, NO>> phase2b = rcp(new AggregationPhase2bAlgorithm(dropFact)); |
| 119 |
phase2b->BuildAggregates(params, *graph, *aggregates, aggStat, numNonAggregatedNodes); |
| 120 |
} |
| 121 |
if (bPhase3) { |
| 122 |
RCP<MueLu::AggregationAlgorithmBase<LO, GO, NO>> phase3 = rcp(new AggregationPhase3Algorithm(dropFact)); |
| 123 |
phase3->BuildAggregates(params, *graph, *aggregates, aggStat, numNonAggregatedNodes); |
| 124 |
} |
| 125 |
aggregates->AggregatesCrossProcessors(false); |
| 126 |
aggregates->ComputeAggregateSizes(true /*forceRecompute*/); |
| 127 |
level.Release("Graph", dropFact.get()); |
| 128 |
} |
| 129 |
|
| 130 |
// Little utility to generate uncoupled aggregates. |
| 131 |
template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node> |
| 132 |
Teuchos::RCP<MueLu::Aggregates<LocalOrdinal, GlobalOrdinal, Node>> |
| 133 |
gimmeUncoupledAggregates(const Teuchos::RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>& A, |
| 134 |
bool bPhase1 = true, bool bPhase2a = true, bool bPhase2b = true, bool bPhase3 = true) { |
| 135 |
#include "MueLu_UseShortNames.hpp" |
| 136 |
RCP<LWGraph_kokkos> graph; |
| 137 |
RCP<Aggregates> aggregates; |
| 138 |
|
| 139 |
gimmeUncoupledAggregates(A, graph, aggregates, bPhase1, bPhase2a, bPhase2b, bPhase3); |
| 140 |
|
| 141 |
return aggregates; |
| 142 |
} |
| 143 |
|
| 144 |
template <class LocalOrdinal, class GlobalOrdinal, class Node> |
| 145 |
LocalOrdinal checkAggregatesContiguous(MueLu::LWGraph_kokkos<LocalOrdinal, GlobalOrdinal, Node> graph, |
| 146 |
MueLu::Aggregates<LocalOrdinal, GlobalOrdinal, Node> aggregates) { |
| 147 |
using LO = LocalOrdinal; |
| 148 |
using GO = GlobalOrdinal; |
| 149 |
using Aggregates = MueLu::Aggregates<LO, GO, Node>; |
| 150 |
using LWGraph_kokkos = MueLu::LWGraph_kokkos<LO, GO, Node>; |
| 151 |
using execution_space = typename LWGraph_kokkos::execution_space; |
| 152 |
using memory_space = typename LWGraph_kokkos::memory_space; |
| 153 |
using device_type = typename LWGraph_kokkos::device_type; |
| 154 |
|
| 155 |
const LO numNodes = graph.GetNodeNumVertices(); |
| 156 |
auto vertex2AggId = aggregates.GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadOnly); |
| 157 |
auto aggSizes = aggregates.ComputeAggregateSizes(true); |
| 158 |
|
| 159 |
auto lclLWGraph = graph; |
| 160 |
|
| 161 |
Kokkos::View<LO*, device_type> discontiguousAggs("discontiguous aggregates", |
| 162 |
aggregates.GetNumAggregates()); |
| 163 |
Kokkos::parallel_for( |
| 164 |
"Mark discontiguous aggregates", |
| 165 |
Kokkos::RangePolicy<LO, execution_space>(0, numNodes), |
| 166 |
KOKKOS_LAMBDA(const LO nodeIdx) { |
| 167 |
const LO myAggId = vertex2AggId(nodeIdx, 0); |
| 168 |
// Check that the node is actually aggregated |
| 169 |
if (myAggId == -1) { |
| 170 |
return; |
| 171 |
} |
| 172 |
const LO myAggSize = aggSizes(myAggId); |
| 173 |
|
| 174 |
if (myAggSize == 1) { |
| 175 |
// Can't have a discontiguous singleton |
| 176 |
return; |
| 177 |
} else { |
| 178 |
auto neighbors = lclLWGraph.getNeighborVertices(nodeIdx); |
| 179 |
for (LO neigh = 0; neigh < neighbors.length; ++neigh) { |
| 180 |
const LO neighIdx = neighbors(neigh); |
| 181 |
const LO neighAggId = vertex2AggId(neighIdx, 0); |
| 182 |
if ((nodeIdx != neighIdx) && (neighAggId == myAggId)) { |
| 183 |
// This aggregate might be discontiguous |
| 184 |
// but at least not because of this node |
| 185 |
return; |
| 186 |
} |
| 187 |
} |
| 188 |
discontiguousAggs(myAggId) = 1; |
| 189 |
} |
| 190 |
}); |
| 191 |
|
| 192 |
LO numDiscontiguousAggregates = 0; |
| 193 |
Kokkos::parallel_reduce( |
| 194 |
"Count discontiguous aggregates", |
| 195 |
Kokkos::RangePolicy<LO, execution_space>(0, aggregates.GetNumAggregates()), |
| 196 |
KOKKOS_LAMBDA(const LO aggIdx, LO& numDiscontiguous) { |
| 197 |
if (discontiguousAggs(aggIdx) == 1) { |
| 198 |
++numDiscontiguous; |
| 199 |
} |
| 200 |
}, |
| 201 |
numDiscontiguousAggregates); |
| 202 |
|
| 203 |
return numDiscontiguousAggregates; |
| 204 |
} |
| 205 |
|
| 206 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustUncoupledAggregationFactory, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 207 |
#include "MueLu_UseShortNames.hpp" |
| 208 |
MUELU_TESTING_SET_OSTREAM; |
| 209 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 210 |
out << "version: " << MueLu::Version() << std::endl; |
| 211 |
|
| 212 |
// Setup aggregation factory (use default factory for graph) |
| 213 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 214 |
aggFact->SetOrdering("graph"); |
| 215 |
TEST_EQUALITY(aggFact->GetOrdering() == "graph", true); |
| 216 |
aggFact->SetOrdering("natural"); |
| 217 |
TEST_EQUALITY(aggFact->GetOrdering() == "natural", true); |
| 218 |
aggFact->SetOrdering("random"); |
| 219 |
TEST_EQUALITY(aggFact->GetOrdering() == "random", true); |
| 220 |
|
| 221 |
aggFact->SetMaxNeighAlreadySelected(12); |
| 222 |
TEST_EQUALITY(aggFact->GetMaxNeighAlreadySelected() == 12, true); |
| 223 |
|
| 224 |
aggFact->SetMaxNeighAlreadySelected(0); |
| 225 |
TEST_EQUALITY(aggFact->GetMaxNeighAlreadySelected() == 0, true); |
| 226 |
|
| 227 |
aggFact->SetMinNodesPerAggregate(0); |
| 228 |
TEST_EQUALITY(aggFact->GetMinNodesPerAggregate() == 0, true); |
| 229 |
|
| 230 |
aggFact->SetMinNodesPerAggregate(3); |
| 231 |
TEST_EQUALITY(aggFact->GetMinNodesPerAggregate() == 3, true); |
| 232 |
} |
| 233 |
|
| 234 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustUncoupledAggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 235 |
#include "MueLu_UseShortNames.hpp" |
| 236 |
MUELU_TESTING_SET_OSTREAM; |
| 237 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 238 |
out << "version: " << MueLu::Version() << std::endl; |
| 239 |
|
| 240 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 241 |
|
| 242 |
RCP<Aggregates> aggregates = gimmeUncoupledAggregates(A); |
| 243 |
|
| 244 |
TEST_EQUALITY(aggregates != Teuchos::null, true); |
| 245 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 246 |
} |
| 247 |
|
| 248 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustDist2UncoupledAggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 249 |
// TODO bmk: A lot of test code duplicated here from gimmeUncoupledAggregates |
| 250 |
// because it can't take a custom parameter list, add that as parameter? |
| 251 |
#include <MueLu_UseShortNames.hpp> |
| 252 |
MUELU_TESTING_SET_OSTREAM; |
| 253 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 254 |
out << "version: " << MueLu::Version() << std::endl; |
| 255 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 256 |
RCP<AmalgamationInfo> amalgInfo; |
| 257 |
Level level; |
| 258 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 259 |
level.Set("A", A); |
| 260 |
|
| 261 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 262 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 263 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 264 |
|
| 265 |
// Setup aggregation factory (use default factory for graph) |
| 266 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 267 |
aggFact->SetFactory("Graph", dropFact); |
| 268 |
aggFact->SetParameter("aggregation: max agg size", Teuchos::ParameterEntry(3)); |
| 269 |
aggFact->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(3)); |
| 270 |
aggFact->SetParameter("aggregation: max selected neighbors", Teuchos::ParameterEntry(0)); |
| 271 |
aggFact->SetParameter("aggregation: preserve Dirichlet points", Teuchos::ParameterEntry(true)); |
| 272 |
aggFact->SetParameter("aggregation: enable phase 1", Teuchos::ParameterEntry(true)); |
| 273 |
aggFact->SetParameter("aggregation: enable phase 2a", Teuchos::ParameterEntry(true)); |
| 274 |
aggFact->SetParameter("aggregation: enable phase 2b", Teuchos::ParameterEntry(true)); |
| 275 |
aggFact->SetParameter("aggregation: enable phase 3", Teuchos::ParameterEntry(true)); |
| 276 |
|
| 277 |
level.Request("Aggregates", aggFact.get()); |
| 278 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 279 |
|
| 280 |
level.Request(*aggFact); |
| 281 |
aggFact->Build(level); |
| 282 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); // fix me |
| 283 |
TEST_INEQUALITY(aggregates, Teuchos::null); |
| 284 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 285 |
amalgInfo = level.Get<RCP<AmalgamationInfo>>("UnAmalgamationInfo", amalgFact.get()); // fix me |
| 286 |
level.Release("UnAmalgamationInfo", amalgFact.get()); |
| 287 |
level.Release("Aggregates", aggFact.get()); |
| 288 |
} |
| 289 |
|
| 290 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustDist2PreserveUncoupledAggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 291 |
// TODO bmk: A lot of test code duplicated here from gimmeUncoupledAggregates |
| 292 |
// because it can't take a custom parameter list, add that as parameter? |
| 293 |
#include <MueLu_UseShortNames.hpp> |
| 294 |
MUELU_TESTING_SET_OSTREAM; |
| 295 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 296 |
out << "version: " << MueLu::Version() << std::endl; |
| 297 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 298 |
RCP<AmalgamationInfo> amalgInfo; |
| 299 |
Level level; |
| 300 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 301 |
level.Set("A", A); |
| 302 |
|
| 303 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 304 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 305 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 306 |
|
| 307 |
// Setup aggregation factory (use default factory for graph) |
| 308 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 309 |
aggFact->SetFactory("Graph", dropFact); |
| 310 |
aggFact->SetParameter("aggregation: max agg size", Teuchos::ParameterEntry(3)); |
| 311 |
aggFact->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(3)); |
| 312 |
aggFact->SetParameter("aggregation: max selected neighbors", Teuchos::ParameterEntry(0)); |
| 313 |
aggFact->SetParameter("aggregation: enable phase 1", Teuchos::ParameterEntry(true)); |
| 314 |
aggFact->SetParameter("aggregation: enable phase 2a", Teuchos::ParameterEntry(true)); |
| 315 |
aggFact->SetParameter("aggregation: enable phase 2b", Teuchos::ParameterEntry(true)); |
| 316 |
aggFact->SetParameter("aggregation: enable phase 3", Teuchos::ParameterEntry(true)); |
| 317 |
|
| 318 |
level.Request("Aggregates", aggFact.get()); |
| 319 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 320 |
|
| 321 |
level.Request(*aggFact); |
| 322 |
aggFact->Build(level); |
| 323 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); // fix me |
| 324 |
TEST_INEQUALITY(aggregates, Teuchos::null); |
| 325 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 326 |
amalgInfo = level.Get<RCP<AmalgamationInfo>>("UnAmalgamationInfo", amalgFact.get()); // fix me |
| 327 |
level.Release("UnAmalgamationInfo", amalgFact.get()); |
| 328 |
level.Release("Aggregates", aggFact.get()); |
| 329 |
} |
| 330 |
|
| 331 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustOnePt2UncoupledAggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 332 |
// TODO bmk: A lot of test code duplicated here from gimmeUncoupledAggregates |
| 333 |
// because it can't take a custom parameter list, add that as parameter? |
| 334 |
#include <MueLu_UseShortNames.hpp> |
| 335 |
MUELU_TESTING_SET_OSTREAM; |
| 336 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 337 |
out << "version: " << MueLu::Version() << std::endl; |
| 338 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 339 |
RCP<AmalgamationInfo> amalgInfo; |
| 340 |
Level level; |
| 341 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 342 |
level.Set("A", A); |
| 343 |
|
| 344 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 345 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 346 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 347 |
|
| 348 |
// Setup aggregation factory (use default factory for graph) |
| 349 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 350 |
aggFact->SetFactory("Graph", dropFact); |
| 351 |
aggFact->SetParameter("aggregation: max agg size", Teuchos::ParameterEntry(3)); |
| 352 |
aggFact->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(3)); |
| 353 |
aggFact->SetParameter("aggregation: max selected neighbors", Teuchos::ParameterEntry(0)); |
| 354 |
aggFact->SetParameter("aggregation: allow user-specified singletons", Teuchos::ParameterEntry(true)); |
| 355 |
aggFact->SetParameter("aggregation: enable phase 1", Teuchos::ParameterEntry(true)); |
| 356 |
aggFact->SetParameter("aggregation: enable phase 2a", Teuchos::ParameterEntry(true)); |
| 357 |
aggFact->SetParameter("aggregation: enable phase 2b", Teuchos::ParameterEntry(true)); |
| 358 |
aggFact->SetParameter("aggregation: enable phase 3", Teuchos::ParameterEntry(true)); |
| 359 |
|
| 360 |
level.Request("Aggregates", aggFact.get()); |
| 361 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 362 |
|
| 363 |
level.Request(*aggFact); |
| 364 |
aggFact->Build(level); |
| 365 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); // fix me |
| 366 |
TEST_INEQUALITY(aggregates, Teuchos::null); |
| 367 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 368 |
amalgInfo = level.Get<RCP<AmalgamationInfo>>("UnAmalgamationInfo", amalgFact.get()); // fix me |
| 369 |
level.Release("UnAmalgamationInfo", amalgFact.get()); |
| 370 |
level.Release("Aggregates", aggFact.get()); |
| 371 |
} |
| 372 |
|
| 373 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, JustDist2DeterUncoupledAggregation, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 374 |
// TODO bmk: A lot of test code duplicated here from gimmeUncoupledAggregates |
| 375 |
// because it can't take a custom parameter list, add that as parameter? |
| 376 |
#include <MueLu_UseShortNames.hpp> |
| 377 |
MUELU_TESTING_SET_OSTREAM; |
| 378 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 379 |
out << "version: " << MueLu::Version() << std::endl; |
| 380 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 381 |
RCP<AmalgamationInfo> amalgInfo; |
| 382 |
Level level; |
| 383 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 384 |
level.Set("A", A); |
| 385 |
|
| 386 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 387 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 388 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 389 |
|
| 390 |
// Setup aggregation factory (use default factory for graph) |
| 391 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 392 |
aggFact->SetFactory("Graph", dropFact); |
| 393 |
aggFact->SetParameter("aggregation: max agg size", Teuchos::ParameterEntry(3)); |
| 394 |
aggFact->SetParameter("aggregation: min agg size", Teuchos::ParameterEntry(3)); |
| 395 |
aggFact->SetParameter("aggregation: max selected neighbors", Teuchos::ParameterEntry(0)); |
| 396 |
aggFact->SetParameter("aggregation: deterministic", Teuchos::ParameterEntry(true)); |
| 397 |
aggFact->SetParameter("aggregation: enable phase 1", Teuchos::ParameterEntry(true)); |
| 398 |
aggFact->SetParameter("aggregation: enable phase 2a", Teuchos::ParameterEntry(true)); |
| 399 |
aggFact->SetParameter("aggregation: enable phase 2b", Teuchos::ParameterEntry(true)); |
| 400 |
aggFact->SetParameter("aggregation: enable phase 3", Teuchos::ParameterEntry(true)); |
| 401 |
|
| 402 |
level.Request("Aggregates", aggFact.get()); |
| 403 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 404 |
|
| 405 |
level.Request(*aggFact); |
| 406 |
|
| 407 |
// Set some node to ONEPT state |
| 408 |
|
| 409 |
aggFact->Build(level); |
| 410 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); // fix me |
| 411 |
TEST_INEQUALITY(aggregates, Teuchos::null); |
| 412 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 413 |
amalgInfo = level.Get<RCP<AmalgamationInfo>>("UnAmalgamationInfo", amalgFact.get()); // fix me |
| 414 |
level.Release("UnAmalgamationInfo", amalgFact.get()); |
| 415 |
level.Release("Aggregates", aggFact.get()); |
| 416 |
} |
| 417 |
|
| 418 |
// A test that creates discontiguous aggregates to make sure the detection algorithm works well |
| 419 |
/// pretty much testing the test... |
| 420 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, DiscontiguousAggregates, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 421 |
#include "MueLu_UseShortNames.hpp" |
| 422 |
MUELU_TESTING_SET_OSTREAM; |
| 423 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 424 |
out << "version: " << MueLu::Version() << std::endl; |
| 425 |
|
| 426 |
using device_type = typename Aggregates::device_type; |
| 427 |
using memory_space = typename device_type::memory_space; |
| 428 |
|
| 429 |
RCP<const Teuchos::Comm<int>> comm = TestHelpers_kokkos::Parameters::getDefaultComm(); |
| 430 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(3 * comm->getSize()); |
| 431 |
Level level; |
| 432 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 433 |
level.Set("A", A); |
| 434 |
|
| 435 |
RCP<Aggregates> aggregates; |
| 436 |
RCP<LWGraph_kokkos> graph; |
| 437 |
|
| 438 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 439 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 440 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 441 |
|
| 442 |
level.Request("Graph", dropFact.get()); |
| 443 |
level.Request(*dropFact); |
| 444 |
dropFact->Build(level); |
| 445 |
graph = level.Get<RCP<LWGraph_kokkos>>("Graph", dropFact.get()); |
| 446 |
RCP<const Map> importMap = graph->GetImportMap(); |
| 447 |
const LO numNodes = graph->GetNodeNumVertices(); |
| 448 |
aggregates = rcp(new Aggregates(*graph)); |
| 449 |
aggregates->setObjectLabel("UC"); |
| 450 |
|
| 451 |
Kokkos::View<unsigned*, device_type> aggStat("aggStat", numNodes); |
| 452 |
Kokkos::deep_copy(aggStat, MueLu::READY); |
| 453 |
|
| 454 |
// Performing fake aggregates to generate a discontiguous aggregate |
| 455 |
Kokkos::View<LO**, Kokkos::LayoutLeft, device_type> vertex2AggId = aggregates->GetVertex2AggId()->getDeviceLocalView(Xpetra::Access::ReadWrite); |
| 456 |
Kokkos::View<LO**, Kokkos::LayoutLeft, device_type> procWinner = aggregates->GetProcWinner()->getDeviceLocalView(Xpetra::Access::ReadWrite); |
| 457 |
|
| 458 |
typename Kokkos::View<LO**, Kokkos::LayoutLeft, device_type>::HostMirror vertex2AggId_h = Kokkos::create_mirror_view(vertex2AggId); |
| 459 |
Kokkos::deep_copy(vertex2AggId_h, vertex2AggId); |
| 460 |
vertex2AggId_h(0, 0) = 0; |
| 461 |
vertex2AggId_h(1, 0) = 1; |
| 462 |
vertex2AggId_h(2, 0) = 0; |
| 463 |
Kokkos::deep_copy(vertex2AggId, vertex2AggId_h); |
| 464 |
|
| 465 |
typename Kokkos::View<LO**, Kokkos::LayoutLeft, device_type>::HostMirror procWinner_h = Kokkos::create_mirror_view(procWinner); |
| 466 |
Kokkos::deep_copy(procWinner_h, procWinner); |
| 467 |
procWinner_h(0, 0) = comm->getRank(); |
| 468 |
procWinner_h(1, 0) = comm->getRank(); |
| 469 |
procWinner_h(2, 0) = comm->getRank(); |
| 470 |
Kokkos::deep_copy(procWinner, procWinner_h); |
| 471 |
|
| 472 |
aggregates->SetNumAggregates(2); |
| 473 |
aggregates->AggregatesCrossProcessors(false); |
| 474 |
aggregates->ComputeAggregateSizes(true); |
| 475 |
|
| 476 |
const LO numDiscontiguous = checkAggregatesContiguous(*graph, *aggregates); |
| 477 |
TEST_EQUALITY(numDiscontiguous, 1); |
| 478 |
} // UncoupledPhase1 |
| 479 |
|
| 480 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, UncoupledPhase1, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 481 |
#include "MueLu_UseShortNames.hpp" |
| 482 |
MUELU_TESTING_SET_OSTREAM; |
| 483 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 484 |
out << "version: " << MueLu::Version() << std::endl; |
| 485 |
|
| 486 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36); |
| 487 |
RCP<AmalgamationInfo> amalgInfo; |
| 488 |
|
| 489 |
RCP<Aggregates> aggregates; |
| 490 |
RCP<LWGraph_kokkos> graph; |
| 491 |
gimmeUncoupledAggregates(A, graph, aggregates, true, false, false, false); |
| 492 |
const GO numAggs = aggregates->GetNumAggregates(); |
| 493 |
|
| 494 |
TEST_INEQUALITY(numAggs, 0); |
| 495 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 496 |
|
| 497 |
typename Aggregates::aggregates_sizes_type::const_type aggSizes = aggregates->ComputeAggregateSizes(true); |
| 498 |
|
| 499 |
LO numBadAggregates = 0; |
| 500 |
Kokkos::parallel_reduce( |
| 501 |
"Checking aggregates sizes", |
| 502 |
Kokkos::RangePolicy<LO, typename Aggregates::execution_space>(0, aggSizes.extent(0)), |
| 503 |
KOKKOS_LAMBDA(const LO aggIdx, LO& lNumBadAggregates) { |
| 504 |
if ((aggSizes(aggIdx) < 1) || (3 < aggSizes(aggIdx))) { |
| 505 |
lNumBadAggregates += 1; |
| 506 |
} |
| 507 |
}, |
| 508 |
numBadAggregates); |
| 509 |
TEST_EQUALITY(numBadAggregates, 0); |
| 510 |
|
| 511 |
const LO numDiscontiguous = checkAggregatesContiguous(*graph, *aggregates); |
| 512 |
TEST_EQUALITY(numDiscontiguous, 0); |
| 513 |
} // UncoupledPhase1 |
| 514 |
|
| 515 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, UncoupledPhase2, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 516 |
#include "MueLu_UseShortNames.hpp" |
| 517 |
MUELU_TESTING_SET_OSTREAM; |
| 518 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 519 |
out << "version: " << MueLu::Version() << std::endl; |
| 520 |
|
| 521 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36); |
| 522 |
|
| 523 |
RCP<LWGraph_kokkos> graph; |
| 524 |
RCP<Aggregates> aggregates; |
| 525 |
gimmeUncoupledAggregates(A, graph, aggregates, false, true, true, false); |
| 526 |
GO numAggs = aggregates->GetNumAggregates(); |
| 527 |
|
| 528 |
TEST_INEQUALITY(numAggs, 0); |
| 529 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 530 |
|
| 531 |
const LO numDiscontiguous = checkAggregatesContiguous(*graph, *aggregates); |
| 532 |
TEST_EQUALITY(numDiscontiguous, 0); |
| 533 |
} // UncoupledPhase2 |
| 534 |
|
| 535 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, UncoupledPhase3, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 536 |
#include "MueLu_UseShortNames.hpp" |
| 537 |
MUELU_TESTING_SET_OSTREAM; |
| 538 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO); |
| 539 |
out << "version: " << MueLu::Version() << std::endl; |
| 540 |
|
| 541 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36); |
| 542 |
RCP<AmalgamationInfo> amalgInfo; |
| 543 |
|
| 544 |
RCP<Aggregates> aggregates = gimmeUncoupledAggregates(A, false, false, false, true); |
| 545 |
GO numAggs = aggregates->GetNumAggregates(); |
| 546 |
|
| 547 |
TEST_INEQUALITY(numAggs, 0); |
| 548 |
TEST_EQUALITY(aggregates->AggregatesCrossProcessors(), false); |
| 549 |
|
| 550 |
typename Aggregates::aggregates_sizes_type::const_type aggSizes = aggregates->ComputeAggregateSizes(true); |
| 551 |
|
| 552 |
LO numBadAggregates = 0; |
| 553 |
Kokkos::parallel_reduce( |
| 554 |
"Checking aggregates sizes", |
| 555 |
Kokkos::RangePolicy<LO, typename Aggregates::execution_space>(0, aggSizes.extent(0)), |
| 556 |
KOKKOS_LAMBDA(const LO aggIdx, LO& lNumBadAggregates) { |
| 557 |
if ((aggSizes(aggIdx) < 1) || (5 < aggSizes(aggIdx))) { |
| 558 |
lNumBadAggregates += 1; |
| 559 |
} |
| 560 |
}, |
| 561 |
numBadAggregates); |
| 562 |
TEST_EQUALITY(numBadAggregates, 0); |
| 563 |
|
| 564 |
// Check ComputeNodesInAggregate |
| 565 |
typename Aggregates::LO_view aggPtr, aggNodes, unaggregated; |
| 566 |
aggregates->ComputeNodesInAggregate(aggPtr, aggNodes, unaggregated); |
| 567 |
TEST_EQUALITY(aggPtr.extent_int(0), numAggs + 1); |
| 568 |
// TEST_EQUALITY(unaggregated.extent_int(0), 0); // 1 unaggregated node in the MPI_4 case |
| 569 |
|
| 570 |
// test aggPtr(i)+aggSizes(i)=aggPtr(i+1) |
| 571 |
typename Aggregates::LO_view::HostMirror aggPtr_h = Kokkos::create_mirror_view(aggPtr); |
| 572 |
typename Aggregates::aggregates_sizes_type::HostMirror aggSizes_h = Kokkos::create_mirror_view(aggSizes); |
| 573 |
Kokkos::deep_copy(aggPtr_h, aggPtr); |
| 574 |
Kokkos::deep_copy(aggSizes_h, aggSizes); |
| 575 |
for (LO i = 0; i < aggSizes_h.extent_int(0); ++i) |
| 576 |
TEST_EQUALITY(aggPtr_h(i) + aggSizes_h(i), aggPtr_h(i + 1)); |
| 577 |
|
| 578 |
} // UncoupledPhase3 |
| 579 |
|
| 580 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, AllowDroppingToCreateAdditionalDirichletRows, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 581 |
#include <MueLu_UseShortNames.hpp> |
| 582 |
MUELU_TESTING_SET_OSTREAM |
| 583 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 584 |
out << "version: " << MueLu::Version() << std::endl; |
| 585 |
out << "Test option that allows dropping during aggregation to create new Dirichlet rows" << std::endl; |
| 586 |
|
| 587 |
typedef typename Teuchos::ScalarTraits<Scalar> TST; |
| 588 |
using device_type = typename Aggregates::device_type; |
| 589 |
|
| 590 |
RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(15); |
| 591 |
A->resumeFill(); |
| 592 |
|
| 593 |
// Create one row on every processor with small off-diagonal entries that will be dropped with |
| 594 |
// an appropriately chosen threshold. Avoid domain boundaries. |
| 595 |
LocalOrdinal localRowToModify = 1; |
| 596 |
Teuchos::ArrayView<const LocalOrdinal> indices; |
| 597 |
Teuchos::ArrayView<const Scalar> values; |
| 598 |
A->getLocalRowView(localRowToModify, indices, values); |
| 599 |
Array<Scalar> newvalues(values.size(), TST::zero()); |
| 600 |
for (int j = 0; j < indices.size(); j++) { |
| 601 |
if (indices[j] == localRowToModify) |
| 602 |
newvalues[j] = values[j]; // keep diagonal unmodified |
| 603 |
else |
| 604 |
newvalues[j] = -TST::eps(); |
| 605 |
} |
| 606 |
A->replaceLocalValues(localRowToModify, indices, newvalues); |
| 607 |
A->fillComplete(); |
| 608 |
|
| 609 |
// Dropping connections will not lead to the creation of new Dirichlet rows. |
| 610 |
RCP<AmalgamationInfo> amalgInfo; |
| 611 |
Level level; |
| 612 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 613 |
level.Set("A", A); |
| 614 |
|
| 615 |
RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 616 |
dropFact->SetParameter("aggregation: dropping may create Dirichlet", Teuchos::ParameterEntry(false)); |
| 617 |
dropFact->SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(Teuchos::as<double>(-100 * TST::eps()))); |
| 618 |
RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory()); |
| 619 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 620 |
level.Request("Graph", dropFact.get()); |
| 621 |
|
| 622 |
// Setup aggregation factory (use default factory for graph) |
| 623 |
RCP<UncoupledAggregationFactory> aggFact = rcp(new UncoupledAggregationFactory()); |
| 624 |
aggFact->SetFactory("Graph", dropFact); |
| 625 |
|
| 626 |
level.Request("Aggregates", aggFact.get()); |
| 627 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 628 |
|
| 629 |
level.Request(*aggFact); |
| 630 |
aggFact->Build(level); |
| 631 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); |
| 632 |
RCP<LWGraph_kokkos> graph = level.Get<RCP<LWGraph_kokkos>>("Graph", dropFact.get()); |
| 633 |
Kokkos::View<const bool*, device_type> dirichletBoundaryMap = graph->GetBoundaryNodeMap(); |
| 634 |
int numDirichletRows = 0; |
| 635 |
using execution_space = typename LWGraph_kokkos::execution_space; |
| 636 |
LO numRows = graph->GetNodeNumVertices(); |
| 637 |
Kokkos::parallel_reduce( |
| 638 |
"Count Dirichlet rows", |
| 639 |
Kokkos::RangePolicy<LO, execution_space>(0, numRows), |
| 640 |
KOKKOS_LAMBDA(const LO rowIdx, LO& numDirichlet) { |
| 641 |
if (dirichletBoundaryMap[rowIdx]) { |
| 642 |
++numDirichlet; |
| 643 |
} |
| 644 |
}, |
| 645 |
numDirichletRows); |
| 646 |
TEST_EQUALITY(numDirichletRows, 0); |
| 647 |
|
| 648 |
Array<LO> aggPtr; |
| 649 |
Array<LO> aggNodes; |
| 650 |
Array<LO> unaggregated; |
| 651 |
|
| 652 |
// Repeat with "aggregation: dropping may create Dirichlet" = TRUE, i.e., |
| 653 |
// dropping connections may lead to the creation of new Dirichlet rows. |
| 654 |
// The second row should be flagged as Dirichlet because all off-diagonal entries are dropped. |
| 655 |
amalgFact = rcp(new AmalgamationFactory()); |
| 656 |
dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 657 |
dropFact->SetParameter("aggregation: dropping may create Dirichlet", Teuchos::ParameterEntry(true)); |
| 658 |
dropFact->SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(Teuchos::as<double>(-100 * TST::eps()))); |
| 659 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 660 |
level.Request("Graph", dropFact.get()); |
| 661 |
|
| 662 |
// Setup aggregation factory (use default factory for graph) |
| 663 |
aggFact = rcp(new UncoupledAggregationFactory()); |
| 664 |
aggFact->SetFactory("Graph", dropFact); |
| 665 |
|
| 666 |
level.Request("Aggregates", aggFact.get()); |
| 667 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 668 |
|
| 669 |
level.Request(*aggFact); |
| 670 |
aggFact->Build(level); |
| 671 |
aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); |
| 672 |
graph = level.Get<RCP<LWGraph_kokkos>>("Graph", dropFact.get()); |
| 673 |
dirichletBoundaryMap = graph->GetBoundaryNodeMap(); |
| 674 |
numDirichletRows = 0; |
| 675 |
Kokkos::parallel_reduce( |
| 676 |
"Count Dirichlet rows", |
| 677 |
Kokkos::RangePolicy<LO, execution_space>(0, numRows), |
| 678 |
KOKKOS_LAMBDA(const LO rowIdx, LO& numDirichlet) { |
| 679 |
if (dirichletBoundaryMap[rowIdx]) { |
| 680 |
++numDirichlet; |
| 681 |
} |
| 682 |
}, |
| 683 |
numDirichletRows); |
| 684 |
TEST_EQUALITY(numDirichletRows, 1); |
| 685 |
|
| 686 |
} // AllowDroppingToCreateAdditionalDirichletRows |
| 687 |
|
| 688 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(Aggregates_kokkos, GreedyDirichlet, Scalar, LocalOrdinal, GlobalOrdinal, Node) { |
| 689 |
#include <MueLu_UseShortNames.hpp> |
| 690 |
MUELU_TESTING_SET_OSTREAM |
| 691 |
MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node); |
| 692 |
out << "version: " << MueLu::Version() << std::endl; |
| 693 |
out << "running greedy Dirichlet" << std::endl; |
| 694 |
|
| 695 |
typedef typename Teuchos::ScalarTraits<Scalar> TST; |
| 696 |
|
| 697 |
// RCP<Matrix> A = TestHelpers::TestFactory<SC, LO, GO, NO>::Build1DPoisson(30); |
| 698 |
// Make a Matrix with multiple degrees of freedom per node |
| 699 |
GlobalOrdinal nx = 8, ny = 8; |
| 700 |
|
| 701 |
// Describes the initial layout of matrix rows across processors. |
| 702 |
Teuchos::ParameterList galeriList; |
| 703 |
galeriList.set("nx", nx); |
| 704 |
galeriList.set("ny", ny); |
| 705 |
RCP<const Teuchos::Comm<int>> comm = TestHelpers_kokkos::Parameters::getDefaultComm(); |
| 706 |
RCP<const Map> map = Galeri::Xpetra::CreateMap<LocalOrdinal, GlobalOrdinal, Node>(TestHelpers_kokkos::Parameters::getLib(), "Cartesian2D", comm, galeriList); |
| 707 |
|
| 708 |
map = Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(map, 2); // expand map for 2 DOFs per node |
| 709 |
|
| 710 |
RCP<Galeri::Xpetra::Problem<Map, CrsMatrixWrap, MultiVector>> Pr = |
| 711 |
Galeri::Xpetra::BuildProblem<Scalar, LocalOrdinal, GlobalOrdinal, Map, CrsMatrixWrap, MultiVector>("Elasticity2D", map, galeriList); |
| 712 |
RCP<Matrix> A = Pr->BuildMatrix(); |
| 713 |
A->SetFixedBlockSize(2); |
| 714 |
|
| 715 |
Teuchos::ArrayView<const LocalOrdinal> indices; |
| 716 |
Teuchos::ArrayView<const Scalar> values; |
| 717 |
|
| 718 |
// Create a dirichlet boundary row. |
| 719 |
LocalOrdinal localRowToZero = 5; // Corresponds to a Dof on local graph node 2 |
| 720 |
|
| 721 |
A->resumeFill(); |
| 722 |
A->getLocalRowView(localRowToZero, indices, values); |
| 723 |
Array<Scalar> newvalues(values.size(), TST::zero()); |
| 724 |
for (int j = 0; j < indices.size(); j++) |
| 725 |
// keep diagonal |
| 726 |
if (indices[j] == localRowToZero) newvalues[j] = values[j]; |
| 727 |
A->replaceLocalValues(localRowToZero, indices, newvalues); |
| 728 |
|
| 729 |
A->fillComplete(); |
| 730 |
|
| 731 |
ArrayRCP<const bool> drows = Utilities::DetectDirichletRows(*A); |
| 732 |
TEST_EQUALITY(drows[localRowToZero], true); |
| 733 |
TEST_EQUALITY(drows[localRowToZero - 1], false); |
| 734 |
|
| 735 |
RCP<AmalgamationInfo> amalgInfo; |
| 736 |
Level level; |
| 737 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level); |
| 738 |
level.Set("A", A); |
| 739 |
|
| 740 |
RCP<CoalesceDropFactory_kokkos> dropFact; |
| 741 |
RCP<AmalgamationFactory> amalgFact; |
| 742 |
RCP<UncoupledAggregationFactory> aggFact; |
| 743 |
|
| 744 |
amalgFact = rcp(new AmalgamationFactory()); |
| 745 |
dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 746 |
dropFact->SetParameter("aggregation: greedy Dirichlet", Teuchos::ParameterEntry(false)); |
| 747 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 748 |
|
| 749 |
// Setup aggregation factory (use default factory for graph) |
| 750 |
aggFact = rcp(new UncoupledAggregationFactory()); |
| 751 |
aggFact->SetFactory("Graph", dropFact); |
| 752 |
|
| 753 |
level.Request("Aggregates", aggFact.get()); |
| 754 |
level.Request("UnAmalgamationInfo", amalgFact.get()); |
| 755 |
|
| 756 |
level.Request(*aggFact); |
| 757 |
aggFact->Build(level); |
| 758 |
RCP<Aggregates> aggregates = level.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); |
| 759 |
Array<LO> aggPtr; |
| 760 |
Array<LO> aggNodes; |
| 761 |
Array<LO> unaggregated; |
| 762 |
|
| 763 |
typename Aggregates::aggregates_sizes_type::const_type aggSizes = aggregates->ComputeAggregateSizes(true); |
| 764 |
|
| 765 |
auto vertex2AggId = aggregates->GetVertex2AggId()->getHostLocalView(Xpetra::Access::ReadOnly); |
| 766 |
for (auto i = 0; i < (nx / 2 * ny / 2); i++) { |
| 767 |
TEST_EQUALITY(vertex2AggId(i, 0) != MUELU_UNAGGREGATED, true); // check that all nodes are aggregated |
| 768 |
} |
| 769 |
|
| 770 |
// Repeat with greedy Dirichlet |
| 771 |
Level levelGreedyAndNoPreserve; |
| 772 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(levelGreedyAndNoPreserve); |
| 773 |
levelGreedyAndNoPreserve.Set("A", A); |
| 774 |
amalgFact = rcp(new AmalgamationFactory()); |
| 775 |
dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 776 |
dropFact->SetParameter("aggregation: greedy Dirichlet", Teuchos::ParameterEntry(true)); |
| 777 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 778 |
|
| 779 |
// Setup aggregation factory (use default factory for graph) |
| 780 |
aggFact = rcp(new UncoupledAggregationFactory()); |
| 781 |
aggFact->SetFactory("Graph", dropFact); |
| 782 |
|
| 783 |
levelGreedyAndNoPreserve.Request("Aggregates", aggFact.get()); |
| 784 |
levelGreedyAndNoPreserve.Request("UnAmalgamationInfo", amalgFact.get()); |
| 785 |
|
| 786 |
levelGreedyAndNoPreserve.Request(*aggFact); |
| 787 |
aggFact->Build(levelGreedyAndNoPreserve); |
| 788 |
aggregates = levelGreedyAndNoPreserve.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); |
| 789 |
aggFact->SetParameter("aggregation: preserve Dirichlet points", Teuchos::ParameterEntry(false)); |
| 790 |
|
| 791 |
typename Aggregates::aggregates_sizes_type::const_type aggSizesGreedy = aggregates->ComputeAggregateSizes(true); |
| 792 |
// There should be the same number of aggregates in the greedy dirichlet case as in the standard case |
| 793 |
// though note the aggregates will be smaller in the greedy dirirchlet case. |
| 794 |
// This may not be true for all problem setups, but is true for the setup in this test case. |
| 795 |
TEST_EQUALITY(aggSizesGreedy.extent(0) == aggSizes.extent(0), true) |
| 796 |
|
| 797 |
vertex2AggId = aggregates->GetVertex2AggId()->getHostLocalView(Xpetra::Access::ReadOnly); |
| 798 |
TEST_EQUALITY(vertex2AggId(2, 0) == MUELU_UNAGGREGATED, true); // check that the node with the Dof flagged as dirichlet is unaggregated |
| 799 |
|
| 800 |
// Repeat with greedy Dirichlet and preserve Dirichlet points |
| 801 |
Level levelGreedyAndPreserve; |
| 802 |
TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(levelGreedyAndPreserve); |
| 803 |
levelGreedyAndPreserve.Set("A", A); |
| 804 |
|
| 805 |
amalgFact = rcp(new AmalgamationFactory()); |
| 806 |
dropFact = rcp(new CoalesceDropFactory_kokkos()); |
| 807 |
dropFact->SetParameter("aggregation: greedy Dirichlet", Teuchos::ParameterEntry(true)); |
| 808 |
dropFact->SetFactory("UnAmalgamationInfo", amalgFact); |
| 809 |
|
| 810 |
// Setup aggregation factory (use default factory for graph) |
| 811 |
aggFact = rcp(new UncoupledAggregationFactory()); |
| 812 |
aggFact->SetFactory("Graph", dropFact); |
| 813 |
aggFact->SetParameter("aggregation: preserve Dirichlet points", Teuchos::ParameterEntry(true)); |
| 814 |
|
| 815 |
levelGreedyAndPreserve.Request("Aggregates", aggFact.get()); |
| 816 |
levelGreedyAndPreserve.Request("UnAmalgamationInfo", amalgFact.get()); |
| 817 |
|
| 818 |
levelGreedyAndPreserve.Request(*aggFact); |
| 819 |
aggFact->Build(levelGreedyAndPreserve); |
| 820 |
aggregates = levelGreedyAndPreserve.Get<RCP<Aggregates>>("Aggregates", aggFact.get()); |
| 821 |
|
| 822 |
typename Aggregates::aggregates_sizes_type::const_type aggSizesGreedyPreserve = aggregates->ComputeAggregateSizes(true); |
| 823 |
// check that dirichlet aggs are preserved |
| 824 |
// there should be more aggregates in the dirichlet preserved case than in the standard case. |
| 825 |
// This will always be true. |
| 826 |
TEST_EQUALITY(aggSizesGreedyPreserve.extent(0) > aggSizesGreedy.extent(0), true) |
| 827 |
|
| 828 |
vertex2AggId = aggregates->GetVertex2AggId()->getHostLocalView(Xpetra::Access::ReadOnly); |
| 829 |
for (auto i = 0; i < (nx / 2 * ny / 2); i++) { |
| 830 |
TEST_EQUALITY(vertex2AggId(i, 0) != MUELU_UNAGGREGATED, true); // check that all nodes are aggregated |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
#define MUELU_ETI_GROUP(SC, LO, GO, NO) \ |
| 835 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustUncoupledAggregationFactory, SC, LO, GO, NO) \ |
| 836 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustUncoupledAggregation, SC, LO, GO, NO) \ |
| 837 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustDist2UncoupledAggregation, SC, LO, GO, NO) \ |
| 838 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustDist2PreserveUncoupledAggregation, SC, LO, GO, NO) \ |
| 839 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustDist2DeterUncoupledAggregation, SC, LO, GO, NO) \ |
| 840 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, JustOnePt2UncoupledAggregation, SC, LO, GO, NO) \ |
| 841 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, DiscontiguousAggregates, SC, LO, GO, NO) \ |
| 842 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, UncoupledPhase1, SC, LO, GO, NO) \ |
| 843 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, UncoupledPhase2, SC, LO, GO, NO) \ |
| 844 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, UncoupledPhase3, SC, LO, GO, NO) \ |
| 845 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, AllowDroppingToCreateAdditionalDirichletRows, SC, LO, GO, NO) \ |
| 846 |
TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(Aggregates_kokkos, GreedyDirichlet, SC, LO, GO, NO) |
| 847 |
|
| 848 |
#include <MueLu_ETI_4arg.hpp> |
| 849 |
|
| 850 |
} // namespace MueLuTests |