Debian Codegraph @

packages/muelu/test/unit_tests_kokkos/IndexManager_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_DefaultComm.hpp>
12
13 #include "MueLu_TestHelpers_kokkos.hpp"
14 #include "MueLu_Version.hpp"
15
16 #include "MueLu_Level.hpp"
17 #include "MueLu_FactoryManagerBase.hpp"
18 #include "MueLu_IndexManager_kokkos.hpp"
19
20 namespace MueLuTests {
21
22 template <class IndexManager_type, class LO>
23 struct testFunctor {
24 IndexManager_type IndexManager;
25
26 testFunctor(RCP<IndexManager_type> myIM)
27 : IndexManager(*myIM) {}
28
29 KOKKOS_INLINE_FUNCTION
30 void operator()(const LO& LID) const {
31 LO fineNodeTuple[3];
32 IndexManager.getFineLID2FineTuple(LID, fineNodeTuple);
33 printf("LID=%d --> (i,j,k)=(%d, %d, %d)\n", static_cast<int>(LID),
34 static_cast<int>(fineNodeTuple[0]),
35 static_cast<int>(fineNodeTuple[1]),
36 static_cast<int>(fineNodeTuple[2]));
37 }
38 };
39
40 TEUCHOS_UNIT_TEST_TEMPLATE_4_DECL(IndexManager_kokkos, IndexManager, Scalar, LocalOrdinal, GlobalOrdinal, Node) {
41 #include "MueLu_UseShortNames.hpp"
42 MUELU_TESTING_SET_OSTREAM;
43 MUELU_TESTING_LIMIT_SCOPE(Scalar, GlobalOrdinal, Node);
44
45 out << "version: " << MueLu::Version() << std::endl;
46 RCP<Teuchos::FancyOStream> fout = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
47 fout->setShowAllFrontMatter(false).setShowProcRank(true);
48
49 typedef typename Teuchos::ScalarTraits<SC>::magnitudeType real_type;
50 typedef Xpetra::MultiVector<real_type, LO, GO, NO> RealValuedMultiVector;
51
52 RCP<const Teuchos::Comm<int> > comm = MueLuTests::TestHelpers_kokkos::Parameters::getDefaultComm();
53
54 // Set global geometric data
55 const int numDimensions = 3;
56 const int interpolationOrder = 0;
57 Array<GO> meshData;
58 Array<GO> gNodesPerDir(3);
59 Array<LO> lNodesPerDir(3);
60 Array<LO> coarseRate(3);
61 for (int dim = 0; dim < 3; ++dim) {
62 if (dim < numDimensions) {
63 // Use more nodes in 1D to have a reasonable number of nodes per procs
64 gNodesPerDir[dim] = 5;
65 coarseRate[dim] = 2;
66 } else {
67 gNodesPerDir[dim] = -1;
68 coarseRate[dim] = 1;
69 }
70 }
71
72 RCP<RealValuedMultiVector> coords =
73 MueLuTests::TestHelpers_kokkos::TestFactory<SC, LO, GO, NO>::BuildGeoCoordinates(numDimensions,
74 gNodesPerDir,
75 lNodesPerDir,
76 meshData,
77 "Local Lexicographic");
78
79 std::cout << "Hello!" << std::endl;
80 RCP<IndexManager_kokkos> myIndexManager = rcp(new IndexManager_kokkos(numDimensions,
81 interpolationOrder,
82 comm->getRank(),
83 lNodesPerDir,
84 coarseRate));
85
86 using execution_space = typename IndexManager_kokkos::execution_space;
87 using memory_space = typename IndexManager_kokkos::memory_space;
88 using device_type = typename IndexManager_kokkos::device_type;
89
90 Kokkos::fence();
91 std::cout << "Allocate host views before performing checks" << std::endl;
92
93 typename Kokkos::View<const int[3], device_type>::HostMirror coarseRate_h = Kokkos::create_mirror_view(myIndexManager->getCoarseningRates());
94 Kokkos::deep_copy(coarseRate_h, myIndexManager->getCoarseningRates());
95
96 typename Kokkos::View<LO[3], device_type>::HostMirror lFineNodesPerDir_h = Kokkos::create_mirror_view(myIndexManager->getLocalFineNodesPerDir());
97 Kokkos::deep_copy(lFineNodesPerDir_h, myIndexManager->getLocalFineNodesPerDir());
98
99 typename Kokkos::View<LO[3], device_type>::HostMirror lCoarseNodesPerDir_h = Kokkos::create_mirror_view(myIndexManager->getCoarseNodesPerDir());
100 Kokkos::deep_copy(lCoarseNodesPerDir_h, myIndexManager->getCoarseNodesPerDir());
101
102 Kokkos::fence();
103 std::cout << "Start checking process" << std::endl;
104
105 int chk = 0;
106 if (myIndexManager->getInterpolationOrder() != interpolationOrder) {
107 chk = -1;
108 }
109 if (myIndexManager->getNumDimensions() != numDimensions) {
110 chk = -1;
111 }
112 for (int dim = 0; dim < 3; ++dim) {
113 if (coarseRate_h(dim) != coarseRate[dim]) {
114 chk = -1;
115 }
116 }
117 if (comm->getSize() == 1) {
118 if (myIndexManager->getNumLocalFineNodes() != 125) {
119 chk = -1;
120 }
121 if (myIndexManager->getNumCoarseNodes() != 27) {
122 chk = -1;
123 }
124 for (int dim = 0; dim < 3; ++dim) {
125 if (lFineNodesPerDir_h(dim) != lNodesPerDir[dim]) {
126 chk = -1;
127 }
128 if (lCoarseNodesPerDir_h(dim) != 3) {
129 chk = -1;
130 }
131 }
132
133 } else if (comm->getSize() == 4) {
134 if (comm->getRank() == 0) {
135 if (myIndexManager->getNumLocalFineNodes() != 45) {
136 chk = -1;
137 }
138 if (myIndexManager->getNumCoarseNodes() != 12) {
139 chk = -1;
140 }
141 LO lFNPD[3] = {3, 3, 5};
142 LO lCNPD[3] = {2, 2, 3};
143 for (int dim = 0; dim < 3; ++dim) {
144 if (lFineNodesPerDir_h(dim) != lFNPD[dim]) {
145 chk = -1;
146 }
147 if (lCoarseNodesPerDir_h(dim) != lCNPD[dim]) {
148 chk = -1;
149 }
150 }
151 } else if (comm->getRank() == 1) {
152 if (myIndexManager->getNumLocalFineNodes() != 30) {
153 chk = -1;
154 }
155 if (myIndexManager->getNumCoarseNodes() != 12) {
156 chk = -1;
157 }
158 LO lFNPD[3] = {2, 3, 5};
159 LO lCNPD[3] = {2, 2, 3};
160 for (int dim = 0; dim < 3; ++dim) {
161 if (lFineNodesPerDir_h(dim) != lFNPD[dim]) {
162 chk = -1;
163 }
164 if (lCoarseNodesPerDir_h(dim) != lCNPD[dim]) {
165 chk = -1;
166 }
167 }
168 } else if (comm->getRank() == 2) {
169 if (myIndexManager->getNumLocalFineNodes() != 30) {
170 chk = -1;
171 }
172 if (myIndexManager->getNumCoarseNodes() != 12) {
173 chk = -1;
174 }
175 LO lFNPD[3] = {3, 2, 5};
176 LO lCNPD[3] = {2, 2, 3};
177 for (int dim = 0; dim < 3; ++dim) {
178 if (lFineNodesPerDir_h(dim) != lFNPD[dim]) {
179 chk = -1;
180 }
181 if (lCoarseNodesPerDir_h(dim) != lCNPD[dim]) {
182 chk = -1;
183 }
184 }
185 } else if (comm->getRank() == 3) {
186 if (myIndexManager->getNumLocalFineNodes() != 20) {
187 chk = -1;
188 }
189 if (myIndexManager->getNumCoarseNodes() != 12) {
190 chk = -1;
191 }
192 LO lFNPD[3] = {2, 2, 5};
193 LO lCNPD[3] = {2, 2, 3};
194 for (int dim = 0; dim < 3; ++dim) {
195 if (lFineNodesPerDir_h(dim) != lFNPD[dim]) {
196 chk = -1;
197 }
198 if (lCoarseNodesPerDir_h(dim) != lCNPD[dim]) {
199 chk = -1;
200 }
201 }
202 }
203 }
204
205 int gbl_chk[1] = {0};
206 Teuchos::reduceAll(*comm, Teuchos::REDUCE_SUM, 1, &chk, gbl_chk);
207 TEST_EQUALITY(gbl_chk[0], 0);
208
209 std::cout << "Testing UIM methods call from device." << std::endl;
210
211 testFunctor<IndexManager_kokkos, LO> myTestFunctor(myIndexManager);
212 Kokkos::parallel_for("test UIM::getFineLID2FineTuple()",
213 Kokkos::RangePolicy<execution_space>(0, 125),
214 myTestFunctor);
215 } // Uncoupled
216
217 #ifdef HAVE_MUELU_SYCL
218 // Enabling this w/ SYCL yields the error "SYCL kernel cannot call a variadic function"
219 #define MUELU_ETI_GROUP(SC, LO, GO, NO)
220 #else
221 #define MUELU_ETI_GROUP(SC, LO, GO, NO) \
222 TEUCHOS_UNIT_TEST_TEMPLATE_4_INSTANT(IndexManager_kokkos, IndexManager, SC, LO, GO, NO)
223 #endif
224
225 #include <MueLu_ETI_4arg.hpp>
226
227 } // namespace MueLuTests