8 #ifndef MUELU_ISORROPIAINTERFACE_DEF_HPP_ 9 #define MUELU_ISORROPIAINTERFACE_DEF_HPP_ 13 #include <Teuchos_Utils.hpp> 17 #include <Xpetra_MapFactory.hpp> 18 #include <Xpetra_CrsGraphFactory.hpp> 19 #include <Xpetra_BlockedMap.hpp> 20 #include <Xpetra_BlockedCrsMatrix.hpp> 22 #ifdef HAVE_MUELU_ISORROPIA 23 #include <Isorropia_Exception.hpp> 26 #ifdef HAVE_MUELU_EPETRA 27 #include <Xpetra_EpetraCrsGraph.hpp> 28 #include <Epetra_CrsGraph.h> 29 #include <Isorropia_EpetraPartitioner.hpp> 32 #ifdef HAVE_MUELU_TPETRA 33 #include <Xpetra_TpetraCrsGraph.hpp> 35 #endif // ENDIF HAVE_MUELU_ISORROPIA 40 #include "MueLu_Graph.hpp" 41 #include "MueLu_AmalgamationFactory.hpp" 42 #include "MueLu_AmalgamationInfo.hpp" 43 #include "MueLu_Utilities.hpp" 47 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
49 RCP<ParameterList> validParamList = rcp(
new ParameterList());
51 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Factory of the matrix A");
52 validParamList->set< RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
53 validParamList->set< RCP<const FactoryBase> >(
"UnAmalgamationInfo", Teuchos::null,
"Generating factory of UnAmalgamationInfo");
55 return validParamList;
59 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
61 Input(currentLevel,
"A");
62 Input(currentLevel,
"number of partitions");
63 Input(currentLevel,
"UnAmalgamationInfo");
66 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 typedef Xpetra::BlockedMap<LocalOrdinal, GlobalOrdinal, Node> BlockMap;
71 RCP<Matrix> A = Get< RCP<Matrix> >(level,
"A");
72 RCP<AmalgamationInfo> amalInfo = Get< RCP<AmalgamationInfo> >(level,
"UnAmalgamationInfo");
73 GO numParts = Get< int >(level,
"number of partitions");
75 RCP<const Map> rowMap = A->getRowMap();
76 RCP<const Map> colMap = A->getColMap();
78 if (numParts == 1 || numParts == -1) {
80 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
81 Set(level,
"AmalgamatedPartition", decomposition);
98 GO indexBase = rowMap->getIndexBase();
101 LO nStridedOffset = 0;
106 if(A->IsView(
"stridedMaps") &&
107 Teuchos::rcp_dynamic_cast<
const StridedMap>(A->getRowMap(
"stridedMaps")) != Teuchos::null) {
108 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
109 RCP<const StridedMap> strMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(A->getRowMap());
110 TEUCHOS_TEST_FOR_EXCEPTION(strMap == Teuchos::null,
Exceptions::BadCast,
"MueLu::IsorropiaInterface::Build: cast to strided row map failed.");
111 blockdim = strMap->getFixedBlockSize();
112 offset = strMap->getOffset();
113 blockid = strMap->getStridedBlockId();
115 std::vector<size_t> stridingInfo = strMap->getStridingData();
116 for (
size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
117 nStridedOffset += stridingInfo[j];
123 oldView = A->SwitchToView(oldView);
125 }
else GetOStream(
Statistics0) <<
"IsorropiaInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
129 RCP<const Map> nodeMap= amalInfo->getNodeRowMap();
130 RCP<const BlockedMap> bnodeMap = Teuchos::rcp_dynamic_cast<
const BlockedMap>(nodeMap);
131 if(!bnodeMap.is_null()) nodeMap=bnodeMap->getMap();
133 GetOStream(
Statistics0) <<
"IsorropiaInterface:Build(): nodeMap " << nodeMap->getNodeNumElements() <<
"/" << nodeMap->getGlobalNumElements() <<
" elements" << std::endl;
137 RCP<CrsGraph> crsGraph = CrsGraphFactory::Build(nodeMap, 10, Xpetra::DynamicProfile);
140 for(LO row=0; row<Teuchos::as<LO>(A->getRowMap()->getNodeNumElements()); row++) {
142 GO grid = rowMap->getGlobalElement(row);
147 size_t nnz = A->getNumEntriesInLocalRow(row);
148 Teuchos::ArrayView<const LO> indices;
149 Teuchos::ArrayView<const SC> vals;
150 A->getLocalRowView(row, indices, vals);
152 RCP<std::vector<GO> > cnodeIds = Teuchos::rcp(
new std::vector<GO>);
154 for(LO col=0; col<Teuchos::as<LO>(nnz); col++) {
155 GO gcid = colMap->getGlobalElement(indices[col]);
159 cnodeIds->push_back(cnodeId);
164 Teuchos::ArrayRCP<GO> arr_cnodeIds = Teuchos::arcp( cnodeIds );
166 if(arr_cnodeIds.size() > 0 )
167 crsGraph->insertGlobalIndices(nodeId, arr_cnodeIds());
170 crsGraph->fillComplete(nodeMap,nodeMap);
173 #ifdef HAVE_MUELU_ISORROPIA 176 Teuchos::ParameterList paramlist;
177 paramlist.set(
"NUM PARTS",
toString(numParts));
185 Teuchos::ParameterList& sublist = paramlist.sublist(
"Zoltan");
186 sublist.set(
"LB_APPROACH",
"PARTITION");
190 #ifdef HAVE_MUELU_EPETRA 191 RCP< Xpetra::EpetraCrsGraphT<GO, Node> > epCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::EpetraCrsGraphT<GO, Node> >(crsGraph);
192 if(epCrsGraph != Teuchos::null) {
193 RCP< const Epetra_CrsGraph> epetraCrsGraph = epCrsGraph->getEpetra_CrsGraph();
195 RCP<Isorropia::Epetra::Partitioner> isoPart = Teuchos::rcp(
new Isorropia::Epetra::Partitioner(epetraCrsGraph,paramlist));
198 const int* array = NULL;
199 isoPart->extractPartsView(size,array);
201 TEUCHOS_TEST_FOR_EXCEPTION(size != Teuchos::as<int>(nodeMap->getNodeNumElements()),
Exceptions::RuntimeError,
"length of array returned from extractPartsView does not match local length of rowMap");
203 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(nodeMap,
false);
204 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
207 for(
int i = 0; i<size; i++) {
208 decompEntries[i] = Teuchos::as<GO>(array[i]);
211 Set(level,
"AmalgamatedPartition", decomposition);
214 #endif // ENDIF HAVE_MUELU_EPETRA 216 #ifdef HAVE_MUELU_TPETRA 217 #ifdef HAVE_MUELU_INST_DOUBLE_INT_INT 218 RCP< Xpetra::TpetraCrsGraph<LO, GO, Node> > tpCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::TpetraCrsGraph<LO, GO, Node> >(crsGraph);
219 TEUCHOS_TEST_FOR_EXCEPTION(tpCrsGraph != Teuchos::null,
Exceptions::RuntimeError,
"Tpetra is not supported with Isorropia.");
221 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Isorropia is an interface to Zoltan which only has support for LO=GO=int and SC=double.");
222 #endif // ENDIF HAVE_MUELU_INST_DOUBLE_INT_INT 223 #endif // ENDIF HAVE_MUELU_TPETRA 224 #endif // HAVE_MUELU_ISORROPIA 225 #else // if we don't have MPI 229 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
230 Set(level,
"AmalgamatedPartition", decomposition);
Exception indicating invalid cast attempted.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
Timer to be used in factories. Similar to Monitor but with additional timers.
void Build(Level &level) const
Build an object with this factory.
Namespace for MueLu classes and methods.
static const GlobalOrdinal DOFGid2NodeId(GlobalOrdinal gid, LocalOrdinal blockSize, const GlobalOrdinal offset, const GlobalOrdinal indexBase)
translate global (row/column) id to global amalgamation block id
Print statistics that do not involve significant additional computation.
Class that holds all level-specific information.
Exception throws to report errors in the internal logical of the program.