Debian Codegraph @

packages/muelu/test/unit_tests_kokkos/CoalesceDropFactory_kokkos.cpp

raw
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 <ostream>
12
13 #include "MueLu_TestHelpers_kokkos.hpp"
14 #include "MueLu_Version.hpp"
15
16 #include <MueLu_InitialBlockNumberFactory.hpp>
17 #include "MueLu_CoalesceDropFactory.hpp"
18 #include "MueLu_FilteredAFactory.hpp"
19 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
20 #include "MueLu_AmalgamationFactory.hpp"
21 #include "MueLu_LWGraph_kokkos.hpp"
22
23 #include <Galeri_XpetraParameters.hpp>
24
25 namespace MueLuTests {
26
27 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
28 #include "MueLu_UseShortNames.hpp"
29 MUELU_TESTING_SET_OSTREAM;
30 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO);
31 out << "version: " << MueLu::Version() << std::endl;
32
33 RCP<CoalesceDropFactory_kokkos> coalesceDropFact = rcp(new CoalesceDropFactory_kokkos());
34 TEST_EQUALITY(coalesceDropFact != Teuchos::null, true);
35
36 out << *coalesceDropFact << std::endl;
37 }
38
39 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, Build, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
40 #include <MueLu_UseShortNames.hpp>
41 MUELU_TESTING_SET_OSTREAM;
42 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
43 out << "version: " << MueLu::Version() << std::endl;
44
45 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
46
47 Level fineLevel;
48 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
49
50 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
51 fineLevel.Set("A", A);
52
53 CoalesceDropFactory_kokkos coalesceDropFact;
54 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
55 fineLevel.Request("Graph", &coalesceDropFact);
56 fineLevel.Request("DofsPerNode", &coalesceDropFact);
57
58 coalesceDropFact.Build(fineLevel);
59
60 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
61 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
62 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
63
64 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
65 const RCP<const Map> myDomainMap = graph->GetDomainMap();
66
67 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
68 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
69 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
70 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
71
72 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
73 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
74 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
75 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
76 } // Build
77
78 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacian, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
79 #include <MueLu_UseShortNames.hpp>
80 typedef Teuchos::ScalarTraits<SC> STS;
81 typedef typename STS::magnitudeType real_type;
82 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
83
84 MUELU_TESTING_SET_OSTREAM;
85 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
86 out << "version: " << MueLu::Version() << std::endl;
87
88 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
89
90 Level fineLevel;
91 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
92
93 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
94 fineLevel.Set("A", A);
95
96 Teuchos::ParameterList galeriList;
97 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
98 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
99 fineLevel.Set("Coordinates", coordinates);
100
101 CoalesceDropFactory_kokkos coalesceDropFact;
102 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
103 // We're dropping all the interior off-diagonal entries.
104 // dx = 1/36
105 // L_ij = -36
106 // L_ii = 72
107 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
108 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
109 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
110 fineLevel.Request("Graph", &coalesceDropFact);
111 fineLevel.Request("DofsPerNode", &coalesceDropFact);
112
113 coalesceDropFact.Build(fineLevel);
114
115 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
116 auto graph = graph_d->copyToHost();
117 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
118 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
119
120 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
121 const RCP<const Map> myDomainMap = graph->GetDomainMap();
122
123 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
124 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
125 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
126 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
127
128 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
129 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
130 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
131 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
132
133 TEST_EQUALITY(graph->GetGlobalNumEdges(), 40);
134
135 } // DistanceLaplacian
136
137 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianScaledCut, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
138 #include <MueLu_UseShortNames.hpp>
139 typedef Teuchos::ScalarTraits<SC> STS;
140 typedef typename STS::magnitudeType real_type;
141 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
142
143 MUELU_TESTING_SET_OSTREAM;
144 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
145 out << "version: " << MueLu::Version() << std::endl;
146
147 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
148
149 Level fineLevel;
150 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
151
152 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
153 fineLevel.Set("A", A);
154
155 Teuchos::ParameterList galeriList;
156 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
157 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
158 // Now we doctor the coordinates so that the off-diagonal pair row 0 will want to keep (0,1) and row 1 will want to drop (1,0)
159 if (comm->getRank() == 0) {
160 auto vals = coordinates->getDataNonConst(0);
161 vals[0] = vals[0] - 2000 * 36;
162 }
163
164 fineLevel.Set("Coordinates", coordinates);
165
166 CoalesceDropFactory_kokkos coalesceDropFact;
167 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
168 // We're dropping all the interior off-diagonal entries.
169 // dx = 1/36
170 // L_ij = -36
171 // L_ii = 72
172 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
173 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 8.0));
174 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
175 coalesceDropFact.SetParameter("aggregation: distance laplacian algo", Teuchos::ParameterEntry(std::string("scaled cut")));
176 fineLevel.Request("Graph", &coalesceDropFact);
177 fineLevel.Request("DofsPerNode", &coalesceDropFact);
178
179 coalesceDropFact.Build(fineLevel);
180
181 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
182 auto graph = graph_d->copyToHost();
183 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
184 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
185
186 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
187 const RCP<const Map> myDomainMap = graph->GetDomainMap();
188
189 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
190 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
191 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
192 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
193
194 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
195 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
196 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
197 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
198
199 TEST_EQUALITY(graph->GetGlobalNumEdges(), 105);
200
201 } // DistanceLaplacianScaledCut
202
203 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianUnscaledCut, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
204 #include <MueLu_UseShortNames.hpp>
205 typedef Teuchos::ScalarTraits<SC> STS;
206 typedef typename STS::magnitudeType real_type;
207 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
208
209 MUELU_TESTING_SET_OSTREAM;
210 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
211 out << "version: " << MueLu::Version() << std::endl;
212
213 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
214
215 Level fineLevel;
216 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
217
218 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
219 fineLevel.Set("A", A);
220
221 Teuchos::ParameterList galeriList;
222 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
223 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
224
225 // Now we doctor the coordinates so that the off-diagonal pair row 0 will want to keep (0,1) and row 1 will want to drop (1,0)
226 if (!comm->getRank()) {
227 auto vals = coordinates->getDataNonConst(0);
228 vals[0] = vals[0] - 2000 * 36;
229 }
230
231 fineLevel.Set("Coordinates", coordinates);
232
233 CoalesceDropFactory_kokkos coalesceDropFact;
234 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
235 // We're dropping all the interior off-diagonal entries.
236 // dx = 1/36
237 // L_ij = -36
238 // L_ii = 72
239 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
240 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 8.0));
241 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
242 coalesceDropFact.SetParameter("aggregation: distance laplacian algo", Teuchos::ParameterEntry(std::string("unscaled cut")));
243 fineLevel.Request("Graph", &coalesceDropFact);
244 fineLevel.Request("DofsPerNode", &coalesceDropFact);
245
246 coalesceDropFact.Build(fineLevel);
247
248 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
249 auto graph = graph_d->copyToHost();
250 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
251 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
252
253 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
254 const RCP<const Map> myDomainMap = graph->GetDomainMap();
255
256 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
257 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
258 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
259 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
260
261 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
262 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
263 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
264 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
265
266 TEST_EQUALITY(graph->GetGlobalNumEdges(), 105);
267
268 } // DistanceLaplacianUnscaleCut
269
270 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianCutSym, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
271 #include <MueLu_UseShortNames.hpp>
272 typedef Teuchos::ScalarTraits<SC> STS;
273 typedef typename STS::magnitudeType real_type;
274 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
275
276 MUELU_TESTING_SET_OSTREAM;
277 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
278 out << "version: " << MueLu::Version() << std::endl;
279
280 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
281
282 Level fineLevel;
283 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
284
285 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
286 fineLevel.Set("A", A);
287
288 Teuchos::ParameterList galeriList;
289 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
290 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
291
292 // Now we doctor the coordinates so that the off-diagonal pair row 0 will want to keep (0,1) and row 1 will want to drop (1,0)
293 if (!comm->getRank()) {
294 auto vals = coordinates->getDataNonConst(0);
295 vals[0] = vals[0] - 2000 * 36;
296 }
297
298 fineLevel.Set("Coordinates", coordinates);
299
300 CoalesceDropFactory_kokkos coalesceDropFact;
301 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
302
303 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.5));
304 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
305 coalesceDropFact.SetParameter("aggregation: distance laplacian algo", Teuchos::ParameterEntry(std::string("scaled cut symmetric")));
306 fineLevel.Request("Graph", &coalesceDropFact);
307 fineLevel.Request("DofsPerNode", &coalesceDropFact);
308
309 coalesceDropFact.Build(fineLevel);
310
311 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
312 auto graph = graph_d->copyToHost();
313 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
314 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
315
316 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
317 const RCP<const Map> myDomainMap = graph->GetDomainMap();
318
319 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
320 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
321 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
322 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
323
324 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
325 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
326 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
327 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
328
329 TEST_EQUALITY(graph->GetGlobalNumEdges(), 106);
330
331 } // DistanceLaplacianCutScaled
332
333 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianScalarMaterial, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
334 #include <MueLu_UseShortNames.hpp>
335 typedef Teuchos::ScalarTraits<SC> STS;
336 typedef typename STS::magnitudeType real_type;
337 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
338
339 MUELU_TESTING_SET_OSTREAM;
340 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
341 out << "version: " << MueLu::Version() << std::endl;
342
343 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
344
345 Level fineLevel;
346 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
347
348 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
349 fineLevel.Set("A", A);
350
351 Teuchos::ParameterList galeriList;
352 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
353 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
354 fineLevel.Set("Coordinates", coordinates);
355
356 auto material = MultiVectorFactory::Build(A->getRowMap(), 1);
357 material->putScalar(1.0);
358 fineLevel.Set("Material", material);
359
360 CoalesceDropFactory_kokkos coalesceDropFact;
361 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
362 // We're dropping all the interior off-diagonal entries.
363 // dx = 1/36
364 // L_ij = -36
365 // L_ii = 72
366 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
367 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
368 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
369 coalesceDropFact.SetParameter("aggregation: distance laplacian metric", Teuchos::ParameterEntry(std::string("material")));
370 fineLevel.Request("Graph", &coalesceDropFact);
371 fineLevel.Request("DofsPerNode", &coalesceDropFact);
372
373 coalesceDropFact.Build(fineLevel);
374
375 RCP<LWGraph_kokkos> graph_kokkos = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
376 auto graph = graph_kokkos->copyToHost();
377
378 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
379 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
380
381 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
382 const RCP<const Map> myDomainMap = graph->GetDomainMap();
383
384 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
385 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
386 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
387 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
388
389 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
390 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
391 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
392 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
393
394 TEST_EQUALITY(graph->GetGlobalNumEdges(), 40);
395
396 } // DistanceLaplacianScalarMaterial
397
398 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
399 using materialTestCase = std::tuple<RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>,
400 RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>>,
401 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::magnitudeType, LocalOrdinal, GlobalOrdinal, Node>>,
402 RCP<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>>>;
403
404 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
405 materialTestCase<Scalar, LocalOrdinal, GlobalOrdinal, Node> constructVariableMaterialMatrix(RCP<const Teuchos::Comm<int>> &comm) {
406 #include <MueLu_UseShortNames.hpp>
407 using ATS = Kokkos::ArithTraits<Scalar>;
408 using impl_scalar_type = typename ATS::val_type;
409 using implATS = Kokkos::ArithTraits<impl_scalar_type>;
410 using magnitudeType = typename implATS::magnitudeType;
411
412 RCP<const Map> map = MapFactory::Build(Xpetra::UseTpetra, 27 * comm->getSize(), 0, comm);
413
414 RCP<Matrix> A;
415 {
416 using local_matrix_type = typename Matrix::local_matrix_type;
417 std::vector<LocalOrdinal> rowptr = {0, 8, 20, 37, 49, 61, 79, 106, 124, 132, 143, 155, 173, 185, 193, 211, 223, 231, 243, 251, 263, 281, 293, 301, 313, 325, 333, 341};
418 std::vector<LocalOrdinal> indices = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 18, 19, 20, 21, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 18, 19, 20, 21, 22, 23, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 18, 19, 20, 21, 24, 25, 1, 2, 5, 6, 8, 9, 10, 11, 1, 5, 6, 8, 9, 10, 11, 12, 14, 16, 17, 1, 2, 5, 6, 8, 9, 10, 11, 19, 20, 22, 23, 1, 2, 5, 6, 8, 9, 10, 11, 12, 14, 16, 17, 19, 20, 22, 23, 24, 26, 2, 3, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 2, 3, 6, 7, 12, 13, 14, 15, 2, 3, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 20, 21, 23, 24, 25, 26, 2, 3, 6, 7, 12, 13, 14, 15, 20, 21, 24, 25, 2, 6, 9, 11, 12, 14, 16, 17, 2, 6, 9, 11, 12, 14, 16, 17, 20, 23, 24, 26, 4, 5, 6, 7, 18, 19, 20, 21, 4, 5, 6, 7, 10, 11, 18, 19, 20, 21, 22, 23, 4, 5, 6, 7, 10, 11, 14, 15, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 4, 5, 6, 7, 14, 15, 18, 19, 20, 21, 24, 25, 5, 6, 10, 11, 19, 20, 22, 23, 5, 6, 10, 11, 14, 17, 19, 20, 22, 23, 24, 26, 6, 7, 11, 14, 15, 17, 20, 21, 23, 24, 25, 26, 6, 7, 14, 15, 20, 21, 24, 25, 6, 11, 14, 17, 20, 23, 24, 26};
419 std::vector<impl_scalar_type> values = {42.6666666666667, -4.88498130835069e-15, -10.6666666666667, 4.44089209850063e-16, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -4.88498130835069e-15, 85.3333333333333, -1.77635683940025e-15, -10.6666666666667, -10.6666666666667, -1.31006316905768e-14, -21.3333333333333, -10.6666666666667, -8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -10.6666666666667, -10.6666666666667, -1.77635683940025e-15, 170.666666666667, -7.105427357601e-15, -10.6666666666667, -21.3333333333333, -2.44526621173691e-14, -21.3333333333333, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.02140518265514e-14, -10.6666666666667, -21.3333333333333, -10.6666666666667, -10.6666666666667, -10.6666666666667, 4.44089209850063e-16, -10.6666666666667, -7.105427357601e-15, 85.3333333333333, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.06581410364015e-14, -10.6666666666667, -2.66453525910038e-15, -10.6666666666667, -10.6666666666667, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, 43, 6.10622663543836e-16, -10.75, 8.81239525796218e-16, -2.42861286636753e-17, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -10.6666666666667, -1.31006316905768e-14, -21.3333333333333, -10.6666666666667, 6.10622663543836e-16, 86, -2.66626998257635e-15, -10.75, -10.6666666666667, -10.6666666666667, -9.08995101411847e-16, -10.75, -0.0833333333333333, -3.46944695195361e-17, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -10.6666666666667, -21.3333333333333, -2.44526621173691e-14, -21.3333333333333, -10.75, -2.66626998257635e-15, 172, -6.65092980689508e-15, -10.6666666666667, -21.3333333333333, -10.75, -7.63278329429795e-17, -21.3333333333333, -10.6666666666667, -1.03146657881581e-14, -10.75, -10.6666666666667, -10.75, -0.0833333333333333, -0.166666666666667, -4.68375338513738e-17, -0.166666666666667, -0.0833333333333333, -0.166666666666667, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.06581410364015e-14, 8.81239525796218e-16, -10.75, -6.65092980689508e-15, 86, -10.6666666666667, -10.6666666666667, -10.75, -3.59434704222394e-15, -0.0833333333333333, -0.0833333333333333, -0.166666666666667, -1.21430643318376e-17, -0.0833333333333333, -0.0833333333333333, -8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -10.6666666666667, 42.6666666666667, -1.77635683940025e-15, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.77635683940025e-15, 85.3333333333333, -10.6666666666667, -1.33781874467331e-14, -10.6666666666667, -10.6666666666667, -6.21724893790088e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -9.08995101411847e-16, -10.75, -7.105427357601e-15, -10.6666666666667, 43, -1.8249290967276e-15, -0.0833333333333333, -0.0833333333333333, -2.08166817117217e-17, -0.0833333333333333, -10.6666666666667, -21.3333333333333, -10.75, -7.63278329429795e-17, -10.6666666666667, -1.33781874467331e-14, -1.8249290967276e-15, 86, -10.6666666666667, -10.75, -10.6666666666667, -4.9960036108132e-15, -0.0833333333333333, -0.166666666666667, -0.0833333333333333, -3.46944695195361e-17, -0.0833333333333333, -0.0833333333333333, -1.02140518265514e-14, -10.6666666666667, -21.3333333333333, -10.6666666666667, -10.6666666666667, -10.6666666666667, 85.3333333333333, -3.5527136788005e-15, -1.06581410364015e-14, -10.6666666666667, 8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -2.66453525910038e-15, -10.6666666666667, -10.6666666666667, -3.5527136788005e-15, 42.6666666666667, -10.6666666666667, -3.33066907387547e-15, -21.3333333333333, -10.6666666666667, -1.03146657881581e-14, -10.75, -10.6666666666667, -10.75, -1.06581410364015e-14, -10.6666666666667, 86, -4.48252546192407e-15, -10.6666666666667, 4.37150315946155e-16, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -1.7130394325271e-17, -0.0833333333333333, -0.0833333333333333, -10.6666666666667, -10.6666666666667, -10.75, -3.59434704222394e-15, -10.6666666666667, -3.33066907387547e-15, -4.48252546192407e-15, 43, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, 6.93889390390723e-18, -10.6666666666667, -10.6666666666667, -6.21724893790088e-15, -10.6666666666667, 8.88178419700125e-16, -10.6666666666667, 42.6666666666667, -6.27276008913213e-15, -10.6666666666667, -10.75, -10.6666666666667, -4.9960036108132e-15, -10.6666666666667, 4.37150315946155e-16, -6.27276008913213e-15, 43, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -1.38777878078145e-17, -2.42861286636753e-17, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, 0.333333333333333, -2.08166817117217e-17, -0.0833333333333333, -1.38777878078145e-17, -0.0833333333333333, -3.46944695195361e-17, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -2.08166817117217e-17, 0.666666666666667, -3.46944695195361e-17, -0.0833333333333333, -2.08166817117217e-17, -0.0833333333333333, -0.0833333333333333, -0.166666666666667, -4.68375338513738e-17, -0.166666666666667, -0.0833333333333333, -0.166666666666667, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -3.46944695195361e-17, 1.33333333333333, -5.98479599211998e-17, -0.0833333333333333, -3.16587034365767e-17, -1.04517089427603e-16, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -0.166666666666667, -1.21430643318376e-17, -0.0833333333333333, -0.0833333333333333, -1.38777878078145e-17, -0.0833333333333333, -5.98479599211998e-17, 0.666666666666667, -0.0833333333333333, -4.85722573273506e-17, -0.0833333333333333, -0.0833333333333333, -2.08166817117217e-17, -0.0833333333333333, -2.08166817117217e-17, -0.0833333333333333, 0.333333333333333, -2.42861286636753e-17, -0.0833333333333333, -0.166666666666667, -0.0833333333333333, -3.46944695195361e-17, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -3.16587034365767e-17, -2.42861286636753e-17, 0.666666666666667, -0.0833333333333333, -5.24753851482984e-17, -0.166666666666667, -0.0833333333333333, -0.0833333333333333, -1.7130394325271e-17, -0.0833333333333333, -0.0833333333333333, -1.04517089427603e-16, -0.0833333333333333, -0.0833333333333333, 0.666666666666667, -5.29090660172926e-17, -3.90312782094782e-18, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, 6.93889390390723e-18, -0.0833333333333333, -4.85722573273506e-17, -5.29090660172926e-17, 0.333333333333333, -0.0833333333333333, -0.0833333333333333, -0.0833333333333333, -1.38777878078145e-17, -0.0833333333333333, -5.24753851482984e-17, -3.90312782094782e-18, 0.333333333333333};
420 local_matrix_type lclMatrix("lclA", 27, 27, 341, values.data(), rowptr.data(), indices.data());
421 A = MatrixFactory::Build(map, map, lclMatrix);
422 }
423
424 RCP<Matrix> droppedA;
425 {
426 using local_matrix_type = typename Matrix::local_matrix_type;
427 std::vector<LocalOrdinal> rowptr = {0, 8, 20, 37, 49, 58, 70, 88, 100, 108, 119, 128, 140, 152, 160, 172, 181, 189, 198, 203, 209, 218, 224, 229, 235, 241, 246, 251};
428 std::vector<LocalOrdinal> indices = {0, 1, 2, 3, 4, 5, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 0, 1, 2, 3, 4, 5, 6, 7, 18, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, 14, 15, 1, 2, 5, 6, 8, 9, 10, 11, 1, 5, 6, 8, 9, 10, 11, 12, 14, 16, 17, 1, 2, 5, 6, 8, 9, 10, 11, 22, 1, 2, 5, 6, 8, 9, 10, 11, 12, 14, 16, 17, 2, 3, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 2, 3, 6, 7, 12, 13, 14, 15, 2, 3, 6, 7, 9, 11, 12, 13, 14, 15, 16, 17, 2, 3, 6, 7, 12, 13, 14, 15, 25, 2, 6, 9, 11, 12, 14, 16, 17, 2, 6, 9, 11, 12, 14, 16, 17, 26, 4, 18, 19, 20, 21, 18, 19, 20, 21, 22, 23, 18, 19, 20, 21, 22, 23, 24, 25, 26, 18, 19, 20, 21, 24, 25, 10, 19, 20, 22, 23, 19, 20, 22, 23, 24, 26, 20, 21, 23, 24, 25, 26, 15, 20, 21, 24, 25, 17, 20, 23, 24, 26};
429 std::vector<impl_scalar_type> values = {42.6666666666667, -4.88498130835069e-15, -10.6666666666667, 4.44089209850063e-16, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -4.88498130835069e-15, 85.3333333333333, -1.77635683940025e-15, -10.6666666666667, -10.6666666666667, -1.31006316905768e-14, -21.3333333333333, -10.6666666666667, -8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -10.6666666666667, -10.6666666666667, -1.77635683940025e-15, 170.666666666667, -7.105427357601e-15, -10.6666666666667, -21.3333333333333, -2.44526621173691e-14, -21.3333333333333, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.02140518265514e-14, -10.6666666666667, -21.3333333333333, -10.6666666666667, -10.6666666666667, -10.6666666666667, 4.44089209850063e-16, -10.6666666666667, -7.105427357601e-15, 85.3333333333333, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.06581410364015e-14, -10.6666666666667, -2.66453525910038e-15, -10.6666666666667, -10.6666666666667, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, 43, 6.10622663543836e-16, -10.75, 8.81239525796218e-16, -2.42861286636753e-17, -10.6666666666667, -1.31006316905768e-14, -21.3333333333333, -10.6666666666667, 6.10622663543836e-16, 86, -2.66626998257635e-15, -10.75, -10.6666666666667, -10.6666666666667, -9.08995101411847e-16, -10.75, -10.6666666666667, -21.3333333333333, -2.44526621173691e-14, -21.3333333333333, -10.75, -2.66626998257635e-15, 172, -6.65092980689508e-15, -10.6666666666667, -21.3333333333333, -10.75, -7.63278329429795e-17, -21.3333333333333, -10.6666666666667, -1.03146657881581e-14, -10.75, -10.6666666666667, -10.75, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.06581410364015e-14, 8.81239525796218e-16, -10.75, -6.65092980689508e-15, 86, -10.6666666666667, -10.6666666666667, -10.75, -3.59434704222394e-15, -8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -10.6666666666667, 42.6666666666667, -1.77635683940025e-15, -7.105427357601e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -21.3333333333333, -1.77635683940025e-15, 85.3333333333333, -10.6666666666667, -1.33781874467331e-14, -10.6666666666667, -10.6666666666667, -6.21724893790088e-15, -10.6666666666667, -10.6666666666667, -10.6666666666667, -9.08995101411847e-16, -10.75, -7.105427357601e-15, -10.6666666666667, 43, -1.8249290967276e-15, -2.08166817117217e-17, -10.6666666666667, -21.3333333333333, -10.75, -7.63278329429795e-17, -10.6666666666667, -1.33781874467331e-14, -1.8249290967276e-15, 86, -10.6666666666667, -10.75, -10.6666666666667, -4.9960036108132e-15, -1.02140518265514e-14, -10.6666666666667, -21.3333333333333, -10.6666666666667, -10.6666666666667, -10.6666666666667, 85.3333333333333, -3.5527136788005e-15, -1.06581410364015e-14, -10.6666666666667, 8.88178419700125e-16, -10.6666666666667, -10.6666666666667, -2.66453525910038e-15, -10.6666666666667, -10.6666666666667, -3.5527136788005e-15, 42.6666666666667, -10.6666666666667, -3.33066907387547e-15, -21.3333333333333, -10.6666666666667, -1.03146657881581e-14, -10.75, -10.6666666666667, -10.75, -1.06581410364015e-14, -10.6666666666667, 86, -4.48252546192407e-15, -10.6666666666667, 4.37150315946155e-16, -10.6666666666667, -10.6666666666667, -10.75, -3.59434704222394e-15, -10.6666666666667, -3.33066907387547e-15, -4.48252546192407e-15, 43, 6.93889390390723e-18, -10.6666666666667, -10.6666666666667, -6.21724893790088e-15, -10.6666666666667, 8.88178419700125e-16, -10.6666666666667, 42.6666666666667, -6.27276008913213e-15, -10.6666666666667, -10.75, -10.6666666666667, -4.9960036108132e-15, -10.6666666666667, 4.37150315946155e-16, -6.27276008913213e-15, 43, -1.38777878078145e-17, -2.42861286636753e-17, 0.333333333333333, -2.08166817117217e-17, -0.0833333333333333, -1.38777878078145e-17, -2.08166817117217e-17, 0.666666666666667, -3.46944695195361e-17, -0.0833333333333333, -2.08166817117217e-17, -0.0833333333333333, -0.0833333333333333, -3.46944695195361e-17, 1.33333333333333, -5.98479599211998e-17, -0.0833333333333333, -3.16587034365767e-17, -1.04517089427603e-16, -0.0833333333333333, -0.0833333333333333, -1.38777878078145e-17, -0.0833333333333333, -5.98479599211998e-17, 0.666666666666667, -0.0833333333333333, -4.85722573273506e-17, -2.08166817117217e-17, -2.08166817117217e-17, -0.0833333333333333, 0.333333333333333, -2.42861286636753e-17, -0.0833333333333333, -3.16587034365767e-17, -2.42861286636753e-17, 0.666666666666667, -0.0833333333333333, -5.24753851482984e-17, -1.04517089427603e-16, -0.0833333333333333, -0.0833333333333333, 0.666666666666667, -5.29090660172926e-17, -3.90312782094782e-18, 6.93889390390723e-18, -0.0833333333333333, -4.85722573273506e-17, -5.29090660172926e-17, 0.333333333333333, -1.38777878078145e-17, -0.0833333333333333, -5.24753851482984e-17, -3.90312782094782e-18, 0.333333333333333};
430 local_matrix_type lclMatrix("lclA", 27, 27, 251, values.data(), rowptr.data(), indices.data());
431
432 droppedA = MatrixFactory::Build(map, map, lclMatrix);
433 }
434
435 auto coords = Xpetra::MultiVectorFactory<magnitudeType, LocalOrdinal, GlobalOrdinal, Node>::Build(map, 3);
436 {
437 magnitudeType data[27][3] = {{0.0, 0.0, 2.0}, {0.0, 0.0, 1.0}, {0.0, 1.0, 1.0}, {0.0, 1.0, 2.0}, {1.0, 0.0, 2.0}, {1.0, 0.0, 1.0}, {1.0, 1.0, 1.0}, {1.0, 1.0, 2.0}, {0.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {1.0, 0.0, 0.0}, {1.0, 1.0, 0.0}, {0.0, 2.0, 1.0}, {0.0, 2.0, 2.0}, {1.0, 2.0, 1.0}, {1.0, 2.0, 2.0}, {0.0, 2.0, 0.0}, {1.0, 2.0, 0.0}, {2.0, 0.0, 2.0}, {2.0, 0.0, 1.0}, {2.0, 1.0, 1.0}, {2.0, 1.0, 2.0}, {2.0, 0.0, 0.0}, {2.0, 1.0, 0.0}, {2.0, 2.0, 1.0}, {2.0, 2.0, 2.0}, {2.0, 2.0, 0.0}};
438 Kokkos::View<magnitudeType **, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>> kv(&data[0][0], 27, 3);
439 auto lclMV = coords->getHostLocalView(Xpetra::Access::OverwriteAll);
440 Kokkos::deep_copy(lclMV, kv);
441 }
442
443 auto material = MultiVectorFactory::Build(map, 9);
444 {
445 impl_scalar_type data[27][9] = {{128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {128.0, 0.0, 0.0, 0.0, 128.0, 0.0, 0.0, 0.0, 128.0}, {64.5, 0.0, 0.0, 0.0, 64.5, 0.0, 0.0, 0.0, 64.5}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}, {1.0, 0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0}};
446 Kokkos::View<impl_scalar_type **, Kokkos::HostSpace, Kokkos::MemoryTraits<Kokkos::Unmanaged>> kv(&data[0][0], 27, 9);
447 auto lclMV = material->getHostLocalView(Xpetra::Access::OverwriteAll);
448 Kokkos::deep_copy(lclMV, kv);
449 }
450 return std::make_tuple(A, droppedA, coords, material);
451 }
452
453 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianTensorMaterial, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
454 #include <MueLu_UseShortNames.hpp>
455 typedef Teuchos::ScalarTraits<SC> STS;
456 typedef typename STS::magnitudeType real_type;
457 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
458
459 MUELU_TESTING_SET_OSTREAM;
460 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
461 out << "version: " << MueLu::Version() << std::endl;
462
463 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
464
465 RCP<Matrix> A, expectedFilteredA;
466 RCP<RealValuedMultiVector> coordinates;
467 RCP<MultiVector> material;
468 {
469 auto testCase = constructVariableMaterialMatrix<Scalar, LocalOrdinal, GlobalOrdinal, Node>(comm);
470 A = std::get<0>(testCase);
471 expectedFilteredA = std::get<1>(testCase);
472 coordinates = std::get<2>(testCase);
473 material = std::get<3>(testCase);
474 }
475
476 RCP<Matrix> filteredA;
477 {
478 Level fineLevel;
479 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
480 fineLevel.Set("A", A);
481 fineLevel.Set("Coordinates", coordinates);
482 fineLevel.Set("Material", material);
483
484 CoalesceDropFactory_kokkos coalesceDropFact;
485 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
486 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.02));
487 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
488 coalesceDropFact.SetParameter("aggregation: distance laplacian metric", Teuchos::ParameterEntry(std::string("material")));
489 coalesceDropFact.SetParameter("filtered matrix: reuse graph", Teuchos::ParameterEntry(false));
490 coalesceDropFact.SetParameter("filtered matrix: use lumping", Teuchos::ParameterEntry(false));
491 fineLevel.Request("Graph", &coalesceDropFact);
492 fineLevel.Request("A", &coalesceDropFact);
493 fineLevel.Request("DofsPerNode", &coalesceDropFact);
494
495 coalesceDropFact.Build(fineLevel);
496
497 // RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
498 filteredA = fineLevel.Get<RCP<Matrix>>("A", &coalesceDropFact);
499 }
500
501 using TF = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>;
502 {
503 auto lclA = A->getLocalMatrixHost();
504 auto lclFilteredA = filteredA->getLocalMatrixHost();
505 auto lclExpectedFilteredA = expectedFilteredA->getLocalMatrixHost();
506
507 out << "A:\n"
508 << TF::localMatToString(lclA);
509
510 out << "\nFiltered A:\n"
511 << TF::localMatToString(lclFilteredA);
512
513 out << "\nExpected A:\n"
514 << TF::localMatToString(lclExpectedFilteredA) << std::endl;
515
516 TEST_EQUALITY(lclFilteredA.graph.row_map.extent(0), lclExpectedFilteredA.graph.row_map.extent(0));
517 TEST_EQUALITY(lclFilteredA.graph.entries.extent(0), lclExpectedFilteredA.graph.entries.extent(0));
518
519 for (size_t row = 0; row < std::min(lclFilteredA.graph.row_map.extent(0) - 1,
520 lclExpectedFilteredA.graph.row_map.extent(0) - 1);
521 ++row) {
522 out << std::endl;
523 TEST_EQUALITY(lclFilteredA.graph.row_map(row), lclExpectedFilteredA.graph.row_map(row));
524 TEST_EQUALITY(lclFilteredA.graph.row_map(row + 1) - lclFilteredA.graph.row_map(row), lclExpectedFilteredA.graph.row_map(row + 1) - lclExpectedFilteredA.graph.row_map(row));
525
526 for (size_t entry = 0; entry < std::min(lclFilteredA.graph.row_map(row + 1) - lclFilteredA.graph.row_map(row), lclExpectedFilteredA.graph.row_map(row + 1) - lclExpectedFilteredA.graph.row_map(row)); ++entry) {
527 auto offset = lclFilteredA.graph.row_map(row);
528 auto offsetExpected = lclExpectedFilteredA.graph.row_map(row);
529 TEST_EQUALITY(lclFilteredA.graph.entries(offset + entry), lclExpectedFilteredA.graph.entries(offsetExpected + entry));
530 TEST_EQUALITY(lclFilteredA.values(offset + entry), lclExpectedFilteredA.values(offsetExpected + entry));
531 }
532 }
533 }
534
535 } // DistanceLaplacianTensorMaterial
536
537 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicalScaledCut, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
538 #include <MueLu_UseShortNames.hpp>
539 typedef Teuchos::ScalarTraits<SC> STS;
540 typedef typename STS::magnitudeType real_type;
541 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
542
543 MUELU_TESTING_SET_OSTREAM;
544 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
545 out << "version: " << MueLu::Version() << std::endl;
546
547 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
548
549 Level fineLevel;
550 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
551
552 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
553 // Change entry (1,0)
554 auto crsA = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(A, true)->getCrsMatrix();
555 crsA->resumeFill();
556 if (comm->getRank() == 0) {
557 Teuchos::Array<GlobalOrdinal> cols(3);
558 Teuchos::Array<Scalar> vals(3);
559 size_t numEntries;
560 crsA->getGlobalRowCopy(1, cols, vals, numEntries);
561 vals[0] = 0.5;
562 crsA->replaceGlobalValues(1, cols, vals);
563 }
564 crsA->fillComplete();
565 fineLevel.Set("A", A);
566
567 Teuchos::ParameterList galeriList;
568 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
569 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
570 fineLevel.Set("Coordinates", coordinates);
571
572 CoalesceDropFactory_kokkos coalesceDropFact;
573 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
574 // We're dropping all the interior off-diagonal entries.
575 // dx = 1/36
576 // L_ij = -36
577 // L_ii = 72
578 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
579 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
580 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("classical")));
581 coalesceDropFact.SetParameter("aggregation: classical algo", Teuchos::ParameterEntry(std::string("scaled cut")));
582 fineLevel.Request("Graph", &coalesceDropFact);
583 fineLevel.Request("DofsPerNode", &coalesceDropFact);
584
585 coalesceDropFact.Build(fineLevel);
586
587 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
588 auto graph = graph_d->copyToHost();
589 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
590 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
591
592 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
593 const RCP<const Map> myDomainMap = graph->GetDomainMap();
594
595 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
596 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
597 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
598 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
599
600 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
601 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
602 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
603 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
604
605 TEST_EQUALITY(graph->GetGlobalNumEdges(), 105);
606
607 } // ClassicalScaledCut
608
609 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicalUnScaledCut, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
610 #include <MueLu_UseShortNames.hpp>
611 typedef Teuchos::ScalarTraits<SC> STS;
612 typedef typename STS::magnitudeType real_type;
613 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
614
615 MUELU_TESTING_SET_OSTREAM;
616 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
617 out << "version: " << MueLu::Version() << std::endl;
618
619 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
620
621 Level fineLevel;
622 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
623
624 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
625 // Change entry (1,0)
626 auto crsA = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(A, true)->getCrsMatrix();
627 crsA->resumeFill();
628 if (comm->getRank() == 0) {
629 Teuchos::Array<GlobalOrdinal> cols(3);
630 Teuchos::Array<Scalar> vals(3);
631 size_t numEntries;
632 crsA->getGlobalRowCopy(1, cols, vals, numEntries);
633 vals[0] = 0.5;
634 crsA->replaceGlobalValues(1, cols, vals);
635 }
636 crsA->fillComplete();
637 fineLevel.Set("A", A);
638
639 Teuchos::ParameterList galeriList;
640 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
641 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
642 fineLevel.Set("Coordinates", coordinates);
643
644 CoalesceDropFactory_kokkos coalesceDropFact;
645 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
646
647 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
648 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("classical")));
649 coalesceDropFact.SetParameter("aggregation: classical algo", Teuchos::ParameterEntry(std::string("unscaled cut")));
650 fineLevel.Request("Graph", &coalesceDropFact);
651 fineLevel.Request("DofsPerNode", &coalesceDropFact);
652
653 coalesceDropFact.Build(fineLevel);
654
655 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
656 auto graph = graph_d->copyToHost();
657 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
658 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
659
660 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
661 const RCP<const Map> myDomainMap = graph->GetDomainMap();
662
663 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
664 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
665 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
666 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
667
668 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
669 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
670 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
671 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
672
673 TEST_EQUALITY(graph->GetGlobalNumEdges(), 105);
674
675 } // ClassicalUnScaledCut
676
677 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicalCutSym, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
678 #include <MueLu_UseShortNames.hpp>
679 typedef Teuchos::ScalarTraits<SC> STS;
680 typedef typename STS::magnitudeType real_type;
681 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
682
683 MUELU_TESTING_SET_OSTREAM;
684 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
685 out << "version: " << MueLu::Version() << std::endl;
686
687 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
688
689 Level fineLevel;
690 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
691
692 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
693 // Change entry (1,0)
694 auto crsA = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(A, true)->getCrsMatrix();
695 crsA->resumeFill();
696 if (comm->getRank() == 0) {
697 Teuchos::Array<GlobalOrdinal> cols(3);
698 Teuchos::Array<Scalar> vals(3);
699 size_t numEntries;
700 crsA->getGlobalRowCopy(1, cols, vals, numEntries);
701 vals[0] = 0.5;
702 crsA->replaceGlobalValues(1, cols, vals);
703 }
704 crsA->fillComplete();
705 fineLevel.Set("A", A);
706
707 Teuchos::ParameterList galeriList;
708 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
709 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
710 fineLevel.Set("Coordinates", coordinates);
711
712 CoalesceDropFactory_kokkos coalesceDropFact;
713 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
714
715 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
716 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("classical")));
717 coalesceDropFact.SetParameter("aggregation: classical algo", Teuchos::ParameterEntry(std::string("scaled cut symmetric")));
718 fineLevel.Request("Graph", &coalesceDropFact);
719 fineLevel.Request("DofsPerNode", &coalesceDropFact);
720
721 coalesceDropFact.Build(fineLevel);
722
723 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
724 auto graph = graph_d->copyToHost();
725 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
726 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
727
728 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
729 const RCP<const Map> myDomainMap = graph->GetDomainMap();
730
731 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
732 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
733 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
734 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
735
736 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
737 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
738 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
739 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
740
741 TEST_EQUALITY(graph->GetGlobalNumEdges(), 106);
742
743 } // ClassicalCutSym
744
745 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, SignedClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
746 #include <MueLu_UseShortNames.hpp>
747 typedef Teuchos::ScalarTraits<SC> STS;
748 typedef typename STS::magnitudeType real_type;
749 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
750
751 MUELU_TESTING_SET_OSTREAM;
752 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
753 out << "version: " << MueLu::Version() << std::endl;
754
755 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
756
757 Level fineLevel;
758 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
759
760 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
761 // Change entry (1,0)
762 auto crsA = Teuchos::rcp_dynamic_cast<CrsMatrixWrap>(A, true)->getCrsMatrix();
763 crsA->resumeFill();
764 if (comm->getRank() == 0) {
765 Teuchos::Array<GlobalOrdinal> cols(3);
766 Teuchos::Array<Scalar> vals(3);
767 size_t numEntries;
768 crsA->getGlobalRowCopy(1, cols, vals, numEntries);
769 vals[0] *= 2;
770 crsA->replaceGlobalValues(1, cols, vals);
771 }
772 crsA->fillComplete();
773 fineLevel.Set("A", A);
774
775 Teuchos::ParameterList galeriList;
776 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
777 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
778 fineLevel.Set("Coordinates", coordinates);
779
780 CoalesceDropFactory_kokkos coalesceDropFact;
781 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
782 // A_10 = -2
783 // A_ij = -1
784 // A_ii = 2
785 // criterion for dropping is
786 // -Re(L_ij) <= tol * max_{k\neq i} Re(-L_ik)
787 // -> We drop entry (1,2).
788 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.51));
789 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("signed classical")));
790 fineLevel.Request("Graph", &coalesceDropFact);
791 fineLevel.Request("DofsPerNode", &coalesceDropFact);
792
793 coalesceDropFact.Build(fineLevel);
794
795 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
796 auto graph = graph_d->copyToHost();
797 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
798 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
799
800 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
801 const RCP<const Map> myDomainMap = graph->GetDomainMap();
802
803 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
804 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
805 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
806 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
807
808 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
809 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
810 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
811 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
812
813 TEST_EQUALITY(graph->GetGlobalNumEdges(), 105);
814
815 } // SignedClassical
816
817 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, SignedScaledCutClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
818 #include <MueLu_UseShortNames.hpp>
819 typedef Teuchos::ScalarTraits<SC> STS;
820 typedef typename STS::magnitudeType real_type;
821 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
822
823 MUELU_TESTING_SET_OSTREAM;
824 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
825 out << "version: " << MueLu::Version() << std::endl;
826
827 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
828
829 Level fineLevel;
830 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
831
832 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
833 fineLevel.Set("A", A);
834
835 Teuchos::ParameterList galeriList;
836 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
837 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
838 fineLevel.Set("Coordinates", coordinates);
839
840 CoalesceDropFactory_kokkos coalesceDropFact;
841 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
842 // We're dropping all the interior off-diagonal entries.
843 // dx = 1/36
844 // L_ij = -36
845 // L_ii = 72
846 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
847 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 0.51));
848 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("signed classical")));
849 coalesceDropFact.SetParameter("aggregation: classical algo", Teuchos::ParameterEntry(std::string("scaled cut")));
850 fineLevel.Request("Graph", &coalesceDropFact);
851 fineLevel.Request("DofsPerNode", &coalesceDropFact);
852
853 TEST_THROW(coalesceDropFact.Build(fineLevel), MueLu::Exceptions::RuntimeError);
854
855 // RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos> >("Graph", &coalesceDropFact);
856 // LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
857 // TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
858
859 // const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
860 // const RCP<const Map> myDomainMap = graph->GetDomainMap();
861
862 // TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
863 // TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
864 // TEST_EQUALITY(myImportMap->getMinLocalIndex(),0);
865 // TEST_EQUALITY(myImportMap->getGlobalNumElements(),Teuchos::as<size_t>(36 + (comm->getSize()-1)*2));
866
867 // TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
868 // TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
869 // TEST_EQUALITY(myDomainMap->getMinLocalIndex(),0);
870 // TEST_EQUALITY(myDomainMap->getGlobalNumElements(),36);
871
872 // TEST_EQUALITY(graph->GetGlobalNumEdges(),36);
873
874 } // SignedScaledCutClassical
875
876 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, SignedUnscaledCutClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
877 #include <MueLu_UseShortNames.hpp>
878 typedef Teuchos::ScalarTraits<SC> STS;
879 typedef typename STS::magnitudeType real_type;
880 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
881
882 MUELU_TESTING_SET_OSTREAM;
883 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
884 out << "version: " << MueLu::Version() << std::endl;
885
886 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
887
888 Level fineLevel;
889 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
890
891 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
892 fineLevel.Set("A", A);
893
894 Teuchos::ParameterList galeriList;
895 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
896 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
897 fineLevel.Set("Coordinates", coordinates);
898
899 CoalesceDropFactory_kokkos coalesceDropFact;
900 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
901 // We're dropping all the interior off-diagonal entries.
902 // dx = 1/36
903 // L_ij = -36
904 // L_ii = 72
905 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
906 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 0.51));
907 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("signed classical")));
908 coalesceDropFact.SetParameter("aggregation: classical algo", Teuchos::ParameterEntry(std::string("unscaled cut")));
909 fineLevel.Request("Graph", &coalesceDropFact);
910 fineLevel.Request("DofsPerNode", &coalesceDropFact);
911
912 TEST_THROW(coalesceDropFact.Build(fineLevel), MueLu::Exceptions::RuntimeError);
913
914 // RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos> >("Graph", &coalesceDropFact);
915 // LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
916 // TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
917
918 // const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
919 // const RCP<const Map> myDomainMap = graph->GetDomainMap();
920
921 // TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
922 // TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
923 // TEST_EQUALITY(myImportMap->getMinLocalIndex(),0);
924 // TEST_EQUALITY(myImportMap->getGlobalNumElements(),Teuchos::as<size_t>(36 + (comm->getSize()-1)*2));
925
926 // TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
927 // TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
928 // TEST_EQUALITY(myDomainMap->getMinLocalIndex(),0);
929 // TEST_EQUALITY(myDomainMap->getGlobalNumElements(),36);
930
931 // TEST_EQUALITY(graph->GetGlobalNumEdges(),36);
932
933 } // SignedUnScaledCutClassical
934
935 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalColoredSignedClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
936 #include <MueLu_UseShortNames.hpp>
937 typedef Teuchos::ScalarTraits<SC> STS;
938 typedef typename STS::magnitudeType real_type;
939 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
940
941 MUELU_TESTING_SET_OSTREAM;
942 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
943 out << "version: " << MueLu::Version() << std::endl;
944
945 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
946 Level fineLevel;
947 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
948
949 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
950 fineLevel.Set("A", A);
951
952 Teuchos::ParameterList galeriList;
953 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
954 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
955 fineLevel.Set("Coordinates", coordinates);
956
957 CoalesceDropFactory_kokkos coalesceDropFact;
958 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
959 // We're dropping all the interior off-diagonal entries.
960 // dx = 1/36
961 // L_ij = -36
962 // L_ii = 72
963 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
964 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 0.51));
965 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal colored signed classical")));
966 fineLevel.Request("Graph", &coalesceDropFact);
967 fineLevel.Request("DofsPerNode", &coalesceDropFact);
968
969 coalesceDropFact.Build(fineLevel);
970
971 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
972 auto graph = graph_d->copyToHost();
973 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
974 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
975
976 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
977 const RCP<const Map> myDomainMap = graph->GetDomainMap();
978
979 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
980 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
981 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
982 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
983
984 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
985 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
986 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
987 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
988
989 TEST_EQUALITY(graph->GetGlobalNumEdges(), 36);
990
991 } // BlockDiagonalColoredSignedClassical
992
993 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalNoColoredSignedClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
994 #include <MueLu_UseShortNames.hpp>
995 typedef Teuchos::ScalarTraits<SC> STS;
996 typedef typename STS::magnitudeType real_type;
997 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
998
999 MUELU_TESTING_SET_OSTREAM;
1000 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1001 out << "version: " << MueLu::Version() << std::endl;
1002
1003 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1004 // this test is only compatible with rank higher than 1
1005 if (comm->getSize() == 1) {
1006 return;
1007 }
1008
1009 // Default is Laplace1D with nx = 8748.
1010 // It's a nice size for 1D and perfect aggregation. (6561 = 3^8)
1011 // Nice size for 1D and perfect aggregation on small numbers of processors. (8748 = 4*3^7)
1012 Teuchos::CommandLineProcessor clp(false);
1013 Galeri::Xpetra::Parameters<GO> matrixParameters(clp, 8748); // manage parameters of the test case
1014 Xpetra::Parameters xpetraParameters(clp);
1015
1016 RCP<const Map> map = MapFactory::Build(xpetraParameters.GetLib(), matrixParameters.GetNumGlobalElements(), 0, comm);
1017
1018 Level fineLevel;
1019 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1020
1021 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
1022 fineLevel.Set("A", A);
1023
1024 // getCrsGraph()->getImporter()
1025 RCP<const Import> importer = ImportFactory::Build(A->getRowMap(), map);
1026 fineLevel.Set("Importer", importer);
1027 auto importerTest = A->getCrsGraph()->getImporter(); // NULL
1028 Teuchos::ParameterList galeriList;
1029 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
1030 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
1031 fineLevel.Set("Coordinates", coordinates);
1032
1033 CoalesceDropFactory_kokkos coalesceDropFact;
1034 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1035 // We're dropping all the interior off-diagonal entries.
1036 // dx = 1/36
1037 // L_ij = -36
1038 // L_ii = 72
1039 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
1040 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 0.51));
1041 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal colored signed classical")));
1042 coalesceDropFact.SetParameter("aggregation: coloring: localize color graph", Teuchos::ParameterEntry(false));
1043 fineLevel.Request("Graph", &coalesceDropFact);
1044 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1045
1046 // Need an importer
1047 coalesceDropFact.Build(fineLevel);
1048
1049 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1050 auto graph = graph_d->copyToHost();
1051 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1052 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1053
1054 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1055 const RCP<const Map> myDomainMap = graph->GetDomainMap();
1056
1057 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
1058 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1059 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1060 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
1061
1062 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
1063 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1064 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1065 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
1066
1067 TEST_EQUALITY(graph->GetGlobalNumEdges(), 36);
1068
1069 } // BlockDiagonalNoColoredSignedClassical
1070
1071 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalSignedClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1072 #include <MueLu_UseShortNames.hpp>
1073 typedef Teuchos::ScalarTraits<SC> STS;
1074 typedef typename STS::magnitudeType real_type;
1075 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1076
1077 MUELU_TESTING_SET_OSTREAM;
1078 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1079 out << "version: " << MueLu::Version() << std::endl;
1080
1081 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1082
1083 Level fineLevel;
1084 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1085
1086 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
1087 fineLevel.Set("A", A);
1088
1089 Teuchos::ParameterList galeriList;
1090 galeriList.set("nx", Teuchos::as<GlobalOrdinal>(36));
1091 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), galeriList);
1092 fineLevel.Set("Coordinates", coordinates);
1093
1094 CoalesceDropFactory_kokkos coalesceDropFact;
1095 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1096 // We're dropping all the interior off-diagonal entries.
1097 // dx = 1/36
1098 // L_ij = -36
1099 // L_ii = 72
1100 // criterion for dropping is |L_ij|^2 <= tol^2 * |L_ii*L_jj|
1101 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 0.51));
1102 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal signed classical")));
1103 fineLevel.Request("Graph", &coalesceDropFact);
1104 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1105
1106 coalesceDropFact.Build(fineLevel);
1107
1108 RCP<LWGraph_kokkos> graph_d = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1109 auto graph = graph_d->copyToHost();
1110 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1111 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1112
1113 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1114 const RCP<const Map> myDomainMap = graph->GetDomainMap();
1115
1116 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
1117 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1118 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1119 TEST_EQUALITY(myImportMap->getGlobalNumElements(), Teuchos::as<size_t>(36 + (comm->getSize() - 1) * 2));
1120
1121 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
1122 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1123 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1124 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
1125
1126 TEST_EQUALITY(graph->GetGlobalNumEdges(), 36);
1127
1128 } // BlockDiagonalSignedClassical
1129
1130 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonal, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1131 #include <MueLu_UseShortNames.hpp>
1132 typedef Teuchos::ScalarTraits<SC> STS;
1133 typedef typename STS::magnitudeType real_type;
1134 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1135
1136 MUELU_TESTING_SET_OSTREAM;
1137 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1138 out << "version: " << MueLu::Version() << std::endl;
1139
1140 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1141 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1142
1143 GO nx = 10 * comm->getSize();
1144 Teuchos::ParameterList matrixList;
1145 matrixList.set("nx", nx);
1146 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(matrixList, lib);
1147 A->SetFixedBlockSize(1); // So we can block diagonalize
1148 Level fineLevel;
1149 fineLevel.Set("A", A);
1150
1151 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), matrixList);
1152 fineLevel.Set("Coordinates", coordinates);
1153
1154 RCP<InitialBlockNumberFactory> ibFact = rcp(new InitialBlockNumberFactory());
1155 Teuchos::ParameterList ibList;
1156 ibList.set("aggregation: block diagonal: interleaved blocksize", 3);
1157 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1158 CoalesceDropFactory_kokkos coalesceDropFact;
1159 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1160 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1161 coalesceDropFact.SetFactory("BlockNumber", ibFact);
1162 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 8.0));
1163 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal")));
1164 coalesceDropFact.SetParameter("aggregation: block diagonal: interleaved blocksize", Teuchos::ParameterEntry(3));
1165 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1166
1167 fineLevel.Request("Graph", &coalesceDropFact);
1168 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1169
1170 coalesceDropFact.Build(fineLevel);
1171
1172 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1173 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1174 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1175 }
1176
1177 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalClassical, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1178 #include <MueLu_UseShortNames.hpp>
1179 typedef Teuchos::ScalarTraits<SC> STS;
1180 typedef typename STS::magnitudeType real_type;
1181 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1182
1183 MUELU_TESTING_SET_OSTREAM;
1184 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1185 out << "version: " << MueLu::Version() << std::endl;
1186
1187 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1188 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1189
1190 GO nx = 10 * comm->getSize();
1191 Teuchos::ParameterList matrixList;
1192 matrixList.set("nx", nx);
1193 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(matrixList, lib);
1194 A->SetFixedBlockSize(1); // So we can block diagonalize
1195 Level fineLevel;
1196 fineLevel.Set("A", A);
1197
1198 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), matrixList);
1199 fineLevel.Set("Coordinates", coordinates);
1200
1201 RCP<InitialBlockNumberFactory> ibFact = rcp(new InitialBlockNumberFactory());
1202 Teuchos::ParameterList ibList;
1203 ibList.set("aggregation: block diagonal: interleaved blocksize", 3);
1204 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1205 CoalesceDropFactory_kokkos coalesceDropFact;
1206 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1207 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1208 coalesceDropFact.SetFactory("BlockNumber", ibFact);
1209 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0 / 8.0));
1210 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal classical")));
1211 coalesceDropFact.SetParameter("aggregation: block diagonal: interleaved blocksize", Teuchos::ParameterEntry(3));
1212 fineLevel.Request("Graph", &coalesceDropFact);
1213 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1214
1215 coalesceDropFact.Build(fineLevel);
1216
1217 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1218 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1219 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1220 }
1221
1222 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalDistanceLaplacian, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1223 #include <MueLu_UseShortNames.hpp>
1224 typedef Teuchos::ScalarTraits<SC> STS;
1225 typedef typename STS::magnitudeType real_type;
1226 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1227
1228 MUELU_TESTING_SET_OSTREAM;
1229 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1230 out << "version: " << MueLu::Version() << std::endl;
1231
1232 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1233 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1234
1235 GO nx = 10 * comm->getSize();
1236 Teuchos::ParameterList matrixList;
1237 matrixList.set("nx", nx);
1238 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(matrixList, lib);
1239 A->SetFixedBlockSize(1); // So we can block diagonalize
1240 Level fineLevel;
1241 fineLevel.Set("A", A);
1242
1243 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", A->getRowMap(), matrixList);
1244 fineLevel.Set("Coordinates", coordinates);
1245
1246 RCP<InitialBlockNumberFactory> ibFact = rcp(new InitialBlockNumberFactory());
1247 Teuchos::ParameterList ibList;
1248 ibList.set("aggregation: block diagonal: interleaved blocksize", 3);
1249 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1250 CoalesceDropFactory_kokkos coalesceDropFact;
1251 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1252 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1253 coalesceDropFact.SetFactory("BlockNumber", ibFact);
1254 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.025));
1255 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal distance laplacian")));
1256 coalesceDropFact.SetParameter("aggregation: block diagonal: interleaved blocksize", Teuchos::ParameterEntry(3));
1257 fineLevel.Request("Graph", &coalesceDropFact);
1258 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1259
1260 coalesceDropFact.Build(fineLevel);
1261
1262 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1263 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1264 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1265 }
1266
1267 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalDistanceDifferentCoordinatesLaplacian, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1268 #include <MueLu_UseShortNames.hpp>
1269 typedef Teuchos::ScalarTraits<SC> STS;
1270 typedef typename STS::magnitudeType real_type;
1271 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1272
1273 MUELU_TESTING_SET_OSTREAM;
1274 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1275 out << "version: " << MueLu::Version() << std::endl;
1276
1277 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1278 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1279
1280 GO nx = 10 * comm->getSize();
1281 Teuchos::ParameterList matrixList;
1282 matrixList.set("nx", nx);
1283 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(matrixList, lib);
1284 A->SetFixedBlockSize(1); // So we can block diagonalize
1285 Level fineLevel;
1286 fineLevel.Set("A", A);
1287
1288 GO bnx = 15 * comm->getSize();
1289 Teuchos::ParameterList bMatrixList;
1290 matrixList.set("bnx", bnx);
1291 RCP<Matrix> B = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(bMatrixList, lib);
1292
1293 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("1D", B->getRowMap(), matrixList);
1294 fineLevel.Set("Coordinates", coordinates);
1295
1296 RCP<InitialBlockNumberFactory> ibFact = rcp(new InitialBlockNumberFactory());
1297 Teuchos::ParameterList ibList;
1298 ibList.set("aggregation: block diagonal: interleaved blocksize", 3);
1299 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1300 CoalesceDropFactory_kokkos coalesceDropFact;
1301 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1302 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1303 coalesceDropFact.SetFactory("BlockNumber", ibFact);
1304 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.025));
1305 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal distance laplacian")));
1306 coalesceDropFact.SetParameter("aggregation: block diagonal: interleaved blocksize", Teuchos::ParameterEntry(3));
1307 fineLevel.Request("Graph", &coalesceDropFact);
1308 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1309
1310 coalesceDropFact.Build(fineLevel);
1311
1312 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1313 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1314 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1315 }
1316
1317 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, BlockDiagonalDistanceLaplacianWeighted, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1318 #include <MueLu_UseShortNames.hpp>
1319 typedef Teuchos::ScalarTraits<SC> STS;
1320 typedef typename STS::magnitudeType real_type;
1321 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1322
1323 MUELU_TESTING_SET_OSTREAM;
1324 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1325 out << "version: " << MueLu::Version() << std::endl;
1326
1327 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1328 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1329
1330 GO nx = 10 * comm->getSize();
1331 Teuchos::ParameterList matrixList;
1332 matrixList.set("nx", nx);
1333 matrixList.set("ny", (GO)10);
1334 matrixList.set("nz", (GO)10);
1335 matrixList.set("matrixType", "Laplace3D");
1336 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildBlockMatrixAsPoint(matrixList, lib);
1337 A->SetFixedBlockSize(1); // So we can block diagonalize
1338 Level fineLevel;
1339 fineLevel.Set("A", A);
1340
1341 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("3D", A->getRowMap(), matrixList);
1342 fineLevel.Set("Coordinates", coordinates);
1343
1344 RCP<InitialBlockNumberFactory> ibFact = rcp(new InitialBlockNumberFactory());
1345 Teuchos::ParameterList ibList;
1346 ibList.set("aggregation: block diagonal: interleaved blocksize", 3);
1347 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1348 CoalesceDropFactory_kokkos coalesceDropFact;
1349 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1350 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1351 coalesceDropFact.SetFactory("BlockNumber", ibFact);
1352 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.025));
1353 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("block diagonal distance laplacian")));
1354 coalesceDropFact.SetParameter("aggregation: block diagonal: interleaved blocksize", Teuchos::ParameterEntry(3));
1355 std::vector<double> weights_v{100.0, 1.0, 1.0, 1.0, 100, 1.0, 1.0, 1.0, 100.0};
1356 Teuchos::Array<double> weights(weights_v);
1357 coalesceDropFact.SetParameter("aggregation: distance laplacian directional weights", Teuchos::ParameterEntry(weights));
1358 fineLevel.Request("Graph", &coalesceDropFact);
1359 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1360
1361 coalesceDropFact.Build(fineLevel);
1362
1363 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1364 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1365 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1366 }
1367
1368 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, DistanceLaplacianWeighted, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1369 #include <MueLu_UseShortNames.hpp>
1370 typedef Teuchos::ScalarTraits<SC> STS;
1371 typedef typename STS::magnitudeType real_type;
1372 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
1373
1374 MUELU_TESTING_SET_OSTREAM;
1375 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1376 out << "version: " << MueLu::Version() << std::endl;
1377
1378 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1379 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1380
1381 GO nx = 10 * comm->getSize();
1382 Teuchos::ParameterList matrixList;
1383 matrixList.set("nx", nx);
1384 matrixList.set("ny", (GO)10);
1385 matrixList.set("nz", (GO)10);
1386 matrixList.set("matrixType", "Laplace3D");
1387 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildMatrix(matrixList, lib);
1388
1389 Level fineLevel;
1390 fineLevel.Set("A", A);
1391
1392 RCP<RealValuedMultiVector> coordinates = Galeri::Xpetra::Utils::CreateCartesianCoordinates<SC, LO, GO, Map, RealValuedMultiVector>("3D", A->getRowMap(), matrixList);
1393 fineLevel.Set("Coordinates", coordinates);
1394
1395 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1396 CoalesceDropFactory_kokkos coalesceDropFact;
1397 coalesceDropFact.SetDefaultVerbLevel(MueLu::Extreme);
1398 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1399 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.025));
1400 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
1401 std::vector<double> weights_v{100.0, 1.0, 1.0};
1402 Teuchos::Array<double> weights(weights_v);
1403 coalesceDropFact.SetParameter("aggregation: distance laplacian directional weights", Teuchos::ParameterEntry(weights));
1404 fineLevel.Request("Graph", &coalesceDropFact);
1405 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1406
1407 coalesceDropFact.Build(fineLevel);
1408
1409 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1410 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1411 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1412 }
1413
1414 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, SignedClassicalSA, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1415 #include <MueLu_UseShortNames.hpp>
1416 typedef Teuchos::ScalarTraits<SC> STS;
1417 typedef typename STS::magnitudeType real_type;
1418
1419 MUELU_TESTING_SET_OSTREAM;
1420 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
1421 out << "version: " << MueLu::Version() << std::endl;
1422
1423 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1424 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1425
1426 GO nx = 10 * comm->getSize();
1427 Teuchos::ParameterList matrixList;
1428 matrixList.set("nx", nx);
1429 matrixList.set("ny", (GO)10);
1430 matrixList.set("nz", (GO)10);
1431 matrixList.set("matrixType", "Laplace3D");
1432 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildMatrix(matrixList, lib);
1433
1434 Level fineLevel;
1435 fineLevel.Set("A", A);
1436
1437 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
1438 CoalesceDropFactory_kokkos coalesceDropFact;
1439 coalesceDropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1440 coalesceDropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.0));
1441 coalesceDropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("signed classical sa")));
1442 fineLevel.Request("Graph", &coalesceDropFact);
1443 fineLevel.Request("DofsPerNode", &coalesceDropFact);
1444
1445 coalesceDropFact.Build(fineLevel);
1446
1447 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &coalesceDropFact);
1448 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &coalesceDropFact);
1449 TEST_EQUALITY(Teuchos::as<int>(myDofsPerNode) == 1, true);
1450 }
1451
1452 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicScalarWithoutFiltering, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1453 #include "MueLu_UseShortNames.hpp"
1454 MUELU_TESTING_SET_OSTREAM;
1455 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO);
1456 out << "version: " << MueLu::Version() << std::endl;
1457
1458 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1459
1460 Level fineLevel;
1461 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1462
1463 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(36);
1464 fineLevel.Set("A", A);
1465
1466 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1467 CoalesceDropFactory_kokkos dropFact;
1468 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1469
1470 fineLevel.Request("Graph", &dropFact);
1471 fineLevel.Request("DofsPerNode", &dropFact);
1472
1473 dropFact.Build(fineLevel);
1474
1475 auto graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &dropFact);
1476 auto myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1477
1478 TEST_EQUALITY(as<int>(myDofsPerNode) == 1, true);
1479
1480 bool bCorrectGraph = false;
1481 int reduction_val = 0;
1482 int comm_size = comm->getSize(), comm_rank = comm->getRank();
1483 auto lclLWGraph = *graph;
1484 Kokkos::parallel_reduce(
1485 "MueLu:TentativePF:Build:compute_agg_sizes", Kokkos::RangePolicy<typename NO::execution_space, size_t>(0, 1),
1486 KOKKOS_LAMBDA(const LO i, int &correct) {
1487 if (comm_size == 1) {
1488 auto v0 = lclLWGraph.getNeighborVertices(0);
1489 auto v1 = lclLWGraph.getNeighborVertices(1);
1490 auto v2 = lclLWGraph.getNeighborVertices(2);
1491 if (v0.length == 2 && ((v0(0) == 0 && v0(1) == 1) || (v0(0) == 1 && v0(1) == 0)) &&
1492 v1.length == 3 && v2.length == 3)
1493 correct = true;
1494 } else {
1495 if (comm_rank == 0) {
1496 if (lclLWGraph.getNeighborVertices(0).length == 2)
1497 correct = true;
1498
1499 } else {
1500 if (lclLWGraph.getNeighborVertices(0).length == 3)
1501 correct = true;
1502 }
1503 }
1504 },
1505 reduction_val);
1506 bCorrectGraph = reduction_val;
1507 TEST_EQUALITY(bCorrectGraph, true);
1508
1509 auto myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1510 auto myDomainMap = graph->GetDomainMap();
1511
1512 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
1513 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1514 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1515 TEST_EQUALITY(myImportMap->getGlobalNumElements(), as<size_t>(36 + (comm->getSize() - 1) * 2));
1516
1517 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
1518 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1519 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1520 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
1521 }
1522
1523 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicScalarWithFiltering, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1524 #include "MueLu_UseShortNames.hpp"
1525 MUELU_TESTING_SET_OSTREAM;
1526 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO);
1527 out << "version: " << MueLu::Version() << std::endl;
1528
1529 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1530 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1531
1532 Level fineLevel;
1533 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1534
1535 auto dofMap = MapFactory::Build(lib, 3 * comm->getSize(), 0, comm);
1536 auto mtx = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildTridiag(dofMap, 1.0, -1.0, -0.0001);
1537
1538 mtx->SetFixedBlockSize(1, 0);
1539 fineLevel.Set("A", mtx);
1540
1541 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1542 CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
1543 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1544 dropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(0.5));
1545
1546 fineLevel.Request("Graph", &dropFact);
1547 fineLevel.Request("DofsPerNode", &dropFact);
1548
1549 dropFact.Build(fineLevel);
1550
1551 auto graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &dropFact);
1552 auto myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1553
1554 TEST_EQUALITY(as<int>(myDofsPerNode) == 1, true);
1555 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == 3 * comm->getSize(), true);
1556
1557 bool bCorrectGraph = false;
1558 int reduction_val = 0;
1559 int comm_size = comm->getSize(), comm_rank = comm->getRank();
1560 auto lclLWGraph = *graph;
1561 Kokkos::parallel_reduce(
1562 "MueLu:TentativePF:Build:compute_agg_sizes", Kokkos::RangePolicy<typename NO::execution_space, size_t>(0, 1),
1563 KOKKOS_LAMBDA(const LO i, int &correct) {
1564 if (comm_size == 1) {
1565 auto v0 = lclLWGraph.getNeighborVertices(0);
1566 auto v1 = lclLWGraph.getNeighborVertices(1);
1567 auto v2 = lclLWGraph.getNeighborVertices(2);
1568 if (v0.length == 1 && v0(0) == 0 &&
1569 v1.length == 2 && ((v1(0) == 0 && v1(1) == 1) || (v1(0) == 1 && v1(1) == 0)) &&
1570 v2.length == 2 && ((v2(0) == 1 && v2(1) == 2) || (v2(0) == 2 && v2(1) == 1)))
1571 correct = true;
1572 } else {
1573 if (comm_rank == 0) {
1574 if (lclLWGraph.getNeighborVertices(0).length == 1)
1575 correct = true;
1576
1577 } else {
1578 if (lclLWGraph.getNeighborVertices(0).length == 2)
1579 correct = true;
1580 }
1581 }
1582 },
1583 reduction_val);
1584 bCorrectGraph = reduction_val;
1585 TEST_EQUALITY(bCorrectGraph, true);
1586
1587 auto myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1588 auto myDomainMap = graph->GetDomainMap();
1589
1590 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 3 * comm->getSize() - 1);
1591 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1592 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1593 TEST_EQUALITY(myImportMap->getGlobalNumElements(), as<size_t>(3 * comm->getSize() + (comm->getSize() - 1) * 2));
1594
1595 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 3 * comm->getSize() - 1);
1596 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1597 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1598 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), as<size_t>(3 * comm->getSize()));
1599 TEST_EQUALITY(myDomainMap->getLocalNumElements(), 3);
1600 }
1601
1602 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicBlockWithoutFiltering, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1603 #include "MueLu_UseShortNames.hpp"
1604 MUELU_TESTING_SET_OSTREAM;
1605 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO);
1606 out << "version: " << MueLu::Version() << std::endl;
1607
1608 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1609 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1610
1611 Level fineLevel;
1612 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1613
1614 int blockSize = 3;
1615
1616 auto dofMap = MapFactory::Build(lib, blockSize * comm->getSize(), 0, comm);
1617 auto mtx = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildTridiag(dofMap, 2.0, -1.0, -1.0);
1618 mtx->SetFixedBlockSize(blockSize, 0);
1619 fineLevel.Set("A", mtx);
1620
1621 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1622 CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
1623 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1624
1625 fineLevel.Request("Graph", &dropFact);
1626 fineLevel.Request("DofsPerNode", &dropFact);
1627
1628 dropFact.Build(fineLevel);
1629
1630 auto graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &dropFact);
1631 auto myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1632
1633 TEST_EQUALITY(as<int>(myDofsPerNode) == blockSize, true);
1634 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == comm->getSize(), true);
1635
1636 bool bCorrectGraph = false;
1637 int reduction_val = 0;
1638 int comm_size = comm->getSize(), comm_rank = comm->getRank();
1639 auto lclLWGraph = *graph;
1640 Kokkos::parallel_reduce(
1641 "MueLu:TentativePF:Build:compute_agg_sizes", Kokkos::RangePolicy<typename NO::execution_space, size_t>(0, 1),
1642 KOKKOS_LAMBDA(const LO i, int &correct) {
1643 if (comm_size == 1 && lclLWGraph.getNeighborVertices(0).length == 1) {
1644 correct = true;
1645 } else {
1646 if (comm_rank == 0 || comm_rank == comm_size - 1) {
1647 if (lclLWGraph.getNeighborVertices(0).length == 2)
1648 correct = true;
1649
1650 } else {
1651 if (static_cast<int>(lclLWGraph.getNeighborVertices(0).length) == blockSize)
1652 correct = true;
1653 }
1654 }
1655 },
1656 reduction_val);
1657 bCorrectGraph = reduction_val;
1658 TEST_EQUALITY(bCorrectGraph, true);
1659
1660 auto myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1661 auto myDomainMap = graph->GetDomainMap();
1662
1663 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), comm->getSize() - 1);
1664 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1665 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1666 TEST_EQUALITY(myImportMap->getGlobalNumElements(), as<size_t>(comm->getSize() + 2 * (comm->getSize() - 1)));
1667
1668 if (comm->getSize() > 1) {
1669 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
1670 size_t numLocalImportElts = myImportMap->getLocalNumElements();
1671 if (comm->getRank() == 0 || comm->getRank() == comm->getSize() - 1) {
1672 TEST_EQUALITY(numLocalImportElts, numLocalRowMapElts + 1);
1673 } else {
1674 TEST_EQUALITY(numLocalImportElts, numLocalRowMapElts + 2);
1675 }
1676 }
1677 if (comm->getSize() > 1) {
1678 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
1679 size_t maxLocalIndex = myImportMap->getMaxLocalIndex();
1680 if (comm->getRank() == 0 || comm->getRank() == comm->getSize() - 1) {
1681 TEST_EQUALITY(maxLocalIndex, numLocalRowMapElts * blockSize - 2);
1682 } else {
1683 TEST_EQUALITY(maxLocalIndex, numLocalRowMapElts * blockSize - 1);
1684 }
1685 }
1686
1687 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), comm->getSize() - 1);
1688 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1689 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1690 TEST_EQUALITY(myDomainMap->getMaxLocalIndex(), 0);
1691 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), as<size_t>(comm->getSize()));
1692 TEST_EQUALITY(myDomainMap->getLocalNumElements(), 1);
1693 }
1694
1695 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, ClassicBlockWithFiltering, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
1696 #include "MueLu_UseShortNames.hpp"
1697 MUELU_TESTING_SET_OSTREAM;
1698 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, NO);
1699 out << "version: " << MueLu::Version() << std::endl;
1700
1701 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
1702 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
1703
1704 Level fineLevel;
1705 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
1706
1707 auto dofMap = MapFactory::Build(lib, 3 * comm->getSize(), 0, comm);
1708 auto mtx = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildTridiag(dofMap, 2.0, -1.0, 0.00001);
1709
1710 mtx->SetFixedBlockSize(3, 0);
1711 fineLevel.Set("A", mtx);
1712
1713 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1714 CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
1715 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1716 dropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(1.0));
1717
1718 fineLevel.Request("Graph", &dropFact);
1719 fineLevel.Request("DofsPerNode", &dropFact);
1720
1721 dropFact.Build(fineLevel);
1722
1723 auto graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &dropFact);
1724 auto myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1725
1726 TEST_EQUALITY(as<int>(myDofsPerNode) == 3, true);
1727 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == comm->getSize(), true);
1728
1729 TEST_EQUALITY(graph->getNeighborVertices(0).size(), 1);
1730
1731 auto myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1732 auto myDomainMap = graph->GetDomainMap();
1733
1734 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), comm->getSize() - 1);
1735 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1736 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1737 TEST_EQUALITY(myImportMap->getGlobalNumElements(), as<size_t>(comm->getSize() + 2 * (comm->getSize() - 1)));
1738 if (comm->getSize() > 1) {
1739 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
1740 size_t numLocalImportElts = myImportMap->getLocalNumElements();
1741 if (comm->getRank() == 0 || comm->getRank() == comm->getSize() - 1) {
1742 TEST_EQUALITY(numLocalImportElts, numLocalRowMapElts + 1);
1743 } else {
1744 TEST_EQUALITY(numLocalImportElts, numLocalRowMapElts + 2);
1745 }
1746 }
1747
1748 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), comm->getSize() - 1);
1749 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1750 TEST_EQUALITY(myDomainMap->getMaxLocalIndex(), 0);
1751 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1752 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), as<size_t>(comm->getSize()));
1753 TEST_EQUALITY(myDomainMap->getLocalNumElements(), 1);
1754 }
1755
1756 #if 0
1757 TEUCHOS_UNIT_TEST(CoalesceDropFactory_kokkos, LaplacianScalarWithoutFiltering)
1758 {
1759 #include "MueLu_UseShortNames.hpp"
1760 MUELU_TESTING_SET_OSTREAM;
1761 MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,NO);
1762 out << "version: " << MueLu::Version() << std::endl;
1763
1764 RCP<const Teuchos::Comm<int> > comm = Parameters::getDefaultComm();
1765
1766 Level fineLevel;
1767 TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
1768
1769 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::Build1DPoisson(36);
1770 fineLevel.Set("A", A);
1771
1772 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1773 CoalesceDropFactory_kokkos dropFact;
1774 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1775 dropFact.SetParameter("aggregation: drop scheme", Teuchos::ParameterEntry(std::string("distance laplacian")));
1776
1777 fineLevel.Request("Graph", &dropFact);
1778 fineLevel.Request("DofsPerNode", &dropFact);
1779
1780 dropFact.Build(fineLevel);
1781
1782 auto graph_d = fineLevel.Get<RCP<LWGraph_kokkos> >("Graph", &dropFact);
1783 auto graph = graph_d->copyToHost();
1784 auto myDofsPerNode = fineLevel.Get<LO> ("DofsPerNode", &dropFact);
1785 TEST_EQUALITY(as<int>(myDofsPerNode) == 1, true);
1786
1787 bool bCorrectGraph = false;
1788 if (comm->getSize() == 1) {
1789 auto v0 = graph->getNeighborVertices(0);
1790 auto v1 = graph->getNeighborVertices(1);
1791 auto v2 = graph->getNeighborVertices(2);
1792 if (v0.size() == 2 && ((v0(0) == 0 && v0(1) == 1) || (v0(0) == 1 && v0(1) == 0)) &&
1793 v1.size() == 3 && v2.size() == 3)
1794 bCorrectGraph = true;
1795 } else {
1796 if (comm->getRank() == 0 ) {
1797 if (graph->getNeighborVertices(0).size() == 2)
1798 bCorrectGraph = true;
1799
1800 } else {
1801 if (graph->getNeighborVertices(0).size() == 3)
1802 bCorrectGraph = true;
1803 }
1804 }
1805 TEST_EQUALITY(bCorrectGraph, true);
1806
1807 auto myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1808 auto myDomainMap = graph->GetDomainMap();
1809
1810 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), 35);
1811 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1812 TEST_EQUALITY(myImportMap->getMinLocalIndex(), 0);
1813 TEST_EQUALITY(myImportMap->getGlobalNumElements(), as<size_t>(36 + (comm->getSize()-1)*2));
1814
1815 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), 35);
1816 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1817 TEST_EQUALITY(myDomainMap->getMinLocalIndex(), 0);
1818 TEST_EQUALITY(myDomainMap->getGlobalNumElements(), 36);
1819 }
1820 #endif
1821
1822 #if 0
1823 TEUCHOS_UNIT_TEST(CoalesceDropFactory, AmalgamationStridedLW)
1824 {
1825 #include "MueLu_UseShortNames.hpp"
1826 MUELU_TESTING_SET_OSTREAM;
1827 MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,NO);
1828 out << "version: " << MueLu::Version() << std::endl;
1829
1830 // unit test for block size 3 using a strided map
1831
1832 RCP<const Teuchos::Comm<int> > comm = Parameters::getDefaultComm();
1833
1834 Level fineLevel;
1835 TestHelpers::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
1836
1837 int blockSize=3;
1838
1839 GO nx = blockSize*comm->getSize();
1840 RCP<Matrix> A = TestHelpers::TestFactory<SC,LO,GO,NO>::Build1DPoisson(nx);
1841
1842 std::vector<size_t> stridingInfo;
1843 stridingInfo.push_back(as<size_t>(blockSize));
1844 LocalOrdinal stridedBlockId = -1;
1845
1846 RCP<const Xpetra::StridedMap<LocalOrdinal, GlobalOrdinal, Node> > stridedRangeMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
1847 A->getRangeMap(),
1848 stridingInfo,
1849 stridedBlockId,
1850 0 /*offset*/
1851 );
1852 RCP<const Map> stridedDomainMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
1853 A->getDomainMap(),
1854 stridingInfo,
1855 stridedBlockId,
1856 0 /*offset*/
1857 );
1858
1859 if(A->IsView("stridedMaps") == true) A->RemoveView("stridedMaps");
1860 A->CreateView("stridedMaps", stridedRangeMap, stridedDomainMap);
1861
1862 fineLevel.Set("A", A);
1863 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1864 CoalesceDropFactory dropFact = CoalesceDropFactory();
1865 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1866 fineLevel.Request("Graph", &dropFact);
1867 fineLevel.Request("DofsPerNode", &dropFact);
1868
1869 dropFact.Build(fineLevel);
1870
1871 fineLevel.print(out);
1872 RCP<GraphBase> graph = fineLevel.Get<RCP<GraphBase> >("Graph", &dropFact);
1873 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1874 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == comm->getSize(), true);
1875 TEST_EQUALITY(as<int>(myDofsPerNode) == blockSize, true);
1876 bool bCorrectGraph = false;
1877 if (comm->getSize() == 1 && graph->getNeighborVertices(0).size() == 1) {
1878 bCorrectGraph = true;
1879 } else {
1880 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
1881 if (graph->getNeighborVertices(0).size() == 2) bCorrectGraph = true;
1882 }
1883 else {
1884 if (graph->getNeighborVertices(0).size() == blockSize) bCorrectGraph = true;
1885 }
1886 }
1887 TEST_EQUALITY(bCorrectGraph, true);
1888
1889 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1890 const RCP<const Map> myDomainMap = graph->GetDomainMap();
1891
1892 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), comm->getSize()-1);
1893 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
1894 TEST_EQUALITY(myImportMap->getMinLocalIndex(),0);
1895 TEST_EQUALITY(myImportMap->getGlobalNumElements(),as<size_t>(comm->getSize()+2*(comm->getSize()-1)));
1896 if (comm->getSize()>1) {
1897 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
1898 size_t numLocalImportElts = myImportMap->getLocalNumElements();
1899 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
1900 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+1), true);
1901 } else {
1902 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+2), true);
1903 }
1904 }
1905 if (comm->getSize()>1) {
1906 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
1907 size_t maxLocalIndex = myImportMap->getMaxLocalIndex();
1908 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
1909 TEST_EQUALITY(as<bool>(maxLocalIndex==numLocalRowMapElts*blockSize-2), true);
1910 } else {
1911 TEST_EQUALITY(as<bool>(maxLocalIndex==numLocalRowMapElts*blockSize-1), true);
1912 }
1913 }
1914
1915 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), comm->getSize()-1);
1916 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
1917 TEST_EQUALITY(myDomainMap->getMinLocalIndex(),0);
1918 TEST_EQUALITY(myDomainMap->getMaxLocalIndex(),0);
1919 TEST_EQUALITY(myDomainMap->getGlobalNumElements(),as<size_t>(comm->getSize()));
1920 TEST_EQUALITY(as<bool>(myDomainMap->getLocalNumElements()==1), true);
1921 } // AmalgamationStridedLW
1922
1923 TEUCHOS_UNIT_TEST(CoalesceDropFactory, AmalgamationStrided2LW)
1924 {
1925 #include "MueLu_UseShortNames.hpp"
1926 MUELU_TESTING_SET_OSTREAM;
1927 MUELU_TESTING_LIMIT_SCOPE(Scalar,GlobalOrdinal,NO);
1928 out << "version: " << MueLu::Version() << std::endl;
1929
1930 // unit test for block size 3 = (2,1). wrap block 0
1931
1932 RCP<const Teuchos::Comm<int> > comm = Parameters::getDefaultComm();
1933 Xpetra::UnderlyingLib lib = TestHelpers::Parameters::getLib();
1934
1935 // create strided map information
1936 std::vector<size_t> stridingInfo;
1937 stridingInfo.push_back(as<size_t>(2));
1938 stridingInfo.push_back(as<size_t>(1));
1939 LocalOrdinal stridedBlockId = 0;
1940
1941 int blockSize=3;
1942
1943 RCP<const StridedMap> dofMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(lib, blockSize*comm->getSize(), 0,
1944 stridingInfo, comm,
1945 stridedBlockId /*blockId*/, 0 /*offset*/);
1946
1947 /////////////////////////////////////////////////////
1948
1949 Teuchos::RCP<Matrix> mtx = TestHelpers::TestFactory<SC,LO,GO,NO>::BuildTridiag(dofMap, 2.0, -1.0, -1.0);
1950
1951 Level fineLevel;
1952 TestHelpers::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
1953
1954 RCP<const Xpetra::StridedMap<LocalOrdinal, GlobalOrdinal, Node> > stridedRangeMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
1955 mtx->getRangeMap(),
1956 stridingInfo,
1957 stridedBlockId,
1958 0 /*offset*/
1959 );
1960 RCP<const Map> stridedDomainMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
1961 mtx->getDomainMap(),
1962 stridingInfo,
1963 stridedBlockId,
1964 0 /*offset*/
1965 );
1966 if(mtx->IsView("stridedMaps") == true) mtx->RemoveView("stridedMaps");
1967 mtx->CreateView("stridedMaps", stridedRangeMap, stridedDomainMap);
1968
1969 fineLevel.Set("A", mtx);
1970 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
1971 CoalesceDropFactory dropFact = CoalesceDropFactory();
1972 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
1973 fineLevel.Request("Graph", &dropFact);
1974 fineLevel.Request("DofsPerNode", &dropFact);
1975
1976 dropFact.Build(fineLevel);
1977
1978 fineLevel.print(out);
1979 RCP<GraphBase> graph = fineLevel.Get<RCP<GraphBase> >("Graph", &dropFact);
1980
1981 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
1982 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == comm->getSize(), true);
1983 TEST_EQUALITY(as<int>(myDofsPerNode) == blockSize, true);
1984 bool bCorrectGraph = false;
1985 if (comm->getSize() == 1 && graph->getNeighborVertices(0).size() == 1) {
1986 bCorrectGraph = true;
1987 } else {
1988 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
1989 if (graph->getNeighborVertices(0).size() == 2) bCorrectGraph = true;
1990 }
1991 else {
1992 if (graph->getNeighborVertices(0).size() == blockSize) bCorrectGraph = true;
1993 }
1994 }
1995 TEST_EQUALITY(bCorrectGraph, true);
1996
1997 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
1998 const RCP<const Map> myDomainMap = graph->GetDomainMap();
1999
2000 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), comm->getSize()-1);
2001 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
2002 TEST_EQUALITY(myImportMap->getMinLocalIndex(),0);
2003 TEST_EQUALITY(myImportMap->getGlobalNumElements(),as<size_t>(comm->getSize()+2*(comm->getSize()-1)));
2004 if (comm->getSize()>1) {
2005 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
2006 size_t numLocalImportElts = myImportMap->getLocalNumElements();
2007 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
2008 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+1), true);
2009 } else {
2010 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+2), true);
2011 }
2012 }
2013 if (comm->getSize()>1) {
2014 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
2015 size_t maxLocalIndex = myImportMap->getMaxLocalIndex();
2016 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
2017 TEST_EQUALITY(as<bool>(maxLocalIndex==numLocalRowMapElts*blockSize-2), true);
2018 } else {
2019 TEST_EQUALITY(as<bool>(maxLocalIndex==numLocalRowMapElts*blockSize-1), true);
2020 }
2021 }
2022
2023 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), comm->getSize()-1);
2024 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
2025 TEST_EQUALITY(myDomainMap->getMinLocalIndex(),0);
2026 TEST_EQUALITY(myDomainMap->getMaxLocalIndex(),0);
2027 TEST_EQUALITY(myDomainMap->getGlobalNumElements(),as<size_t>(comm->getSize()));
2028 TEST_EQUALITY(as<bool>(myDomainMap->getLocalNumElements()==1), true);
2029 } // AmalgamationStrided2LW
2030
2031
2032 TEUCHOS_UNIT_TEST(CoalesceDropFactory, AmalgamationStridedOffsetDropping2LW)
2033 {
2034 // unit test for block size 9 = (2,3,4). wrap block 1.
2035 // drop small entries
2036 out << "version: " << MueLu::Version() << std::endl;
2037
2038 RCP<const Teuchos::Comm<int> > comm = Parameters::getDefaultComm();
2039 Xpetra::UnderlyingLib lib = TestHelpers::Parameters::getLib();
2040
2041 // create strided map information
2042 std::vector<size_t> stridingInfo;
2043 stridingInfo.push_back(as<size_t>(2));
2044 stridingInfo.push_back(as<size_t>(3));
2045 stridingInfo.push_back(as<size_t>(4));
2046 LocalOrdinal stridedBlockId = 1;
2047 GlobalOrdinal offset = 19;
2048
2049 RCP<const StridedMap> dofMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(lib, 9*comm->getSize(), 0,
2050 stridingInfo, comm,
2051 stridedBlockId, offset);
2052
2053 /////////////////////////////////////////////////////
2054
2055 Teuchos::RCP<Matrix> mtx = TestHelpers::TestFactory<SC,LO,GO,NO>::BuildTridiag(dofMap, 2.0, 1.0, 0.0001);
2056
2057 Level fineLevel;
2058 TestHelpers::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
2059
2060 RCP<const Map> stridedRangeMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
2061 mtx->getRangeMap(),
2062 stridingInfo,
2063 stridedBlockId,
2064 offset
2065 );
2066 RCP<const Map> stridedDomainMap = Xpetra::StridedMapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(
2067 mtx->getDomainMap(),
2068 stridingInfo,
2069 stridedBlockId,
2070 offset
2071 );
2072
2073 if(mtx->IsView("stridedMaps") == true) mtx->RemoveView("stridedMaps");
2074 mtx->CreateView("stridedMaps", stridedRangeMap, stridedDomainMap);
2075
2076 fineLevel.Set("A", mtx);
2077 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory);
2078 CoalesceDropFactory dropFact = CoalesceDropFactory();
2079 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
2080 dropFact.SetParameter("aggregation: drop tol",Teuchos::ParameterEntry(0.3));
2081
2082 fineLevel.Request("Graph", &dropFact);
2083 fineLevel.Request("DofsPerNode", &dropFact);
2084
2085 dropFact.Build(fineLevel);
2086
2087 fineLevel.print(out);
2088 RCP<GraphBase> graph = fineLevel.Get<RCP<GraphBase> >("Graph", &dropFact);
2089
2090 LO myDofsPerNode = fineLevel.Get<LO>("DofsPerNode", &dropFact);
2091 TEST_EQUALITY(as<int>(graph->GetDomainMap()->getGlobalNumElements()) == comm->getSize(), true);
2092 TEST_EQUALITY(as<int>(myDofsPerNode) == 9, true);
2093 bool bCorrectGraph = false;
2094 if (comm->getSize() == 1 && graph->getNeighborVertices(0).size() == 1) {
2095 bCorrectGraph = true;
2096 } else {
2097 if (comm->getRank() == 0) {
2098 if (graph->getNeighborVertices(0).size() == 1) bCorrectGraph = true;
2099 }
2100 else {
2101 if (graph->getNeighborVertices(0).size() == 2) bCorrectGraph = true;
2102 }
2103 }
2104 TEST_EQUALITY(bCorrectGraph, true);
2105
2106 const RCP<const Map> myImportMap = graph->GetImportMap(); // < note that the ImportMap is built from the column map of the matrix A WITHOUT dropping!
2107 const RCP<const Map> myDomainMap = graph->GetDomainMap();
2108
2109 TEST_EQUALITY(myImportMap->getMaxAllGlobalIndex(), comm->getSize()-1);
2110 TEST_EQUALITY(myImportMap->getMinAllGlobalIndex(), 0);
2111 TEST_EQUALITY(myImportMap->getMinLocalIndex(),0);
2112 TEST_EQUALITY(myImportMap->getGlobalNumElements(),as<size_t>(comm->getSize()+2*(comm->getSize()-1)));
2113 if (comm->getSize()>1) {
2114 size_t numLocalRowMapElts = graph->GetNodeNumVertices();
2115 size_t numLocalImportElts = myImportMap->getLocalNumElements();
2116 if (comm->getRank() == 0 || comm->getRank() == comm->getSize()-1) {
2117 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+1), true);
2118 } else {
2119 TEST_EQUALITY(as<bool>(numLocalImportElts==numLocalRowMapElts+2), true);
2120 }
2121 }
2122 TEST_EQUALITY(myDomainMap->getMaxAllGlobalIndex(), comm->getSize()-1);
2123 TEST_EQUALITY(myDomainMap->getMinAllGlobalIndex(), 0);
2124 TEST_EQUALITY(myDomainMap->getMinLocalIndex(),0);
2125 TEST_EQUALITY(myDomainMap->getGlobalNumElements(),as<size_t>(comm->getSize()));
2126 TEST_EQUALITY(as<bool>(myDomainMap->getLocalNumElements()==1), true);
2127 } // AmalgamationStridedOffsetDropping2LW
2128 #endif
2129
2130 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, AggresiveDroppingIsMarkedAsBoundary, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
2131 // Test that when everything but the diagonal is dropped, the node is marked as boundary
2132 #include <MueLu_UseShortNames.hpp>
2133 MUELU_TESTING_SET_OSTREAM;
2134 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
2135 out << "version: " << MueLu::Version() << std::endl;
2136
2137 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
2138 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
2139
2140 RCP<const Map> dofMap = Xpetra::MapFactory<LocalOrdinal, GlobalOrdinal, Node>::Build(lib, 12 * comm->getSize(), 0, comm);
2141 Teuchos::RCP<Matrix> mtx = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildTridiag(dofMap, 2.0, -1.0, -1.0);
2142
2143 {
2144 Level fineLevel;
2145 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
2146
2147 mtx->SetFixedBlockSize(1);
2148 fineLevel.Set("A", mtx);
2149
2150 CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
2151 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
2152 dropFact.SetFactory("UnAmalgamationInfo", amalgFact);
2153 dropFact.SetParameter("aggregation: drop tol", Teuchos::ParameterEntry(4.1));
2154 fineLevel.Request("Graph", &dropFact);
2155 fineLevel.Request("DofsPerNode", &dropFact);
2156
2157 dropFact.Build(fineLevel);
2158
2159 RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", &dropFact);
2160
2161 auto boundaryNodes = graph->GetBoundaryNodeMap();
2162 auto boundaryNodesHost = Kokkos::create_mirror_view(boundaryNodes);
2163 Kokkos::deep_copy(boundaryNodesHost, boundaryNodes);
2164 bool allNodesAreOnBoundary = true;
2165 for (LO i = 0; i < Teuchos::as<LO>(boundaryNodesHost.size()); i++)
2166 allNodesAreOnBoundary &= boundaryNodesHost(i);
2167 TEST_EQUALITY(allNodesAreOnBoundary, true);
2168 }
2169
2170 // {
2171 // Level fineLevel;
2172 // TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
2173
2174 // mtx->SetFixedBlockSize(2);
2175 // fineLevel.Set("A", mtx);
2176
2177 // CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
2178 // RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
2179 // dropFact.SetFactory("UnAmalgamationInfo",amalgFact);
2180 // dropFact.SetParameter("aggregation: drop tol",Teuchos::ParameterEntry(4.1));
2181 // fineLevel.Request("Graph", &dropFact);
2182 // fineLevel.Request("DofsPerNode", &dropFact);
2183
2184 // dropFact.Build(fineLevel);
2185
2186 // RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos> >("Graph", &dropFact);
2187
2188 // auto boundaryNodes = graph->GetBoundaryNodeMap();
2189 // bool allNodesAreOnBoundary = true;
2190 // for (LO i = 0; i < Teuchos::as<LO>(boundaryNodes.size()); i++)
2191 // allNodesAreOnBoundary &= boundaryNodes[i];
2192 // TEST_EQUALITY(allNodesAreOnBoundary, true);
2193 // }
2194
2195 // {
2196 // Level fineLevel;
2197 // TestHelpers_kokkos::TestFactory<SC,LO,GO,NO>::createSingleLevelHierarchy(fineLevel);
2198
2199 // mtx->SetFixedBlockSize(3);
2200 // fineLevel.Set("A", mtx);
2201
2202 // CoalesceDropFactory_kokkos dropFact = CoalesceDropFactory_kokkos();
2203 // RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
2204 // dropFact.SetFactory("UnAmalgamationInfo",amalgFact);
2205 // dropFact.SetParameter("aggregation: drop tol",Teuchos::ParameterEntry(4.1));
2206 // fineLevel.Request("Graph", &dropFact);
2207 // fineLevel.Request("DofsPerNode", &dropFact);
2208
2209 // dropFact.Build(fineLevel);
2210
2211 // RCP<LWGraph_kokkos> graph = fineLevel.Get<RCP<LWGraph_kokkos> >("Graph", &dropFact);
2212
2213 // auto boundaryNodes = graph->GetBoundaryNodeMap();
2214 // bool allNodesAreOnBoundary = true;
2215 // for (LO i = 0; i < Teuchos::as<LO>(boundaryNodes.size()); i++)
2216 // allNodesAreOnBoundary &= boundaryNodes[i];
2217 // TEST_EQUALITY(allNodesAreOnBoundary, true);
2218 // }
2219
2220 } // AggresiveDroppingIsMarkedAsBoundary
2221
2222 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(CoalesceDropFactory_kokkos, 2x2, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
2223 #include <MueLu_UseShortNames.hpp>
2224 MUELU_TESTING_SET_OSTREAM;
2225 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
2226 out << "version: " << MueLu::Version() << std::endl;
2227
2228 RCP<const Teuchos::Comm<int>> comm = Parameters::getDefaultComm();
2229 Xpetra::UnderlyingLib lib = TestHelpers_kokkos::Parameters::getLib();
2230
2231 // Set up a 2x2 matrix.
2232 Teuchos::RCP<Matrix> mtx = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::build2x2(lib,
2233 2.0, -1.0,
2234 -1.5, 2.0);
2235 mtx->SetFixedBlockSize(1);
2236
2237 using magnitudeType = typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
2238 Teuchos::RCP<Xpetra::MultiVector<magnitudeType, LocalOrdinal, GlobalOrdinal, Node>> coords;
2239 coords = Xpetra::MultiVectorFactory<magnitudeType, LocalOrdinal, GlobalOrdinal, Node>::Build(mtx->getRowMap(), 1);
2240 {
2241 auto lclCoords = coords->getHostLocalView(Xpetra::Access::OverwriteAll);
2242 auto rank = comm->getRank();
2243 lclCoords(0, 0) = 2 * rank;
2244 lclCoords(1, 0) = 2 * rank + 1;
2245 }
2246
2247 using TF = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>;
2248 using local_matrix_type = typename Matrix::local_matrix_type::HostMirror;
2249
2250 std::vector<Teuchos::ParameterList> params;
2251 std::vector<local_matrix_type> expectedFilteredMatrices;
2252 std::vector<std::vector<bool>> expectedBoundaryNodesVector;
2253
2254 for (bool reuseGraph : {false, true}) {
2255 // test case 0
2256 Teuchos::ParameterList params0 = Teuchos::ParameterList();
2257 params0.set("aggregation: Dirichlet threshold", 0.);
2258 // dropFact.SetParameter("aggregation: row sum drop tol", Teuchos::ParameterEntry(0.2));
2259
2260 params0.set("aggregation: drop scheme", "classical");
2261 params0.set("aggregation: use ml scaling of drop tol", false);
2262 params0.set("aggregation: drop tol", 0.);
2263 params0.set("aggregation: dropping may create Dirichlet", false);
2264 params0.set("filtered matrix: reuse graph", reuseGraph);
2265 params0.set("filtered matrix: use lumping", false);
2266 params.push_back(params0);
2267 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, -1.0,
2268 -1.5, 2.0, reuseGraph));
2269 expectedBoundaryNodesVector.push_back({false, false});
2270
2271 // test case 1
2272 Teuchos::ParameterList params1 = Teuchos::ParameterList(params0);
2273 params1.set("aggregation: Dirichlet threshold", 0.2);
2274 params.push_back(params1);
2275 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, -1.0,
2276 -1.5, 2.0, reuseGraph));
2277 expectedBoundaryNodesVector.push_back({false, false});
2278
2279 // test case 2
2280 Teuchos::ParameterList params2 = Teuchos::ParameterList(params0);
2281 params2.set("aggregation: Dirichlet threshold", 1.1);
2282 params.push_back(params2);
2283 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, -1.0,
2284 -1.5, 2.0, reuseGraph));
2285 expectedBoundaryNodesVector.push_back({true, false});
2286
2287 // test case 3
2288 Teuchos::ParameterList params3 = Teuchos::ParameterList(params0);
2289 params3.set("aggregation: drop tol", 0.51);
2290 params.push_back(params3);
2291 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, 0.0,
2292 -1.5, 2.0, reuseGraph));
2293 expectedBoundaryNodesVector.push_back({false, false});
2294
2295 // test case 4
2296 Teuchos::ParameterList params4 = Teuchos::ParameterList(params0);
2297 params4.set("aggregation: Dirichlet threshold", 1.1);
2298 params4.set("aggregation: drop tol", 0.51);
2299 params.push_back(params4);
2300 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, 0.0,
2301 -1.5, 2.0, reuseGraph));
2302 expectedBoundaryNodesVector.push_back({true, false});
2303
2304 // test case 5
2305 Teuchos::ParameterList params5 = Teuchos::ParameterList(params0);
2306 params5.set("aggregation: Dirichlet threshold", 1.1);
2307 params5.set("aggregation: dropping may create Dirichlet", true);
2308 params5.set("aggregation: drop tol", 0.51);
2309 params.push_back(params5);
2310 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, 0.0,
2311 -1.5, 2.0, reuseGraph));
2312 expectedBoundaryNodesVector.push_back({true, false});
2313
2314 // test case 6
2315 Teuchos::ParameterList params6 = Teuchos::ParameterList(params4);
2316 params6.set("aggregation: Dirichlet threshold", 1.1);
2317 params6.set("filtered matrix: use lumping", true);
2318 params.push_back(params6);
2319 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(1.0, 0.0,
2320 -1.5, 2.0, reuseGraph));
2321 expectedBoundaryNodesVector.push_back({true, false});
2322
2323 // test case 7
2324 Teuchos::ParameterList params7 = Teuchos::ParameterList(params0);
2325 params7.set("aggregation: drop scheme", "distance laplacian");
2326 params0.set("aggregation: dropping may create Dirichlet", true);
2327 params.push_back(params7);
2328 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, -1.0,
2329 -1.5, 2.0, reuseGraph));
2330 expectedBoundaryNodesVector.push_back({false, false});
2331
2332 // test case 8
2333 Teuchos::ParameterList params8 = Teuchos::ParameterList(params0);
2334 params8.set("aggregation: drop scheme", "distance laplacian");
2335 params8.set("aggregation: drop tol", 1.01);
2336 params.push_back(params8);
2337 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, 0.0,
2338 0.0, 2.0, reuseGraph));
2339 expectedBoundaryNodesVector.push_back({true, true});
2340
2341 // test case 9
2342 Teuchos::ParameterList params9 = Teuchos::ParameterList(params0);
2343 params9.set("aggregation: drop scheme", "classical");
2344 params9.set("aggregation: classical algo", "unscaled cut");
2345 params9.set("aggregation: drop tol", 1.0 / 3.6);
2346 params.push_back(params9);
2347 expectedFilteredMatrices.push_back(TF::buildLocal2x2Host(2.0, -1.0,
2348 -1.5, 2.0, reuseGraph));
2349 expectedBoundaryNodesVector.push_back({false, false});
2350 }
2351
2352 for (size_t testNo = 0; testNo < params.size(); ++testNo) {
2353 out << "\n\nRunning test number " << testNo << std::endl
2354 << std::endl;
2355
2356 auto param = params[testNo];
2357 auto expectedFilteredMatrix = expectedFilteredMatrices[testNo];
2358 auto expectedBoundaryNodes = expectedBoundaryNodesVector[testNo];
2359
2360 for (bool useKokkos : {false, true}) {
2361 RCP<Matrix> filteredA;
2362 Kokkos::View<bool *, Kokkos::HostSpace> boundaryNodes;
2363 {
2364 Level fineLevel;
2365 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(fineLevel);
2366 fineLevel.Set("A", mtx);
2367 fineLevel.Set("Coordinates", coords);
2368
2369 RCP<MueLu::SingleLevelFactoryBase> dropFact;
2370 RCP<MueLu::SingleLevelFactoryBase> filteredAFact;
2371 if (useKokkos) {
2372 out << "\nKokkos code path\nparams:\n"
2373 << param << "\n";
2374 dropFact = rcp(new CoalesceDropFactory_kokkos());
2375 dropFact->SetParameterList(param);
2376 filteredAFact = dropFact;
2377 } else {
2378 out << "\nNon-Kokkos code path\nparams:\n"
2379 << param << "\n";
2380 dropFact = rcp(new CoalesceDropFactory());
2381 filteredAFact = rcp(new FilteredAFactory());
2382 auto paramCopy = Teuchos::ParameterList(param);
2383 auto paramFilteredA = Teuchos::ParameterList();
2384 paramFilteredA.set("filtered matrix: use lumping", paramCopy.get<bool>("filtered matrix: use lumping"));
2385 paramCopy.remove("filtered matrix: use lumping");
2386 paramFilteredA.set("filtered matrix: reuse graph", paramCopy.get<bool>("filtered matrix: reuse graph"));
2387 paramCopy.remove("filtered matrix: reuse graph");
2388 paramFilteredA.set("filtered matrix: Dirichlet threshold", paramCopy.get<double>("aggregation: Dirichlet threshold"));
2389 dropFact->SetParameterList(paramCopy);
2390 filteredAFact->SetParameterList(paramFilteredA);
2391 filteredAFact->SetFactory("Graph", dropFact);
2392 filteredAFact->SetFactory("Filtering", dropFact);
2393 }
2394 fineLevel.Request("A", filteredAFact.get());
2395 fineLevel.Request("Graph", dropFact.get());
2396 fineLevel.Request("DofsPerNode", dropFact.get());
2397 dropFact->Build(fineLevel);
2398
2399 filteredA = fineLevel.Get<RCP<Matrix>>("A", filteredAFact.get());
2400
2401 if (useKokkos) {
2402 auto graph = fineLevel.Get<RCP<LWGraph_kokkos>>("Graph", dropFact.get());
2403 auto boundaryNodes_d = graph->GetBoundaryNodeMap();
2404 boundaryNodes = Kokkos::View<bool *, Kokkos::HostSpace>("boundaryNodes_host", boundaryNodes_d.extent(0));
2405 Kokkos::deep_copy(boundaryNodes, boundaryNodes_d);
2406 } else {
2407 auto graph = fineLevel.Get<RCP<LWGraph>>("Graph", dropFact.get());
2408 boundaryNodes = graph->GetBoundaryNodeMap();
2409 }
2410 }
2411
2412 auto lclFilteredA = filteredA->getLocalMatrixHost();
2413 auto lclExpectedFilteredA = expectedFilteredMatrix;
2414
2415 out << "Filtered A:\n"
2416 << TF::localMatToString(lclFilteredA);
2417
2418 TEST_EQUALITY(lclFilteredA.graph.row_map.extent(0), lclExpectedFilteredA.graph.row_map.extent(0));
2419 for (size_t row = 0; row < std::min(lclFilteredA.graph.row_map.extent(0), lclExpectedFilteredA.graph.row_map.extent(0)); ++row)
2420 TEST_EQUALITY(lclFilteredA.graph.row_map(row), lclExpectedFilteredA.graph.row_map(row));
2421
2422 TEST_EQUALITY(lclFilteredA.graph.entries.extent(0), lclExpectedFilteredA.graph.entries.extent(0));
2423 for (size_t entry = 0; entry < std::min(lclFilteredA.graph.entries.extent(0), lclExpectedFilteredA.graph.entries.extent(0)); ++entry) {
2424 TEST_EQUALITY(lclFilteredA.graph.entries(entry), lclExpectedFilteredA.graph.entries(entry));
2425 TEST_EQUALITY(lclFilteredA.values(entry), lclExpectedFilteredA.values(entry));
2426 }
2427
2428 auto boundaryNodes_h = Kokkos::create_mirror_view(boundaryNodes);
2429 Kokkos::deep_copy(boundaryNodes_h, boundaryNodes);
2430 TEST_EQUALITY(boundaryNodes_h.extent(0), expectedBoundaryNodes.size());
2431 for (size_t row = 0; row < std::min(boundaryNodes_h.extent(0), expectedBoundaryNodes.size()); ++row)
2432 TEST_EQUALITY(boundaryNodes_h(row), expectedBoundaryNodes[row]);
2433 }
2434 out << "Done with test number " << testNo << std::endl;
2435 }
2436 }
2437
2438 #define MUELU_ETI_GROUP(SC, LO, GO, NO) \
2439 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, Constructor, SC, LO, GO, NO) \
2440 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, Build, SC, LO, GO, NO) \
2441 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacian, SC, LO, GO, NO) \
2442 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianScaledCut, SC, LO, GO, NO) \
2443 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianUnscaledCut, SC, LO, GO, NO) \
2444 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianCutSym, SC, LO, GO, NO) \
2445 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianScalarMaterial, SC, LO, GO, NO) \
2446 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianTensorMaterial, SC, LO, GO, NO) \
2447 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicalScaledCut, SC, LO, GO, NO) \
2448 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicalUnScaledCut, SC, LO, GO, NO) \
2449 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicalCutSym, SC, LO, GO, NO) \
2450 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, SignedClassical, SC, LO, GO, NO) \
2451 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, SignedScaledCutClassical, SC, LO, GO, NO) \
2452 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, SignedUnscaledCutClassical, SC, LO, GO, NO) \
2453 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonalColoredSignedClassical, SC, LO, GO, NO) \
2454 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonalNoColoredSignedClassical, SC, LO, GO, NO) \
2455 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonalSignedClassical, SC, LO, GO, NO) \
2456 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonal, SC, LO, GO, NO) \
2457 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonalDistanceLaplacian, SC, LO, GO, NO) \
2458 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, BlockDiagonalDistanceLaplacianWeighted, SC, LO, GO, NO) \
2459 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, DistanceLaplacianWeighted, SC, LO, GO, NO) \
2460 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, SignedClassicalSA, SC, LO, GO, NO) \
2461 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicScalarWithoutFiltering, SC, LO, GO, NO) \
2462 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicScalarWithFiltering, SC, LO, GO, NO) \
2463 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicBlockWithoutFiltering, SC, LO, GO, NO) \
2464 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, AggresiveDroppingIsMarkedAsBoundary, SC, LO, GO, NO) \
2465 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, 2x2, SC, LO, GO, NO)
2466
2467 // TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(CoalesceDropFactory_kokkos, ClassicBlockWithFiltering, SC, LO, GO, NO) // not implemented yet
2468
2469 #include <MueLu_ETI_4arg.hpp>
2470
2471 } // namespace MueLuTests