8 #ifndef MUELU_REPARTITIONINTERFACE_DEF_HPP_
9 #define MUELU_REPARTITIONINTERFACE_DEF_HPP_
16 #include "MueLu_Graph.hpp"
17 #include "MueLu_AmalgamationFactory.hpp"
18 #include "MueLu_AmalgamationInfo.hpp"
19 #include "MueLu_Utilities.hpp"
24 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
26 RCP<ParameterList> validParamList = rcp(
new ParameterList());
27 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Factory of the matrix A");
28 validParamList->set< RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
29 validParamList->set< RCP<const FactoryBase> >(
"AmalgamatedPartition", Teuchos::null,
"(advanced) Factory generating the AmalgamatedPartition (e.g. an IsorropiaInterface)");
31 return validParamList;
35 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
37 Input(currentLevel,
"A");
38 Input(currentLevel,
"number of partitions");
39 Input(currentLevel,
"AmalgamatedPartition");
42 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
46 RCP<Matrix> A = Get< RCP<Matrix> > (level,
"A");
47 RCP<Xpetra::Vector<GO, LO, GO, NO> > amalgPartition = Get< RCP<Xpetra::Vector<GO, LO, GO, NO> > >(level,
"AmalgamatedPartition");
48 int numParts = Get<int>(level,
"number of partitions");
50 RCP<const Map> rowMap = A->getRowMap();
53 RCP<const Teuchos::Comm< int > > comm = A->getRowMap()->getComm();
56 if (numParts == 1 || numParts == -1) {
58 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
59 Set(level,
"Partition", decomposition);
69 ArrayRCP<GO> amalgPartitionData = amalgPartition->getDataNonConst(0);
70 RCP<const Map> nodeMap = amalgPartition->getMap();
75 LO nStridedOffset = 0;
76 LO stridedblocksize = blockdim;
80 if(A->IsView(
"stridedMaps") &&
81 Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap(
"stridedMaps")) != Teuchos::null) {
82 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
83 RCP<const StridedMap> strMap = Teuchos::rcp_dynamic_cast<const StridedMap>(A->getRowMap());
84 TEUCHOS_TEST_FOR_EXCEPTION(strMap == Teuchos::null,
Exceptions::BadCast,
"MueLu::RepartitionInterface::Build: cast to strided row map failed.");
85 blockdim = strMap->getFixedBlockSize();
86 blockid = strMap->getStridedBlockId();
88 std::vector<size_t> stridingInfo = strMap->getStridingData();
89 for (
size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
90 nStridedOffset += stridingInfo[j];
91 stridedblocksize = Teuchos::as<LocalOrdinal>(stridingInfo[blockid]);
94 stridedblocksize = blockdim;
96 oldView = A->SwitchToView(oldView);
98 }
else GetOStream(
Statistics0, -1) <<
"RepartitionInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
101 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
false);
102 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
104 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::as<int>(nodeMap->getNodeNumElements())*stridedblocksize != Teuchos::as<int>(rowMap->getNodeNumElements()),
Exceptions::RuntimeError,
"Inconsistency between nodeMap and dofMap: we are supporting block maps only. No support for general strided maps, yet!");
111 for(
size_t i = 0; i < nodeMap->getNodeNumElements(); i++) {
123 for (LO j = 0; j < stridedblocksize; j++) {
129 decompEntries[i*stridedblocksize + j] = amalgPartitionData[i];
135 Set(level,
"Partition", decomposition);