MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_StructuredRAPFactory_def.hpp
Go to the documentation of this file.
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#ifndef MUELU_STRUCTUREDRAPFACTORY_DEF_HPP
11#define MUELU_STRUCTUREDRAPFACTORY_DEF_HPP
12
13#include <cstdint>
14#include <sstream>
15#include <vector>
16
17#include <Kokkos_Core.hpp>
18
19#include <Xpetra_Matrix.hpp>
20#include <Xpetra_MatrixUtils.hpp>
21#include <Xpetra_MatrixFactory.hpp>
22#include <Xpetra_TripleMatrixMultiply.hpp>
23#include <Xpetra_CrsGraphFactory.hpp>
24#include <Xpetra_CrsGraph.hpp>
25#include <Xpetra_MapFactory.hpp>
26
29
30#include "MueLu_MasterList.hpp"
31#include "MueLu_NoFactory.hpp"
32#include "MueLu_Monitor.hpp"
33#include "MueLu_PerfUtils.hpp"
34#include "MueLu_Behavior.hpp"
36#include "Teuchos_TestForException.hpp"
37#include "Teuchos_CommHelpers.hpp"
38
39namespace MueLu {
40
42
43template <class GO, class LocalNodes>
44KOKKOS_INLINE_FUNCTION void getLocalNodeIndices(const GO localNode,
45 const LocalNodes& localNodes,
46 GO& x, GO& y, GO& z) {
47 x = localNode % localNodes[0];
48 y = (localNode / localNodes[0]) % localNodes[1];
49 z = localNode / (localNodes[0] * localNodes[1]);
50}
51
52template <class GO, class Offset, class LocalNodes, class ProcGrid, class RankData>
53KOKKOS_INLINE_FUNCTION bool resolveNeighbor(const GO x, const GO y, const GO z,
54 const Offset& offset,
55 const LocalNodes& localNodes,
56 const ProcGrid& procGrid,
57 const RankData& rankData,
58 const int myProcX,
59 const int myProcY,
60 const int myProcZ,
61 int& neighborRank,
62 GO& neighborNode) {
63 int neighborProcX = myProcX;
64 int neighborProcY = myProcY;
65 int neighborProcZ = myProcZ;
66 GO neighborX = x + static_cast<GO>(offset.x);
67 GO neighborY = y + static_cast<GO>(offset.y);
68 GO neighborZ = z + static_cast<GO>(offset.z);
69
70 if (neighborX < 0)
71 --neighborProcX;
72 else if (neighborX >= localNodes[0])
73 ++neighborProcX;
74 if (neighborY < 0)
75 --neighborProcY;
76 else if (neighborY >= localNodes[1])
77 ++neighborProcY;
78 if (neighborZ < 0)
79 --neighborProcZ;
80 else if (neighborZ >= localNodes[2])
81 ++neighborProcZ;
82
83 if (neighborProcX < 0 || neighborProcX >= procGrid[0] ||
84 neighborProcY < 0 || neighborProcY >= procGrid[1] ||
85 neighborProcZ < 0 || neighborProcZ >= procGrid[2])
86 return false;
87
88 neighborRank = neighborProcZ * procGrid[0] * procGrid[1] + neighborProcY * procGrid[0] + neighborProcX;
89 const GO neighborLocalNx = rankData(4 * neighborRank + 1);
90 const GO neighborLocalNy = rankData(4 * neighborRank + 2);
91 const GO neighborLocalNz = rankData(4 * neighborRank + 3);
92 if (neighborX < 0)
93 neighborX = neighborLocalNx - 1;
94 else if (neighborX >= localNodes[0])
95 neighborX = 0;
96 if (neighborY < 0)
97 neighborY = neighborLocalNy - 1;
98 else if (neighborY >= localNodes[1])
99 neighborY = 0;
100 if (neighborZ < 0)
101 neighborZ = neighborLocalNz - 1;
102 else if (neighborZ >= localNodes[2])
103 neighborZ = 0;
104
105 neighborNode = rankData(4 * neighborRank) +
106 neighborZ * neighborLocalNx * neighborLocalNy +
107 neighborY * neighborLocalNx + neighborX;
108 return true;
109}
110
111} // namespace StructuredRAPFactoryDetails
112
113template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
117
118template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
120 RCP<ParameterList> validParamList = rcp(new ParameterList());
121 // If no triple product implementation is prescribed, use the structured kernel by default.
122 validParamList->set<std::string>(
123 "rap: triple product implementation", "structured",
124 "Implementation used with a prebuilt coarse graph: unstructured or structured.");
125
126#define SET_VALID_ENTRY(name) validParamList->setEntry(name, MasterList::getEntry(name))
127 SET_VALID_ENTRY("rap: triple product"); // in the long term this has to be the only option for multiplication
128 SET_VALID_ENTRY("rap: prebuild coarse graph"); // if true, the coarse graph is prebuilt and passed to the triple matrix product kernel. This can be used to optimize the symbolic phase of the triple matrix product.
129 SET_VALID_ENTRY("rap: fix zero diagonals");
130 SET_VALID_ENTRY("rap: fix zero diagonals threshold");
131 SET_VALID_ENTRY("rap: fix zero diagonals replacement");
132 SET_VALID_ENTRY("rap: relative diagonal floor");
133#undef SET_VALID_ENTRY
134 validParamList->set<bool>(
135 "transpose: use implicit", true,
136 "Use P^T as the restriction operator. StructuredRAPFactory requires this option to be true.");
137 validParamList->set<RCP<const FactoryBase>>("A", null, "Generating factory of the matrix A used during the prolongator smoothing process");
138 validParamList->set<RCP<const FactoryBase>>("P", null, "Prolongator factory");
139 validParamList->set<RCP<const FactoryBase>>("numDimensions", null, "Number of spatial dimensions.");
140 validParamList->set<RCP<const FactoryBase>>("lNodesPerDim", null, "Local number of fine-grid nodes per spatial dimension.");
141 validParamList->set<RCP<const FactoryBase>>("lCoarseNodesPerDim", null, "Local number of coarse-grid nodes per spatial dimension.");
142 validParamList->set<RCP<const FactoryBase>>("structuredInterpolationOrder", null, "Interpolation order used to construct the structured prolongator.");
143
144 validParamList->set<bool>("CheckMainDiagonal", false, "Check main diagonal for zeros");
145 validParamList->set<bool>("RepairMainDiagonal", false, "Repair zeros on main diagonal");
146
147 // Make sure we don't recursively validate options for the matrixmatrix kernels
148 ParameterList norecurse;
149 norecurse.disableRecursiveValidation();
150 validParamList->set<ParameterList>("matrixmatrix: kernel params", norecurse, "MatrixMatrix kernel parameters");
151
152 return validParamList;
153}
154
155// Configure RAPFactory to delegate to if coarse graph prebuilding is disabled
156template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
158 const Teuchos::ParameterList& pL = GetParameterList();
159
160 ParameterList rapParams;
161 RCP<const ParameterList> validRAPParams = rapFactoryDelegate_->GetValidParameterList();
162 for (ParameterList::ConstIterator it = validRAPParams->begin(); it != validRAPParams->end(); ++it) {
163 const std::string& paramName = validRAPParams->name(it);
164 if (pL.isParameter(paramName))
165 rapParams.setEntry(paramName, pL.getEntry(paramName));
166 else if (pL.isSublist(paramName))
167 rapParams.sublist(paramName) = pL.sublist(paramName);
168 }
169
170 rapFactoryDelegate_->SetParameterList(rapParams);
171 rapFactoryDelegate_->SetFactory("A", GetFactory("A"));
172 rapFactoryDelegate_->SetFactory("P", GetFactory("P"));
173}
174
175template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
176RCP<const FactoryBase>
178 // Used to get lCoarseNodesPerDim and structuredInterpolationOrder from the prolongator factory
179 const std::string& varName) const {
180 const RCP<const Factory> pFactory =
181 rcp_dynamic_cast<const Factory>(GetFactory("P"));
182 if (!pFactory.is_null()) {
183 const RCP<const FactoryBase> metadataFactory = pFactory->GetFactory(varName);
184 if (!metadataFactory.is_null())
185 return metadataFactory;
186 }
187
188 return GetFactory(varName);
189}
190
191template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
193 const Teuchos::ParameterList& pL = GetParameterList();
194 TEUCHOS_TEST_FOR_EXCEPTION(
195 !pL.get<bool>("transpose: use implicit"), Exceptions::RuntimeError,
196 "StructuredRAPFactory requires \"transpose: use implicit\" = true because "
197 "the prebuilt coarse graph assumes the Galerkin product P^T A P.");
198
199 const bool useRAPDelegate =
200 !pL.get<bool>("rap: prebuild coarse graph");
201
202 if (useRAPDelegate) {
204 coarseLevel.DeclareInput("A", rapFactoryDelegate_.get(), this);
205 coarseLevel.DeclareInput("RAP reuse data", rapFactoryDelegate_.get(), this);
206 hasDeclaredInput_ = true;
207 return;
208 }
209
210 Input(fineLevel, "A");
211 Input(coarseLevel, "P");
212
213 const RCP<const FactoryBase> coarseDimensionsFactory =
214 GetStructuredMetadataFactory("lCoarseNodesPerDim");
215 const RCP<const FactoryBase> interpolationOrderFactory =
216 GetStructuredMetadataFactory("structuredInterpolationOrder");
217 fineLevel.DeclareInput("lCoarseNodesPerDim", coarseDimensionsFactory.get(), this);
218 fineLevel.DeclareInput("structuredInterpolationOrder", interpolationOrderFactory.get(), this);
219 if (fineLevel.GetLevelID() == 0) {
220 TEUCHOS_TEST_FOR_EXCEPTION(!fineLevel.IsAvailable("numDimensions", NoFactory::get()),
222 "StructuredRAPFactory: numDimensions was not provided on level 0.");
223 TEUCHOS_TEST_FOR_EXCEPTION(!fineLevel.IsAvailable("lNodesPerDim", NoFactory::get()),
225 "StructuredRAPFactory: lNodesPerDim was not provided on level 0.");
226 fineLevel.DeclareInput("numDimensions", NoFactory::get(), this);
227 fineLevel.DeclareInput("lNodesPerDim", NoFactory::get(), this);
228 } else {
229 Input(fineLevel, "numDimensions");
230 Input(fineLevel, "lNodesPerDim");
231 }
232
233 // call DeclareInput of all user-given transfer factories
234 for (std::vector<RCP<const FactoryBase>>::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it)
235 (*it)->CallDeclareInput(coarseLevel);
236
237 hasDeclaredInput_ = true;
238}
239
240// Infer the fine-grid stencil of A from one representative interior node
241template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
244 const Matrix& A, const int numDimensions,
245 const Teuchos::Array<LocalOrdinal>& lFineNodesPerDim) const {
246 const std::string prefix = "StructuredRAPFactory::DetectFineStencil: ";
247
248 TEUCHOS_TEST_FOR_EXCEPTION(numDimensions < 1 || numDimensions > 3, Exceptions::RuntimeError,
249 prefix << "the number of dimensions must be between one and three.");
250 TEUCHOS_TEST_FOR_EXCEPTION(lFineNodesPerDim.size() < numDimensions, Exceptions::RuntimeError,
251 prefix << "insufficient fine-grid dimensions were supplied.");
252
253 const auto rowMap = A.getRowMap();
254 const auto colMap = A.getColMap();
255 const auto comm = rowMap->getComm();
256 const auto graph = A.getCrsGraph();
257 TEUCHOS_TEST_FOR_EXCEPTION(graph.is_null(), Exceptions::RuntimeError,
258 prefix << "A does not expose a CRS graph.");
259
260 const LO dofsPerNode = Teuchos::as<LO>(A.GetFixedBlockSize());
261 TEUCHOS_TEST_FOR_EXCEPTION(dofsPerNode <= 0, Exceptions::RuntimeError,
262 prefix << "A must have a positive fixed block size.");
263
264 Kokkos::Array<LO, 3> fineNodes{{LO(1), LO(1), LO(1)}};
265 Kokkos::Array<LO, 3> interior{{LO(0), LO(0), LO(0)}};
266 size_t numFineNodes = 1;
267 bool hasLocalInterior = true;
268 // Select interior node in the local subdomain as a representative node for detecting the fine-grid stencil
269 for (int dim = 0; dim < numDimensions; ++dim) {
270 fineNodes[dim] = lFineNodesPerDim[dim];
271 hasLocalInterior = hasLocalInterior && fineNodes[dim] >= LO(3);
272 if (fineNodes[dim] > LO(0)) {
273 interior[dim] = fineNodes[dim] / LO(2);
274 numFineNodes *= Teuchos::as<size_t>(fineNodes[dim]);
275 } else {
276 numFineNodes = 0;
277 }
278 }
279
280 const bool localDimensionsMatch =
281 rowMap->getLocalNumElements() ==
282 numFineNodes * Teuchos::as<size_t>(dofsPerNode);
283 int invalidLocalDimensions = localDimensionsMatch ? 0 : 1;
284 int invalidDimensions = 0;
285 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MAX, 1,
286 &invalidLocalDimensions, &invalidDimensions);
287 TEUCHOS_TEST_FOR_EXCEPTION(
288 invalidDimensions != 0, Exceptions::RuntimeError,
289 prefix << "the structured local dimensions and fixed block size do not match A on every rank.");
290
291 const LO interiorNode = interior[2] * fineNodes[0] * fineNodes[1] +
292 interior[1] * fineNodes[0] + interior[0];
293
294 const auto localA = A.getLocalMatrixDevice();
295 const LO invalidLocalOrdinal = Teuchos::OrdinalTraits<LO>::invalid();
296 std::vector<std::vector<LO>> ownedColumns(
297 Teuchos::as<size_t>(dofsPerNode));
298 bool hasCompleteLocalStencil = hasLocalInterior;
299 if (hasLocalInterior) {
300 const size_t firstRow = Teuchos::as<size_t>(interiorNode * dofsPerNode);
301 const auto detectedRowMap = Kokkos::subview(
302 localA.graph.row_map,
303 std::make_pair(firstRow,
304 firstRow + Teuchos::as<size_t>(dofsPerNode) + 1));
305 const auto detectedRowMapHost = Kokkos::create_mirror_view_and_copy(
306 Kokkos::HostSpace(), detectedRowMap);
307 const size_t firstEntry = detectedRowMapHost(0);
308 const size_t lastEntry =
309 detectedRowMapHost(Teuchos::as<size_t>(dofsPerNode));
310 const auto detectedEntries = Kokkos::subview(
311 localA.graph.entries, std::make_pair(firstEntry, lastEntry));
312 using device_type = typename Node::device_type;
313 using execution_space = typename device_type::execution_space;
314 Kokkos::View<LO*, device_type> detectedOwnedColumns(
315 Kokkos::ViewAllocateWithoutInitializing(
316 "StructuredRAP: detected owned columns"),
317 lastEntry - firstEntry);
318 const auto rowLocalMap = rowMap->getLocalMap();
319 const auto colLocalMap = colMap->getLocalMap();
320 Kokkos::parallel_for(
321 "StructuredRAP: map detected stencil columns",
322 Kokkos::RangePolicy<execution_space>(0, lastEntry - firstEntry),
323 KOKKOS_LAMBDA(const size_t entry) {
324 const GO globalColumn =
325 colLocalMap.getGlobalElement(detectedEntries(entry));
326 detectedOwnedColumns(entry) =
327 rowLocalMap.getLocalElement(globalColumn);
328 });
329 const auto detectedOwnedColumnsHost =
330 Kokkos::create_mirror_view_and_copy(
331 Kokkos::HostSpace(), detectedOwnedColumns);
332
333 for (LO rowDof = 0; rowDof < dofsPerNode; ++rowDof) {
334 const size_t rowBegin = detectedRowMapHost(Teuchos::as<size_t>(rowDof));
335 const size_t rowEnd =
336 detectedRowMapHost(Teuchos::as<size_t>(rowDof) + 1);
337 if (rowBegin == rowEnd)
338 hasCompleteLocalStencil = false;
339 auto& rowColumns = ownedColumns[Teuchos::as<size_t>(rowDof)];
340 rowColumns.reserve(rowEnd - rowBegin);
341 for (size_t entry = rowBegin; entry < rowEnd; ++entry) {
342 const LO ownedColumn =
343 detectedOwnedColumnsHost(entry - firstEntry);
344 rowColumns.push_back(ownedColumn);
345 if (ownedColumn == invalidLocalOrdinal)
346 hasCompleteLocalStencil = false;
347 }
348 }
349 }
350
351 const int myRank = comm->getRank();
352 const int numRanks = comm->getSize();
353 const int candidateRank = hasCompleteLocalStencil ? myRank : numRanks;
354 int detectorRank = numRanks;
355 Teuchos::reduceAll(*comm, Teuchos::REDUCE_MIN, 1, &candidateRank, &detectorRank);
356 TEUCHOS_TEST_FOR_EXCEPTION(
357 detectorRank == numRanks, Exceptions::RuntimeError,
358 prefix << "no MPI rank owns a local interior node whose complete stencil is locally owned; "
359 << "increase the local structured subdomain size.");
360
361 FineStencilSpec stencil;
362 stencil.numDimensions = numDimensions;
363 stencil.dofsPerNode = dofsPerNode;
364
365 // Only the elected rank performs detection
366 if (myRank == detectorRank) {
367 for (LO rowDof = 0; rowDof < dofsPerNode; ++rowDof) {
368 const auto& rowColumns = ownedColumns[Teuchos::as<size_t>(rowDof)];
369 const size_t rowLength = rowColumns.size();
370 for (size_t entry = 0; entry < rowLength; ++entry) {
371 const LO ownedColumn = rowColumns[entry];
372 const LO columnNode = ownedColumn / dofsPerNode;
373 const LO columnDof = ownedColumn % dofsPerNode;
374 LO columnX, columnY, columnZ;
376 columnNode, fineNodes, columnX, columnY, columnZ);
377 const StencilOffset offset{
378 Teuchos::as<int>(columnX - interior[0]),
379 Teuchos::as<int>(columnY - interior[1]),
380 Teuchos::as<int>(columnZ - interior[2])};
381
382 bool knownOffset = false;
383 for (const StencilOffset& known : stencil.stencilOffsets) {
384 if (known.x == offset.x && known.y == offset.y && known.z == offset.z) {
385 knownOffset = true;
386 break;
387 }
388 }
389 if (!knownOffset)
390 stencil.stencilOffsets.push_back(offset);
391
392 stencil.entries.push_back(FineStencilEntry{
393 offset, rowDof, columnDof});
394 }
395 }
396 }
397
398 int counts[2] = {Teuchos::as<int>(stencil.stencilOffsets.size()),
399 Teuchos::as<int>(stencil.entries.size())};
400 Teuchos::broadcast<int, int>(*comm, detectorRank, 2, counts);
401
402 Teuchos::Array<int> offsetData(3 * counts[0]);
403 Teuchos::Array<int> entryOffsetData(3 * counts[1]);
404 Teuchos::Array<LO> entryData(2 * counts[1]);
405 if (myRank == detectorRank) {
406 for (int offset = 0; offset < counts[0]; ++offset) {
407 offsetData[3 * offset] = stencil.stencilOffsets[offset].x;
408 offsetData[3 * offset + 1] = stencil.stencilOffsets[offset].y;
409 offsetData[3 * offset + 2] = stencil.stencilOffsets[offset].z;
410 }
411 for (int entry = 0; entry < counts[1]; ++entry) {
412 entryOffsetData[3 * entry] = stencil.entries[entry].offset.x;
413 entryOffsetData[3 * entry + 1] = stencil.entries[entry].offset.y;
414 entryOffsetData[3 * entry + 2] = stencil.entries[entry].offset.z;
415 entryData[2 * entry] = stencil.entries[entry].rowDof;
416 entryData[2 * entry + 1] = stencil.entries[entry].columnDof;
417 }
418 }
419
420 if (counts[0] > 0)
421 Teuchos::broadcast<int, int>(*comm, detectorRank, 3 * counts[0],
422 offsetData.getRawPtr());
423 if (counts[1] > 0) {
424 Teuchos::broadcast<int, int>(*comm, detectorRank, 3 * counts[1],
425 entryOffsetData.getRawPtr());
426 Teuchos::broadcast<int, LO>(*comm, detectorRank, 2 * counts[1],
427 entryData.getRawPtr());
428 }
429
430 if (myRank != detectorRank) {
431 stencil.stencilOffsets.reserve(counts[0]);
432 for (int offset = 0; offset < counts[0]; ++offset)
433 stencil.stencilOffsets.push_back(StencilOffset{
434 offsetData[3 * offset], offsetData[3 * offset + 1],
435 offsetData[3 * offset + 2]});
436
437 stencil.entries.reserve(counts[1]);
438 for (int entry = 0; entry < counts[1]; ++entry)
439 stencil.entries.push_back(FineStencilEntry{
440 StencilOffset{entryOffsetData[3 * entry],
441 entryOffsetData[3 * entry + 1],
442 entryOffsetData[3 * entry + 2]},
443 entryData[2 * entry], entryData[2 * entry + 1]});
444 }
445
446 TEUCHOS_TEST_FOR_EXCEPTION(stencil.stencilOffsets.empty(), Exceptions::RuntimeError,
447 prefix << "the representative interior rows are empty.");
448 return stencil;
449}
450
451template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
452typename StructuredRAPFactory<Scalar, LocalOrdinal, GlobalOrdinal, Node>::StructuredGraphSpec
454 const FineStencilSpec& fineStencil, const int interpolationOrder) const {
455 const std::string prefix = "StructuredRAPFactory::DeriveCoarseRAPStencil: ";
456
457 TEUCHOS_TEST_FOR_EXCEPTION(fineStencil.numDimensions < 1 || fineStencil.numDimensions > 3,
459 prefix << "the number of dimensions must be between one and three.");
460 TEUCHOS_TEST_FOR_EXCEPTION(fineStencil.dofsPerNode <= 0, Exceptions::RuntimeError,
461 prefix << "dofsPerNode must be positive.");
462 TEUCHOS_TEST_FOR_EXCEPTION(fineStencil.stencilOffsets.empty(), Exceptions::RuntimeError,
463 prefix << "the fine-grid stencil is empty.");
464 TEUCHOS_TEST_FOR_EXCEPTION(interpolationOrder < 0 || interpolationOrder > 1,
466 prefix << "interpolation order " << interpolationOrder
467 << " is not supported; expected zero or one.");
468 for (const StencilOffset& offset : fineStencil.stencilOffsets) {
469 TEUCHOS_TEST_FOR_EXCEPTION(
470 offset.x < -1 || offset.x > 1 ||
471 offset.y < -1 || offset.y > 1 ||
472 offset.z < -1 || offset.z > 1,
474 prefix << "fine-grid stencil offset (" << offset.x << ", "
475 << offset.y << ", " << offset.z
476 << ") exceeds the supported radius one; disable "
477 "\"rap: prebuild coarse graph\" for wider stencils.");
478 }
479
480 StructuredGraphSpec coarseStencil;
481 coarseStencil.numDimensions = fineStencil.numDimensions;
482 coarseStencil.dofsPerNode = fineStencil.dofsPerNode;
483
484 if (interpolationOrder == 0) {
485 coarseStencil.stencilOffsets = fineStencil.stencilOffsets;
486 bool hasCenter = false;
487 for (const StencilOffset& offset : coarseStencil.stencilOffsets)
488 hasCenter = hasCenter || (offset.x == 0 && offset.y == 0 && offset.z == 0);
489 if (!hasCenter)
490 coarseStencil.stencilOffsets.push_back(StencilOffset{0, 0, 0});
491 } else {
492 // The supports of neighboring piecewise-linear basis functions overlap.
493 // For a radius-one fine stencil this produces the full radius-one coarse
494 // stencil in every active dimension.
495 const int minY = fineStencil.numDimensions > 1 ? -1 : 0;
496 const int maxY = fineStencil.numDimensions > 1 ? 1 : 0;
497 const int minZ = fineStencil.numDimensions > 2 ? -1 : 0;
498 const int maxZ = fineStencil.numDimensions > 2 ? 1 : 0;
499 for (int z = minZ; z <= maxZ; ++z)
500 for (int y = minY; y <= maxY; ++y)
501 for (int x = -1; x <= 1; ++x)
502 coarseStencil.stencilOffsets.push_back(StencilOffset{x, y, z});
503 }
504
505 int minimum[3] = {coarseStencil.stencilOffsets[0].x,
506 coarseStencil.stencilOffsets[0].y,
507 coarseStencil.stencilOffsets[0].z};
508 int maximum[3] = {minimum[0], minimum[1], minimum[2]};
509 for (const StencilOffset& offset : coarseStencil.stencilOffsets) {
510 const int components[3] = {offset.x, offset.y, offset.z};
511 for (int dim = 0; dim < fineStencil.numDimensions; ++dim) {
512 if (components[dim] < minimum[dim])
513 minimum[dim] = components[dim];
514 if (components[dim] > maximum[dim])
515 maximum[dim] = components[dim];
516 }
517 }
518
519 std::ostringstream description;
520 for (int dim = 0; dim < fineStencil.numDimensions; ++dim) {
521 if (dim != 0)
522 description << "x";
523 description << maximum[dim] - minimum[dim] + 1;
524 }
525 coarseStencil.description = description.str();
526 return coarseStencil;
527}
528
529// Prebuild sparsity structure of coarse matrix
530template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
532 RCP<Matrix>& Ac, const RCP<Matrix>& P,
533 const Teuchos::Array<LocalOrdinal>& lCoarseNodesPerDim,
534 const StructuredGraphSpec& graphSpec) const {
535 using local_graph_type = typename CrsGraph::local_graph_type;
536 using row_map_type = typename local_graph_type::row_map_type::non_const_type;
537 using entries_type = typename local_graph_type::entries_type::non_const_type;
538 using device_type = typename Node::device_type;
539 using execution_space = typename device_type::execution_space;
540 using range_policy = Kokkos::RangePolicy<execution_space, Kokkos::IndexType<size_t>>;
541
542 TEUCHOS_TEST_FOR_EXCEPTION(graphSpec.numDimensions < 1 || graphSpec.numDimensions > 3, Exceptions::RuntimeError,
543 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
544 << "): number of dimensions must be between one and three.");
545 TEUCHOS_TEST_FOR_EXCEPTION(lCoarseNodesPerDim.size() < graphSpec.numDimensions, Exceptions::RuntimeError,
546 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
547 << "): insufficient local coarse-grid dimensions.");
548 TEUCHOS_TEST_FOR_EXCEPTION(graphSpec.dofsPerNode <= 0, Exceptions::RuntimeError,
549 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
550 << "): dofsPerNode must be positive.");
551 TEUCHOS_TEST_FOR_EXCEPTION(graphSpec.stencilOffsets.empty(), Exceptions::RuntimeError,
552 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
553 << "): coarse-grid stencil is empty; it must define at least one relative node position (dx, dy, dz).");
554 constexpr size_t maxSupportedStencilSize = 27;
555 constexpr size_t maxSupportedDofsPerNode = 3;
556 TEUCHOS_TEST_FOR_EXCEPTION(graphSpec.stencilOffsets.size() > maxSupportedStencilSize, Exceptions::RuntimeError,
557 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
558 << "): a radius-one stencil may contain at most 27 entries.");
559 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<size_t>(graphSpec.dofsPerNode) > maxSupportedDofsPerNode, Exceptions::RuntimeError,
560 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
561 << "): at most three DOFs per node are supported.");
562
563 Kokkos::Array<GO, 3> localNodes{{GO(1), GO(1), GO(1)}};
564 for (int dim = 0; dim < graphSpec.numDimensions; ++dim) {
565 localNodes[dim] = Teuchos::as<GO>(lCoarseNodesPerDim[dim]);
566 TEUCHOS_TEST_FOR_EXCEPTION(localNodes[dim] <= 0, Exceptions::RuntimeError,
567 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
568 << "): local coarse dimensions must be positive.");
569 }
570
571 Kokkos::Array<StencilOffset, maxSupportedStencilSize> stencilOffsets{};
572 Kokkos::Array<GO, maxSupportedStencilSize> localStencilNodeOffsets{};
573 for (size_t stencil = 0; stencil < graphSpec.stencilOffsets.size(); ++stencil) {
574 const StencilOffset& offset = graphSpec.stencilOffsets[stencil];
575 TEUCHOS_TEST_FOR_EXCEPTION(offset.x < -1 || offset.x > 1 ||
576 offset.y < -1 || offset.y > 1 ||
577 offset.z < -1 || offset.z > 1,
579 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
580 << "): only radius-one stencil offsets are currently supported.");
581 TEUCHOS_TEST_FOR_EXCEPTION((graphSpec.numDimensions < 2 && offset.y != 0) ||
582 (graphSpec.numDimensions < 3 && offset.z != 0),
584 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
585 << "): stencil contains an offset in an inactive dimension.");
586 stencilOffsets[stencil] = offset;
587 localStencilNodeOffsets[stencil] =
588 static_cast<GO>(offset.x) + static_cast<GO>(offset.y) * localNodes[0] +
589 static_cast<GO>(offset.z) * localNodes[0] * localNodes[1];
590 }
591
592 RCP<ParameterList> paramList = rcp(new ParameterList);
593 paramList->set("No Nonlocal Changes", true);
594 paramList->set("Optimize Storage", true);
595 paramList->set("compute global constants", true);
596
597 // Columns of P represent coarse-grid nodes
598 auto rowMap = P->getDomainMap();
599 const size_t localNumRows = rowMap->getLocalNumElements();
600 const LO dofsPerNode = graphSpec.dofsPerNode;
601 const GO dofsPerNodeGO = Teuchos::as<GO>(dofsPerNode);
602 const size_t rowsPerNode = Teuchos::as<size_t>(dofsPerNode);
603 const GO localNumNodesGO = localNodes[0] * localNodes[1] * localNodes[2];
604 const size_t localNumNodes = Teuchos::as<size_t>(localNumNodesGO);
605 const GO expectedLocalRows = localNumNodesGO * dofsPerNodeGO;
606 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<GO>(localNumRows) != expectedLocalRows, Exceptions::RuntimeError,
607 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
608 << "): local coarse dimensions with " << graphSpec.dofsPerNode
609 << " dofs per node do not match local coarse row count "
610 << localNumRows << ".");
611 TEUCHOS_TEST_FOR_EXCEPTION(rowMap->lib() != Xpetra::UseTpetra, Exceptions::RuntimeError,
612 "StructuredRAPFactory::GetStructuredGraph requires the Tpetra backend.");
613
614 const GO numGlobalRows = Teuchos::as<GO>(rowMap->getGlobalNumElements());
615 TEUCHOS_TEST_FOR_EXCEPTION(numGlobalRows % dofsPerNodeGO != 0, Exceptions::RuntimeError,
616 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
617 << "): global coarse row count is not divisible by dofsPerNode.");
618 const GO numGlobalNodes = numGlobalRows / dofsPerNodeGO;
619 const GO globalMinGid = rowMap->getMinAllGlobalIndex();
620 const GO globalMaxGid = rowMap->getMaxAllGlobalIndex();
621 TEUCHOS_TEST_FOR_EXCEPTION(globalMaxGid - globalMinGid + 1 != numGlobalRows, Exceptions::RuntimeError,
622 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
623 << "): coarse row-map GIDs must form a contiguous range.");
624
625 RCP<const Teuchos::Comm<int>> comm = rowMap->getComm();
626 const int myRank = comm->getRank();
627 const int numRanks = comm->getSize();
628 const GO localMinGid = rowMap->getMinGlobalIndex();
629 TEUCHOS_TEST_FOR_EXCEPTION((localMinGid - globalMinGid) % dofsPerNodeGO != 0, Exceptions::RuntimeError,
630 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
631 << "): local row range does not begin at a nodal boundary.");
632 const GO firstLocalNode = (localMinGid - globalMinGid) / dofsPerNodeGO;
633
634 Teuchos::Array<GO> localRankData(4);
635 localRankData[0] = firstLocalNode;
636 localRankData[1] = localNodes[0];
637 localRankData[2] = localNodes[1];
638 localRankData[3] = localNodes[2];
639 Teuchos::Array<GO> rankData(4 * numRanks);
640 Teuchos::gatherAll(*comm, 4, localRankData.getRawPtr(),
641 4 * numRanks, rankData.getRawPtr());
642
643 // Get mx, my and mz (number of ranks per dimension) like they are defined in Galeri (compare Galeri_XpetraMaps_def.hpp)
644 Kokkos::Array<int, 3> procGrid{{1, 1, 1}};
645 if (graphSpec.numDimensions == 1) {
646 procGrid[0] = numRanks;
647 } else if (graphSpec.numDimensions == 2) {
648 while ((procGrid[0] + 1) * (procGrid[0] + 1) <= numRanks)
649 ++procGrid[0];
650 procGrid[1] = numRanks / procGrid[0];
651 while (procGrid[0] * procGrid[1] != numRanks)
652 procGrid[1] = numRanks / (--procGrid[0]);
653 } else {
654 int cubeRootNumRanks = 1;
655 while ((cubeRootNumRanks + 1) * (cubeRootNumRanks + 1) * (cubeRootNumRanks + 1) <= numRanks)
656 ++cubeRootNumRanks;
657 procGrid[0] = cubeRootNumRanks;
658 procGrid[1] = cubeRootNumRanks;
659 procGrid[2] = cubeRootNumRanks;
660
661 if (procGrid[0] * procGrid[1] * procGrid[2] != numRanks) {
662 procGrid[0] = 1;
663 procGrid[1] = 1;
664 procGrid[2] = 1;
665
666 int procTemp = numRanks;
667 // Keep this factorization limit synchronized with Galeri_XpetraMaps_def.hpp.
668 const int galeriFactorSearchLimit = 50;
669 int factors[galeriFactorSearchLimit] = {};
670 for (int factor = 2; factor < galeriFactorSearchLimit; ++factor) {
671 while (procTemp % factor == 0) {
672 ++factors[factor];
673 procTemp /= factor;
674 }
675 }
676 procGrid[0] = procTemp;
677 for (int factor = galeriFactorSearchLimit - 1; factor > 0; --factor) {
678 while (factors[factor] != 0) {
679 if (procGrid[0] <= procGrid[1] && procGrid[0] <= procGrid[2])
680 procGrid[0] *= factor;
681 else if (procGrid[1] <= procGrid[0] && procGrid[1] <= procGrid[2])
682 procGrid[1] *= factor;
683 else
684 procGrid[2] *= factor;
685 --factors[factor];
686 }
687 }
688 }
689 }
690
691 const int procXY = procGrid[0] * procGrid[1];
692 TEUCHOS_TEST_FOR_EXCEPTION(procGrid[0] <= 0 || procGrid[1] <= 0 || procGrid[2] <= 0 ||
693 procXY * procGrid[2] != numRanks,
695 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
696 << "): invalid inferred processor grid "
697 << procGrid[0] << "x" << procGrid[1] << "x" << procGrid[2]
698 << " for " << numRanks << " ranks.");
699
700 const int myProcX = myRank % procGrid[0];
701 const int myProcY = (myRank % procXY) / procGrid[0];
702 const int myProcZ = myRank / procXY;
703
704 Kokkos::Array<GO, 3> globalNodes{{GO(0), GO(0), GO(0)}};
705 for (int px = 0; px < procGrid[0]; ++px)
706 globalNodes[0] += rankData[4 * px + 1];
707 for (int py = 0; py < procGrid[1]; ++py)
708 globalNodes[1] += rankData[4 * (py * procGrid[0]) + 2];
709 for (int pz = 0; pz < procGrid[2]; ++pz)
710 globalNodes[2] += rankData[4 * (pz * procXY) + 3];
711 TEUCHOS_TEST_FOR_EXCEPTION(globalNodes[0] * globalNodes[1] * globalNodes[2] != numGlobalNodes,
713 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
714 << "): processor-grid coarse dimensions do not match coarse node count.");
715
716 execution_space executionSpace;
717 Kokkos::View<GO*, device_type> rankDataDevice(
718 Kokkos::ViewAllocateWithoutInitializing("StructuredRAP: rank metadata"), rankData.size());
719 auto rankDataHost = Kokkos::create_mirror_view(rankDataDevice);
720 for (int entry = 0; entry < rankData.size(); ++entry)
721 rankDataHost(entry) = rankData[entry];
722 Kokkos::deep_copy(executionSpace, rankDataDevice, rankDataHost);
723
724 const size_t stencilSize = graphSpec.stencilOffsets.size();
725 const int numDimensions = graphSpec.numDimensions;
726
727 const bool debug = Behavior::debug();
728 if (debug) {
729 const auto rowLocalMap = rowMap->getLocalMap();
730 size_t invalidLocalRows = 0;
731 Kokkos::parallel_reduce(
732 "StructuredRAP: validate local rows", range_policy(executionSpace, 0, localNumRows),
733 KOKKOS_LAMBDA(const size_t rowLid, size_t& invalid) {
734 const GO rowGid = rowLocalMap.getGlobalElement(static_cast<LO>(rowLid));
735 const GO expectedRowGid = localMinGid + static_cast<GO>(rowLid);
736 if (rowGid != expectedRowGid)
737 ++invalid;
738 },
739 invalidLocalRows);
740 TEUCHOS_TEST_FOR_EXCEPTION(invalidLocalRows != 0, Exceptions::RuntimeError,
741 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
742 << "): coarse row-map GIDs are not locally contiguous and ordered.");
743 }
744
745 // A radius-one stencil reaches disjoint faces, edges, and corners of at most
746 // 26 neighboring ranks, so generate each remote column exactly once.
747 constexpr size_t maxNeighborRegions = 26;
748 Kokkos::Array<int, maxNeighborRegions> remoteRegionRanks{};
749 Kokkos::Array<StencilOffset, maxNeighborRegions> remoteRegionDirections{};
750 Kokkos::Array<GO, maxNeighborRegions> remoteRegionFirstNodes{};
751 Kokkos::Array<GO, maxNeighborRegions> remoteRegionNx{};
752 Kokkos::Array<GO, maxNeighborRegions> remoteRegionNy{};
753 Kokkos::Array<GO, maxNeighborRegions> remoteRegionNz{};
754 Kokkos::Array<size_t, maxNeighborRegions + 1> remoteRegionOffsets{};
755 size_t numRemoteRegions = 0;
756
757 const int minProcY = graphSpec.numDimensions > 1 ? -1 : 0;
758 const int maxProcY = graphSpec.numDimensions > 1 ? 1 : 0;
759 const int minProcZ = graphSpec.numDimensions > 2 ? -1 : 0;
760 const int maxProcZ = graphSpec.numDimensions > 2 ? 1 : 0;
761 for (int procDz = minProcZ; procDz <= maxProcZ; ++procDz) {
762 for (int procDy = minProcY; procDy <= maxProcY; ++procDy) {
763 for (int procDx = -1; procDx <= 1; ++procDx) {
764 if (procDx == 0 && procDy == 0 && procDz == 0)
765 continue;
766
767 bool stencilReachesRegion = false;
768 for (size_t stencil = 0; stencil < stencilSize; ++stencil) {
769 const StencilOffset& offset = stencilOffsets[stencil];
770 const bool reachesX = procDx == 0 || offset.x == procDx;
771 const bool reachesY = procDy == 0 || offset.y == procDy;
772 const bool reachesZ = procDz == 0 || offset.z == procDz;
773 if (reachesX && reachesY && reachesZ) {
774 stencilReachesRegion = true;
775 break;
776 }
777 }
778 if (!stencilReachesRegion)
779 continue;
780
781 const int neighborProcX = myProcX + procDx;
782 const int neighborProcY = myProcY + procDy;
783 const int neighborProcZ = myProcZ + procDz;
784 if (neighborProcX < 0 || neighborProcX >= procGrid[0] ||
785 neighborProcY < 0 || neighborProcY >= procGrid[1] ||
786 neighborProcZ < 0 || neighborProcZ >= procGrid[2])
787 continue;
788
789 const int neighborRank = neighborProcZ * procXY + neighborProcY * procGrid[0] + neighborProcX;
790 const GO neighborNx = rankData[4 * neighborRank + 1];
791 const GO neighborNy = rankData[4 * neighborRank + 2];
792 const GO neighborNz = rankData[4 * neighborRank + 3];
793 const size_t regionNodes = Teuchos::as<size_t>((procDx == 0 ? neighborNx : 1) *
794 (procDy == 0 ? neighborNy : 1) *
795 (procDz == 0 ? neighborNz : 1));
796
797 remoteRegionRanks[numRemoteRegions] = neighborRank;
798 remoteRegionDirections[numRemoteRegions] = StencilOffset{procDx, procDy, procDz};
799 remoteRegionFirstNodes[numRemoteRegions] = rankData[4 * neighborRank];
800 remoteRegionNx[numRemoteRegions] = neighborNx;
801 remoteRegionNy[numRemoteRegions] = neighborNy;
802 remoteRegionNz[numRemoteRegions] = neighborNz;
803 remoteRegionOffsets[numRemoteRegions + 1] =
804 remoteRegionOffsets[numRemoteRegions] + regionNodes * rowsPerNode;
805 ++numRemoteRegions;
806 }
807 }
808 }
809 const size_t numRemoteColumns = remoteRegionOffsets[numRemoteRegions];
810
811 RCP<const Map> colMap;
812 if (numRemoteColumns == 0) {
813 colMap = rowMap;
814 } else {
815 Kokkos::View<GO*, device_type> colMapGids(
816 Kokkos::ViewAllocateWithoutInitializing("StructuredRAP: column map GIDs"),
817 localNumRows + numRemoteColumns);
818 const auto localRowGidsDevice = rowMap->getMyGlobalIndicesDevice();
819 Kokkos::parallel_for(
820 "StructuredRAP: fill column map", range_policy(executionSpace, 0, localNumRows + numRemoteColumns),
821 KOKKOS_LAMBDA(const size_t entry) {
822 if (entry < localNumRows) {
823 colMapGids(entry) = localRowGidsDevice(entry);
824 return;
825 }
826
827 const size_t remoteEntry = entry - localNumRows;
828 size_t region = 0;
829 while (remoteEntry >= remoteRegionOffsets[region + 1])
830 ++region;
831
832 const StencilOffset direction = remoteRegionDirections[region];
833 const GO neighborNx = remoteRegionNx[region];
834 const GO neighborNy = remoteRegionNy[region];
835 const GO neighborNz = remoteRegionNz[region];
836 size_t regionEntry = remoteEntry - remoteRegionOffsets[region];
837 const GO dof = static_cast<GO>(regionEntry % rowsPerNode);
838 size_t regionNode = regionEntry / rowsPerNode;
839
840 GO neighborX = direction.x < 0 ? neighborNx - 1 : 0;
841 GO neighborY = direction.y < 0 ? neighborNy - 1 : 0;
842 GO neighborZ = direction.z < 0 ? neighborNz - 1 : 0;
843 if (direction.x == 0) {
844 neighborX = static_cast<GO>(regionNode % static_cast<size_t>(neighborNx));
845 regionNode /= static_cast<size_t>(neighborNx);
846 }
847 if (direction.y == 0) {
848 neighborY = static_cast<GO>(regionNode % static_cast<size_t>(neighborNy));
849 regionNode /= static_cast<size_t>(neighborNy);
850 }
851 if (direction.z == 0)
852 neighborZ = static_cast<GO>(regionNode);
853
854 const GO neighborNode = remoteRegionFirstNodes[region] +
855 neighborZ * neighborNx * neighborNy + neighborY * neighborNx + neighborX;
856 colMapGids(entry) = globalMinGid + neighborNode * dofsPerNodeGO + dof;
857 });
858 executionSpace.fence("StructuredRAP: column map GIDs ready");
859
860 typename Map::global_indices_array_device_type constColMapGids = colMapGids;
861 colMap = MapFactory::Build(
862 rowMap->lib(), Teuchos::OrdinalTraits<Xpetra::global_size_t>::invalid(),
863 constColMapGids, rowMap->getIndexBase(), comm);
864 }
865
866 // For each low/interior/high boundary combination, precompute the affine
867 // number of stencil interactions preceding (x,y,z) in lexicographic order.
868 // This makes row offsets constant-time in the graph-fill kernel and avoids a
869 // device-wide scan without traversing the stencil for every interior node.
870 constexpr size_t numBoundaryClasses = 64;
871 Kokkos::Array<std::int64_t, numBoundaryClasses> prefixConstant{};
872 Kokkos::Array<std::int64_t, numBoundaryClasses> prefixX{};
873 Kokkos::Array<std::int64_t, numBoundaryClasses> prefixY{};
874 Kokkos::Array<std::int64_t, numBoundaryClasses> prefixZ{};
875 size_t localNnz = 0;
876 const int procCoordinates[3] = {myProcX, myProcY, myProcZ};
877 for (size_t stencil = 0; stencil < stencilSize; ++stencil) {
878 const StencilOffset& offset = stencilOffsets[stencil];
879 const int offsets[3] = {offset.x, offset.y, offset.z};
880 GO lower[3] = {0, 0, 0};
881 GO upper[3] = {localNodes[0], localNodes[1], localNodes[2]};
882 for (int dim = 0; dim < 3; ++dim) {
883 if (offsets[dim] < 0 && procCoordinates[dim] == 0)
884 lower[dim] = 1;
885 if (offsets[dim] > 0 && procCoordinates[dim] + 1 == procGrid[dim])
886 --upper[dim];
887 }
888 const std::int64_t lengths[3] = {
889 static_cast<std::int64_t>(upper[0] - lower[0]),
890 static_cast<std::int64_t>(upper[1] - lower[1]),
891 static_cast<std::int64_t>(upper[2] - lower[2])};
892 localNnz += static_cast<size_t>(lengths[0] * lengths[1] * lengths[2]) *
893 rowsPerNode * rowsPerNode;
894
895 for (size_t boundaryClass = 0; boundaryClass < numBoundaryClasses; ++boundaryClass) {
896 std::int64_t coordinates[3];
897 for (int dim = 0; dim < 3; ++dim) {
898 const bool low = boundaryClass & (size_t(1) << (2 * dim));
899 const bool high = boundaryClass & (size_t(2) << (2 * dim));
900 coordinates[dim] = low ? 0 : high ? static_cast<std::int64_t>(localNodes[dim] - 1)
901 : 1;
902 }
903 std::int64_t* coefficients[3] = {
904 &prefixX[boundaryClass], &prefixY[boundaryClass], &prefixZ[boundaryClass]};
905 auto addClamped = [&](const int dim, const std::int64_t multiplier) {
906 const std::int64_t begin = static_cast<std::int64_t>(lower[dim]);
907 const std::int64_t end = static_cast<std::int64_t>(upper[dim]);
908 if (coordinates[dim] >= end)
909 prefixConstant[boundaryClass] += (end - begin) * multiplier;
910 else if (coordinates[dim] >= begin) {
911 prefixConstant[boundaryClass] -= begin * multiplier;
912 *coefficients[dim] += multiplier;
913 }
914 };
915 const bool insideZ = coordinates[2] >= lower[2] && coordinates[2] < upper[2];
916 const bool insideY = coordinates[1] >= lower[1] && coordinates[1] < upper[1];
917 addClamped(2, lengths[0] * lengths[1]);
918 if (insideZ)
919 addClamped(1, lengths[0]);
920 if (insideZ && insideY)
921 addClamped(0, 1);
922 }
923 }
924
925 row_map_type rowptr(
926 Kokkos::ViewAllocateWithoutInitializing("StructuredRAP: graph row pointers"), localNumRows + 1);
927
928 entries_type colind(
929 Kokkos::ViewAllocateWithoutInitializing(
930 "StructuredRAP: graph column indices"),
931 localNnz);
932
933 const LO invalidLocalOrdinal = Teuchos::OrdinalTraits<LO>::invalid();
934 Kokkos::View<int, device_type> invalidColumn;
935 if (debug) {
936 invalidColumn = Kokkos::View<int, device_type>("StructuredRAP: invalid column");
937 Kokkos::deep_copy(executionSpace, invalidColumn, 0);
938 }
939
940 // Loop to fill colind
941 {
942 Kokkos::parallel_for(
943 "StructuredRAP: fill graph column indices", range_policy(executionSpace, 0, localNumNodes),
944 KOKKOS_LAMBDA(const size_t localNodeIndex) {
945 const GO localNode = static_cast<GO>(localNodeIndex);
946 GO x = 0, y = 0, z = 0;
947 StructuredRAPFactoryDetails::getLocalNodeIndices(localNode, localNodes, x, y, z);
948 const size_t boundaryClass =
949 (x == 0 ? size_t(1) : 0) | (x + 1 == localNodes[0] ? size_t(2) : 0) |
950 (y == 0 ? size_t(4) : 0) | (y + 1 == localNodes[1] ? size_t(8) : 0) |
951 (z == 0 ? size_t(16) : 0) | (z + 1 == localNodes[2] ? size_t(32) : 0);
952 const size_t nodeRowStart = static_cast<size_t>(
953 prefixConstant[boundaryClass] + prefixX[boundaryClass] * static_cast<std::int64_t>(x) +
954 prefixY[boundaryClass] * static_cast<std::int64_t>(y) +
955 prefixZ[boundaryClass] * static_cast<std::int64_t>(z)) *
956 rowsPerNode * rowsPerNode;
957 size_t columnOffset = 0;
958 const bool isInterior =
959 x > 0 && x + 1 < localNodes[0] &&
960 (numDimensions < 2 || (y > 0 && y + 1 < localNodes[1])) &&
961 (numDimensions < 3 || (z > 0 && z + 1 < localNodes[2]));
962
963 if (isInterior) {
964 const size_t firstRow = localNodeIndex * rowsPerNode;
965 const size_t rowLength = stencilSize * rowsPerNode;
966 for (size_t rowDof = 0; rowDof < rowsPerNode; ++rowDof)
967 rowptr(firstRow + rowDof) = nodeRowStart + rowDof * rowLength;
968 for (size_t stencil = 0; stencil < stencilSize; ++stencil) {
969 const GO neighborLocalNode = localNode + localStencilNodeOffsets[stencil];
970 for (size_t colDof = 0; colDof < rowsPerNode; ++colDof) {
971 const LO colLid = static_cast<LO>(
972 neighborLocalNode * dofsPerNodeGO + static_cast<GO>(colDof));
973 for (size_t rowDof = 0; rowDof < rowsPerNode; ++rowDof)
974 colind(rowptr(firstRow + rowDof) + columnOffset) = colLid;
975 ++columnOffset;
976 }
977 }
978 if (localNodeIndex + 1 == localNumNodes)
979 rowptr(localNumRows) = localNnz;
980 return;
981 }
982
983 Kokkos::Array<LO, maxSupportedStencilSize * maxSupportedDofsPerNode> nodeColumns;
984 for (size_t stencil = 0; stencil < stencilSize; ++stencil) {
985 int neighborRank = myRank;
986 GO neighborNode = 0;
988 x, y, z, stencilOffsets[stencil], localNodes, procGrid, rankDataDevice,
989 myProcX, myProcY, myProcZ, neighborRank, neighborNode))
990 continue;
991
992 for (size_t colDof = 0; colDof < rowsPerNode; ++colDof) {
993 const GO colGid = globalMinGid + neighborNode * dofsPerNodeGO + static_cast<GO>(colDof);
994 LO colLid = invalidLocalOrdinal;
995 if (neighborRank == myRank) {
996 colLid = static_cast<LO>(colGid - localMinGid);
997 } else {
998 size_t region = 0;
999 while (region < numRemoteRegions && remoteRegionRanks[region] != neighborRank)
1000 ++region;
1001 if (region < numRemoteRegions) {
1002 const GO neighborNx = remoteRegionNx[region];
1003 const GO neighborNy = remoteRegionNy[region];
1004 const GO localNeighborNode = neighborNode - remoteRegionFirstNodes[region];
1005 const GO neighborX = localNeighborNode % neighborNx;
1006 const GO neighborY = (localNeighborNode / neighborNx) % neighborNy;
1007 const GO neighborZ = localNeighborNode / (neighborNx * neighborNy);
1008 const StencilOffset direction = remoteRegionDirections[region];
1009 size_t regionNode = 0;
1010 size_t stride = 1;
1011 if (direction.x == 0) {
1012 regionNode += static_cast<size_t>(neighborX) * stride;
1013 stride *= static_cast<size_t>(neighborNx);
1014 }
1015 if (direction.y == 0) {
1016 regionNode += static_cast<size_t>(neighborY) * stride;
1017 stride *= static_cast<size_t>(neighborNy);
1018 }
1019 if (direction.z == 0)
1020 regionNode += static_cast<size_t>(neighborZ) * stride;
1021 colLid = static_cast<LO>(localNumRows + remoteRegionOffsets[region] +
1022 regionNode * rowsPerNode + colDof);
1023 }
1024 }
1025
1026 if (debug && colLid == invalidLocalOrdinal)
1027 Kokkos::atomic_exchange(&invalidColumn(), 1);
1028
1029 nodeColumns[columnOffset++] = colLid;
1030 }
1031 }
1032
1033 for (size_t entry = 1; entry < columnOffset; ++entry) {
1034 const LO value = nodeColumns[entry];
1035 size_t insertion = entry;
1036 while (insertion > 0 && value < nodeColumns[insertion - 1]) {
1037 nodeColumns[insertion] = nodeColumns[insertion - 1];
1038 --insertion;
1039 }
1040 nodeColumns[insertion] = value;
1041 }
1042
1043 const size_t firstRow = localNodeIndex * rowsPerNode;
1044 const size_t rowLength = columnOffset;
1045 for (size_t rowDof = 0; rowDof < rowsPerNode; ++rowDof) {
1046 const size_t rowStart = nodeRowStart + rowDof * rowLength;
1047 rowptr(firstRow + rowDof) = rowStart;
1048 for (size_t entry = 0; entry < columnOffset; ++entry)
1049 colind(rowStart + entry) = nodeColumns[entry];
1050 }
1051 if (localNodeIndex + 1 == localNumNodes)
1052 rowptr(localNumRows) = localNnz;
1053 });
1054 executionSpace.fence("StructuredRAP: graph column indices ready");
1055 }
1056
1057 if (debug) {
1058 int invalidColumnHost = 0;
1059 Kokkos::deep_copy(executionSpace, invalidColumnHost, invalidColumn);
1060 TEUCHOS_TEST_FOR_EXCEPTION(invalidColumnHost != 0, Exceptions::RuntimeError,
1061 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
1062 << "): a generated column GID was not found in the coarse column map.");
1063
1064 size_t unsortedRows = 0;
1065 Kokkos::parallel_reduce(
1066 "StructuredRAP: validate sorted graph rows", range_policy(executionSpace, 0, localNumRows),
1067 KOKKOS_LAMBDA(const size_t row, size_t& invalid) {
1068 for (size_t entry = rowptr(row) + 1; entry < rowptr(row + 1); ++entry) {
1069 if (colind(entry) < colind(entry - 1)) {
1070 ++invalid;
1071 break;
1072 }
1073 }
1074 },
1075 unsortedRows);
1076 TEUCHOS_TEST_FOR_EXCEPTION(unsortedRows != 0, Exceptions::RuntimeError,
1077 "StructuredRAPFactory::GetStructuredGraph(" << graphSpec.description
1078 << "): generated graph rows are not sorted.");
1079 }
1080
1081 local_graph_type localGraph(colind, rowptr);
1082 RCP<CrsGraph> graph = CrsGraphFactory::Build(
1083 localGraph, rowMap, colMap, rowMap, rowMap, paramList);
1084 using values_type = typename Matrix::local_matrix_type::values_type;
1085 values_type values(
1086 Kokkos::ViewAllocateWithoutInitializing(
1087 "StructuredRAP: matrix values"),
1088 localNnz);
1089 Ac = MatrixFactory::Build(graph, values, paramList);
1090}
1091
1092template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1094 const bool doTranspose = true;
1095 const bool doFillComplete = true;
1096 const bool doOptimizeStorage = true;
1097 const Teuchos::ParameterList& pL = GetParameterList();
1098 const bool useRAPDelegate =
1099 !pL.get<bool>("rap: prebuild coarse graph");
1100
1101 TEUCHOS_TEST_FOR_EXCEPTION(
1102 !pL.get<bool>("transpose: use implicit"), Exceptions::RuntimeError,
1103 "StructuredRAPFactory requires \"transpose: use implicit\" = true because "
1104 "the prebuilt coarse graph assumes the Galerkin product P^T A P.");
1105
1106 RCP<Matrix> Ac;
1107
1108 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_ == false, Exceptions::RuntimeError,
1109 "MueLu::RAPFactory::Build(): CallDeclareInput has not been called before Build!");
1110
1111 if (useRAPDelegate) {
1112 if (pL.get<std::string>("rap: triple product implementation") ==
1113 "structured") {
1115 << "StructuredRAP: Coarse graph prebuilding is disabled, "
1116 "redirecting the structured triple product to Xpetra."
1117 << std::endl;
1118 }
1119 if (coarseLevel.IsAvailable("RAP reuse data", this)) {
1120 RCP<ParameterList> RAPparams = coarseLevel.Get<RCP<ParameterList>>("RAP reuse data", this);
1121 coarseLevel.Set("RAP reuse data", RAPparams, rapFactoryDelegate_.get());
1122 }
1123
1124 // RAPFactory does not accept a prebuilt Ac graph, so delegate only when
1125 // coarse-graph prebuilding is disabled.
1126 rapFactoryDelegate_->Build(fineLevel, coarseLevel);
1127
1128 Ac = coarseLevel.Get<RCP<Matrix>>("A", rapFactoryDelegate_.get());
1129 Set(coarseLevel, "A", Ac);
1130
1131 if (coarseLevel.IsAvailable("RAP reuse data", rapFactoryDelegate_.get())) {
1132 RCP<ParameterList> RAPparams = coarseLevel.Get<RCP<ParameterList>>("RAP reuse data", rapFactoryDelegate_.get());
1133 Set(coarseLevel, "RAP reuse data", RAPparams);
1134 }
1135
1136 return;
1137 }
1138
1139 {
1140 const std::string labelstr = FormattingHelper::getColonLabel(coarseLevel.getObjectLabel());
1141 FactoryMonitor m(*this, "Computing Ac", coarseLevel);
1142
1143 std::ostringstream levelstr;
1144 levelstr << coarseLevel.GetLevelID();
1145
1146 TEUCHOS_TEST_FOR_EXCEPTION(
1147 pL.get<bool>("rap: triple product") == false, Exceptions::RuntimeError,
1148 "StructuredRAPFactory requires \"rap: triple product\" = true.");
1149
1150 RCP<Matrix> A = Get<RCP<Matrix>>(fineLevel, "A");
1151 RCP<Matrix> P = Get<RCP<Matrix>>(coarseLevel, "P");
1152 const std::string tripleProductImplementation =
1153 pL.get<std::string>("rap: triple product implementation");
1154 TEUCHOS_TEST_FOR_EXCEPTION(
1155 tripleProductImplementation != "unstructured" && tripleProductImplementation != "structured",
1157 "StructuredRAPFactory: unknown value \"" << tripleProductImplementation
1158 << "\" for \"rap: triple product implementation\". "
1159 "Valid values are \"unstructured\" and \"structured\".");
1160
1161 const RCP<const FactoryBase> coarseDimensionsFactory =
1162 GetStructuredMetadataFactory("lCoarseNodesPerDim");
1163 const RCP<const FactoryBase> interpolationOrderFactory =
1164 GetStructuredMetadataFactory("structuredInterpolationOrder");
1165 const Teuchos::Array<LocalOrdinal> lCoarseNodesPerDim =
1166 fineLevel.Get<Teuchos::Array<LocalOrdinal>>(
1167 "lCoarseNodesPerDim", coarseDimensionsFactory.get());
1168 const int interpolationOrder =
1169 fineLevel.Get<int>("structuredInterpolationOrder",
1170 interpolationOrderFactory.get());
1171 const int numDimensions =
1172 fineLevel.GetLevelID() == 0
1173 ? fineLevel.Get<int>("numDimensions", NoFactory::get())
1174 : Get<int>(fineLevel, "numDimensions");
1175 const Teuchos::Array<LocalOrdinal> lFineNodesPerDim =
1176 fineLevel.GetLevelID() == 0
1177 ? fineLevel.Get<Teuchos::Array<LocalOrdinal>>(
1178 "lNodesPerDim", NoFactory::get())
1179 : Get<Teuchos::Array<LocalOrdinal>>(fineLevel, "lNodesPerDim");
1180 Teuchos::Array<int> structuredCoarseningRate;
1181 if (tripleProductImplementation == "structured") {
1182 // lCoarseNodesPerDim and structuredInterpolationOrder are produced by
1183 // StructuredAggregationFactory. Read the rate from that same producer
1184 // so the structured RAP path uses the existing
1185 // "aggregation: coarsening rate" setting instead of requiring a second,
1186 // potentially inconsistent RAP-specific parameter.
1187 const Factory* structuredFactory =
1188 dynamic_cast<const Factory*>(coarseDimensionsFactory.get());
1189 TEUCHOS_TEST_FOR_EXCEPTION(
1190 structuredFactory == nullptr, Exceptions::RuntimeError,
1191 "StructuredRAPFactory: the factory producing lCoarseNodesPerDim "
1192 "does not expose its aggregation parameters.");
1193 const ParameterList& structuredParameters =
1194 structuredFactory->GetParameterList();
1195 TEUCHOS_TEST_FOR_EXCEPTION(
1196 !structuredParameters.isType<std::string>(
1197 "aggregation: coarsening rate"),
1199 "StructuredRAPFactory: the factory producing lCoarseNodesPerDim "
1200 "does not provide the string parameter \"aggregation: coarsening "
1201 "rate\".");
1202 try {
1203 structuredCoarseningRate = Teuchos::fromStringToArray<int>(
1204 structuredParameters.get<std::string>(
1205 "aggregation: coarsening rate"));
1206 } catch (const Teuchos::InvalidArrayStringRepresentation& e) {
1207 GetOStream(Errors, -1)
1208 << " *** \"aggregation: coarsening rate\" must be a string "
1209 "convertible into an array! *** "
1210 << std::endl;
1211 throw e;
1212 }
1213 }
1214 if (P.is_null()) {
1215 Ac = Teuchos::null;
1216 Set(coarseLevel, "A", Ac);
1217 return;
1218 }
1219
1220 const FineStencilSpec fineStencil =
1221 DetectFineStencil(*A, numDimensions, lFineNodesPerDim);
1222 const StructuredGraphSpec graphSpec =
1223 DeriveCoarseRAPStencil(fineStencil, interpolationOrder);
1224
1225 {
1226 RCP<ParameterList> RAPparams;
1227 {
1228 SubFactoryMonitor mGraph(*this, "Prebuilding coarse Ac graph", coarseLevel);
1229
1230 RAPparams = rcp(new ParameterList);
1231 if (pL.isSublist("matrixmatrix: kernel params"))
1232 RAPparams->sublist("matrixmatrix: kernel params") = pL.sublist("matrixmatrix: kernel params");
1233
1234 if (coarseLevel.IsAvailable("RAP reuse data", this)) {
1235 GetOStream(static_cast<MsgType>(Runtime0 | Test)) << "Reusing previous RAP data" << std::endl;
1236
1237 RAPparams = coarseLevel.Get<RCP<ParameterList>>("RAP reuse data", this);
1238 TEUCHOS_TEST_FOR_EXCEPTION(!RAPparams->isParameter("graph"), Exceptions::RuntimeError,
1239 "StructuredRAPFactory::Build(): \"RAP reuse data\" does not contain the expected graph.");
1240 Ac = RAPparams->get<RCP<Matrix>>("graph");
1241 TEUCHOS_TEST_FOR_EXCEPTION(Ac.is_null(), Exceptions::RuntimeError,
1242 "StructuredRAPFactory::Build(): \"RAP reuse data\" graph is null.");
1243 Ac->SetMaxEigenvalueEstimate(-Teuchos::ScalarTraits<SC>::one());
1244 } else {
1245 // If reuse data is not available, prebuild the sparse graph from the
1246 // detected fine stencil and its derived coarse RAP stencil.
1247 GetOStream(Statistics1) << "StructuredRAP: Using " << graphSpec.description
1248 << " stencil with " << graphSpec.stencilOffsets.size()
1249 << " nodal entries." << std::endl;
1250 GetStructuredGraph(Ac, P, lCoarseNodesPerDim, graphSpec);
1251 }
1252 }
1253
1254 // We *always* need global constants for the RAP, but not for the temps
1255 RAPparams->set("compute global constants: temporaries", RAPparams->get("compute global constants: temporaries", false));
1256 RAPparams->set("compute global constants", true);
1257
1258 if (tripleProductImplementation == "unstructured") {
1259 SubFactoryMonitor m2(*this, "MxMxM: Xpetra P^T x A x P (implicit)", coarseLevel);
1260 Xpetra::TripleMatrixMultiply<SC, LO, GO, NO>::
1261 MultiplyRAP(*P, doTranspose, *A, !doTranspose, *P, !doTranspose, *Ac, doFillComplete,
1262 doOptimizeStorage, labelstr + std::string("MueLu::Xpetra-P^T*A*P-implicit-") + levelstr.str(),
1263 RAPparams);
1264 } else {
1265 SubFactoryMonitor m2(*this, "MxMxM: Structured P^T x A x P (implicit)", coarseLevel);
1267 *A, *P, *Ac, fineStencil, interpolationOrder,
1268 lFineNodesPerDim, lCoarseNodesPerDim,
1269 structuredCoarseningRate, RAPparams);
1270
1271 Ac->CreateView("stridedMaps", P, true, P, false);
1272 }
1273
1274 {
1275 GetOStream(Statistics1) << "StructuredRAP: Ac nnz: local = "
1276 << Ac->getLocalNumEntries()
1277 << ", global = " << Ac->getGlobalNumEntries() << std::endl;
1278
1279 Teuchos::ArrayView<const double> relativeFloor = pL.get<Teuchos::Array<double>>("rap: relative diagonal floor")();
1280 if (relativeFloor.size() > 0) {
1281 Xpetra::MatrixUtils<SC, LO, GO, NO>::RelativeDiagonalBoost(Ac, relativeFloor, GetOStream(Statistics2));
1282 }
1283
1284 bool repairZeroDiagonals = pL.get<bool>("RepairMainDiagonal") || pL.get<bool>("rap: fix zero diagonals");
1285 bool checkAc = pL.get<bool>("CheckMainDiagonal") || pL.get<bool>("rap: fix zero diagonals");
1286 if (checkAc || repairZeroDiagonals) {
1287 using magnitudeType = typename Teuchos::ScalarTraits<Scalar>::magnitudeType;
1288 magnitudeType threshold;
1289 if (pL.isType<magnitudeType>("rap: fix zero diagonals threshold"))
1290 threshold = pL.get<magnitudeType>("rap: fix zero diagonals threshold");
1291 else
1292 threshold = Teuchos::as<magnitudeType>(pL.get<double>("rap: fix zero diagonals threshold"));
1293 Scalar replacement = Teuchos::as<Scalar>(pL.get<double>("rap: fix zero diagonals replacement"));
1294 Xpetra::MatrixUtils<SC, LO, GO, NO>::CheckRepairMainDiagonal(Ac, repairZeroDiagonals, GetOStream(Warnings1), threshold, replacement);
1295 }
1296
1297 if (IsPrint(Statistics2)) {
1298 RCP<ParameterList> params = rcp(new ParameterList());
1299 params->set("printLoadBalancingInfo", true);
1300 params->set("printCommInfo", true);
1301
1302 GetOStream(Statistics2) << PerfUtils::PrintMatrixInfo(*Ac, "Ac", params);
1303 }
1304
1305 std::ostringstream oss;
1306 oss << "A_" << coarseLevel.GetLevelID();
1307 Ac->setObjectLabel(oss.str());
1308 Set(coarseLevel, "A", Ac);
1309
1310 RAPparams->set("graph", Ac);
1311 Set(coarseLevel, "RAP reuse data", RAPparams);
1312 }
1313 }
1314 }
1315
1316 if (Behavior::debug())
1317 MatrixUtils::checkLocalRowMapMatchesColMap(*Ac);
1318
1319 if (transferFacts_.begin() != transferFacts_.end()) {
1320 SubFactoryMonitor m(*this, "Projections", coarseLevel);
1321
1322 // call Build of all user-given transfer factories
1323 for (std::vector<RCP<const FactoryBase>>::const_iterator it = transferFacts_.begin(); it != transferFacts_.end(); ++it) {
1324 RCP<const FactoryBase> fac = *it;
1325 GetOStream(Runtime0) << "RAPFactory: call transfer factory: " << fac->description() << std::endl;
1326 fac->CallBuild(coarseLevel);
1327 coarseLevel.Release(*fac);
1328 }
1329 }
1330}
1331
1332template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
1334 // check if it's a TwoLevelFactoryBase based transfer factory
1335 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<const TwoLevelFactoryBase>(factory) == Teuchos::null, Exceptions::BadCast,
1336 "MueLu::StructuredRAPFactory::AddTransferFactory: Transfer factory is not derived from TwoLevelFactoryBase. "
1337 "This is very strange. (Note: you can remove this exception if there's a good reason for)");
1338 TEUCHOS_TEST_FOR_EXCEPTION(hasDeclaredInput_, Exceptions::RuntimeError, "MueLu::StructuredRAPFactory::AddTransferFactory: Factory is being added after we have already declared input");
1339 transferFacts_.push_back(factory);
1340 rapFactoryDelegate_->AddTransferFactory(factory);
1341}
1342
1343} // namespace MueLu
1344
1345#define MUELU_STRUCTUREDRAPFACTORY_SHORT
1346#endif // MUELU_STRUCTUREDRAPFACTORY_DEF_HPP
#define SET_VALID_ENTRY(name)
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
static bool debug()
Whether MueLu is in debug mode.
virtual std::string description() const
Return a simple one-line description of this object.
static void Compute(const Matrix &A, const Matrix &P, Matrix &Ac, const FineStencil &fineStencil, const int interpolationOrder, const Teuchos::Array< LocalOrdinal > &lFineNodesPerDim, const Teuchos::Array< LocalOrdinal > &lCoarseNodesPerDim, const Teuchos::Array< int > &structuredCoarseningRate, const Teuchos::RCP< Teuchos::ParameterList > &params=Teuchos::null)
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory().
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
bool IsAvailable(const std::string &ename, const FactoryBase *factory=NoFactory::get()) const
Test whether a need's value has been saved.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput().
void Release(const FactoryBase &factory)
Decrement the storage counter for all the inputs of a factory.
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
static const NoFactory * get()
virtual const Teuchos::ParameterList & GetParameterList() const
static std::string PrintMatrixInfo(const Matrix &A, const std::string &msgTag, RCP< const Teuchos::ParameterList > params=Teuchos::null)
Factory for building coarse matrices.
RCP< const FactoryBase > GetStructuredMetadataFactory(const std::string &varName) const
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
void DeclareInput(Level &fineLevel, Level &coarseLevel) const
Input.
void Build(Level &fineLevel, Level &coarseLevel) const
Build an object with this factory.
RCP< MueLu::RAPFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > > rapFactoryDelegate_
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
std::vector< RCP< const FactoryBase > > transferFacts_
list of user-defined transfer Factories
void GetStructuredGraph(RCP< Matrix > &Ac, const RCP< Matrix > &P, const Teuchos::Array< LocalOrdinal > &lCoarseNodesPerDim, const StructuredGraphSpec &graphSpec) const
StructuredGraphSpec DeriveCoarseRAPStencil(const FineStencilSpec &fineStencil, int interpolationOrder) const
FineStencilSpec DetectFineStencil(const Matrix &A, int numDimensions, const Teuchos::Array< LocalOrdinal > &lFineNodesPerDim) const
Timer to be used in factories. Similar to SubMonitor but adds a timer level by level.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
bool IsPrint(MsgType type, int thisProcRankOnly=-1) const
Find out whether we need to print out information for a specific message type.
KOKKOS_INLINE_FUNCTION void getLocalNodeIndices(const GO localNode, const LocalNodes &localNodes, GO &x, GO &y, GO &z)
KOKKOS_INLINE_FUNCTION bool resolveNeighbor(const GO x, const GO y, const GO z, const Offset &offset, const LocalNodes &localNodes, const ProcGrid &procGrid, const RankData &rankData, const int myProcX, const int myProcY, const int myProcZ, int &neighborRank, GO &neighborNode)
Namespace for MueLu classes and methods.
@ Statistics2
Print even more statistics.
@ Statistics1
Print more statistics.
@ Runtime0
One-liner description of what is happening.
@ Warnings1
Additional warnings.
static std::string getColonLabel(const std::string &label)
Helper function for object label.