Debian Codegraph @

packages/muelu/test/unit_tests_kokkos/AmalgamationInfo_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 <Teuchos_ScalarTraits.hpp>
12
13 #include <MueLu_config.hpp>
14
15 #include "MueLu_TestHelpers_kokkos.hpp"
16 #include <MueLu_Version.hpp>
17
18 #include "MueLu_Level.hpp"
19
20 #include <MueLu_AmalgamationInfo.hpp>
21 #include "MueLu_Aggregates.hpp"
22 #include "MueLu_AmalgamationFactory.hpp"
23 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
24
25 namespace MueLuTests {
26
27 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(AmalgamationInfo_kokkos, Constructor, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
28 #include <MueLu_UseShortNames.hpp>
29 MUELU_TESTING_SET_OSTREAM;
30 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
31 out << "version: " << MueLu::Version() << std::endl;
32 LO fullblocksize = 1; // block dim for fixed size blocks
33 GO offset = 0; // global offset of dof gids
34 LO blockid = -1; // block id in strided map
35 LO nStridedOffset = 0; // DOF offset for strided block id "blockid" (default = 0)
36 LO stridedblocksize = fullblocksize; // size of strided block id "blockid" (default = fullblocksize, only if blockid!=-1 stridedblocksize <= fullblocksize)
37
38 const GO nx = 199;
39 using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>;
40 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(nx);
41
42 RCP<AmalgamationInfo> amalgamationData;
43 RCP<Array<LO> > theRowTranslation = rcp(new Array<LO>);
44 RCP<Array<LO> > theColTranslation = rcp(new Array<LO>);
45
46 RCP<AmalgamationInfo> amalgamationInfo_kokkos = rcp(new AmalgamationInfo(theRowTranslation,
47 theColTranslation,
48 A->getRowMap(),
49 A->getColMap(),
50 A->getColMap(),
51 fullblocksize,
52 offset,
53 blockid,
54 nStridedOffset,
55 stridedblocksize));
56 TEST_INEQUALITY(amalgamationInfo_kokkos, Teuchos::null);
57
58 TEST_EQUALITY(amalgamationInfo_kokkos->description(), "AmalgamationInfo");
59 LO fullBlockSizeExpected;
60 LO blockIDExpected;
61 LO stridingOffsetExpected;
62 LO stridedBlockSizeExpected;
63 GO indexBaseExpected;
64 amalgamationInfo_kokkos->GetStridingInformation(fullBlockSizeExpected, blockIDExpected, stridingOffsetExpected, stridedBlockSizeExpected, indexBaseExpected);
65 TEST_EQUALITY(fullBlockSizeExpected == fullblocksize, true);
66 TEST_EQUALITY(blockIDExpected == blockid, true);
67 TEST_EQUALITY(stridingOffsetExpected == nStridedOffset, true);
68 TEST_EQUALITY(stridedBlockSizeExpected == stridedblocksize, true);
69 TEST_EQUALITY(indexBaseExpected == A->getColMap()->getIndexBase(), true);
70
71 TEST_EQUALITY(amalgamationInfo_kokkos->getNodeRowMap() == A->getRowMap(), true);
72 TEST_EQUALITY(amalgamationInfo_kokkos->getNodeColMap() == A->getColMap(), true);
73 TEST_EQUALITY(amalgamationInfo_kokkos->getRowTranslation() == theRowTranslation, true);
74 TEST_EQUALITY(amalgamationInfo_kokkos->getColTranslation() == theColTranslation, true);
75 TEST_EQUALITY(amalgamationInfo_kokkos->GlobalOffset() == offset, true);
76
77 } // Constructor
78
79 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(AmalgamationInfo_kokkos, UnamalgateAggregate, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
80 #include <MueLu_UseShortNames.hpp>
81 MUELU_TESTING_SET_OSTREAM;
82 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
83 out << "version: " << MueLu::Version() << std::endl;
84 LO fullblocksize = 1; // block dim for fixed size blocks
85 GO offset = 0; // global offset of dof gids
86 LO blockid = -1; // block id in strided map
87 LO nStridedOffset = 0; // DOF offset for strided block id "blockid" (default = 0)
88 LO stridedblocksize = fullblocksize; // size of strided block id "blockid" (default = fullblocksize, only if blockid!=-1 stridedblocksize <= fullblocksize)
89
90 const GO nx = 199;
91 using test_factory = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>;
92 RCP<Matrix> A = TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::Build1DPoisson(nx);
93
94 RCP<AmalgamationInfo> amalgamationData;
95 RCP<Array<LO> > theRowTranslation = rcp(new Array<LO>);
96 RCP<Array<LO> > theColTranslation = rcp(new Array<LO>);
97
98 RCP<AmalgamationInfo> amalgamationInfo_kokkos = rcp(new AmalgamationInfo(theRowTranslation,
99 theColTranslation,
100 A->getRowMap(),
101 A->getColMap(),
102 A->getColMap(),
103 fullblocksize,
104 offset,
105 blockid,
106 nStridedOffset,
107 stridedblocksize));
108
109 RCP<AmalgamationFactory> amalgFact = rcp(new AmalgamationFactory());
110 RCP<CoalesceDropFactory_kokkos> dropFact = rcp(new CoalesceDropFactory_kokkos());
111 dropFact->SetFactory("UnAmalgamationInfo", amalgFact);
112
113 RCP<LWGraph_kokkos> graph;
114 Level level;
115 TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::createSingleLevelHierarchy(level);
116 level.Set("A", A);
117 level.Request("Graph", dropFact.get());
118 level.Request(*dropFact);
119 dropFact->Build(level);
120 graph = level.Get<RCP<LWGraph_kokkos> >("Graph", dropFact.get());
121 RCP<Aggregates> aggregates = rcp(new Aggregates(*graph));
122 GO numAggs = aggregates->GetNumAggregates();
123 ArrayRCP<LO> aggSizes = Teuchos::ArrayRCP<LO>(numAggs);
124 ArrayRCP<LO> aggStart;
125 ArrayRCP<GO> aggToRowMap;
126 amalgamationInfo_kokkos->UnamalgamateAggregates(*aggregates, aggStart, aggToRowMap);
127
128 } // UnamalgateAggregate
129
130 #define MUELU_ETI_GROUP(Scalar, LO, GO, Node) \
131 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(AmalgamationInfo_kokkos, Constructor, Scalar, LO, GO, Node) \
132 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(AmalgamationInfo_kokkos, UnamalgateAggregate, Scalar, LO, GO, Node)
133
134 #include <MueLu_ETI_4arg.hpp>
135
136 } // namespace MueLuTests