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> 20 #ifdef HAVE_MUELU_ISORROPIA 21 #include <Isorropia_Exception.hpp> 24 #ifdef HAVE_MUELU_EPETRA 25 #include <Xpetra_EpetraCrsGraph.hpp> 26 #include <Epetra_CrsGraph.h> 27 #include <Isorropia_EpetraPartitioner.hpp> 30 #ifdef HAVE_MUELU_TPETRA 31 #include <Xpetra_TpetraCrsGraph.hpp> 32 #include <Tpetra_CrsGraph.hpp> 33 #ifdef HAVE_ISORROPIA_TPETRA 34 #include <Isorropia_TpetraPartitioner.hpp> 35 #endif // HAVE_ISORROPIA_TPETRA 37 #endif // ENDIF HAVE_MUELU_ISORROPIA 42 #include "MueLu_Graph.hpp" 43 #include "MueLu_AmalgamationFactory.hpp" 44 #include "MueLu_AmalgamationInfo.hpp" 45 #include "MueLu_Utilities.hpp" 49 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
51 RCP<ParameterList> validParamList = rcp(
new ParameterList());
53 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Factory of the matrix A");
54 validParamList->set< RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
55 validParamList->set< RCP<const FactoryBase> >(
"UnAmalgamationInfo", Teuchos::null,
"Generating factory of UnAmalgamationInfo");
57 return validParamList;
61 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 Input(currentLevel,
"A");
64 Input(currentLevel,
"number of partitions");
65 Input(currentLevel,
"UnAmalgamationInfo");
68 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 RCP<Matrix> A = Get< RCP<Matrix> >(level,
"A");
73 RCP<AmalgamationInfo> amalInfo = Get< RCP<AmalgamationInfo> >(level,
"UnAmalgamationInfo");
74 GO numParts = Get< int >(level,
"number of partitions");
76 RCP<const Map> rowMap = A->getRowMap();
77 RCP<const Map> colMap = A->getColMap();
79 if (numParts == 1 || numParts == -1) {
81 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
82 Set(level,
"AmalgamatedPartition", decomposition);
99 GO indexBase = rowMap->getIndexBase();
102 LO nStridedOffset = 0;
103 LO stridedblocksize = blockdim;
107 if(A->IsView(
"stridedMaps") &&
108 Teuchos::rcp_dynamic_cast<
const StridedMap>(A->getRowMap(
"stridedMaps")) != Teuchos::null) {
109 Xpetra::viewLabel_t oldView = A->SwitchToView(
"stridedMaps");
110 RCP<const StridedMap> strMap = Teuchos::rcp_dynamic_cast<
const StridedMap>(A->getRowMap());
111 TEUCHOS_TEST_FOR_EXCEPTION(strMap == Teuchos::null,
Exceptions::BadCast,
"MueLu::IsorropiaInterface::Build: cast to strided row map failed.");
112 blockdim = strMap->getFixedBlockSize();
113 offset = strMap->getOffset();
114 blockid = strMap->getStridedBlockId();
116 std::vector<size_t> stridingInfo = strMap->getStridingData();
117 for (
size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
118 nStridedOffset += stridingInfo[j];
119 stridedblocksize = Teuchos::as<LocalOrdinal>(stridingInfo[blockid]);
122 stridedblocksize = blockdim;
124 oldView = A->SwitchToView(oldView);
126 }
else GetOStream(
Statistics0) <<
"IsorropiaInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
130 RCP<const Map> nodeMap = amalInfo->getNodeRowMap();
131 GetOStream(
Statistics0) <<
"IsorropiaInterface:Build(): nodeMap " << nodeMap->getNodeNumElements() <<
"/" << nodeMap->getGlobalNumElements() <<
" elements" << std::endl;
134 RCP<CrsGraph> crsGraph = CrsGraphFactory::Build(nodeMap, 10, Xpetra::DynamicProfile);
137 for(LO row=0; row<Teuchos::as<LO>(A->getRowMap()->getNodeNumElements()); row++) {
139 GO grid = rowMap->getGlobalElement(row);
144 size_t nnz = A->getNumEntriesInLocalRow(row);
145 Teuchos::ArrayView<const LO> indices;
146 Teuchos::ArrayView<const SC> vals;
147 A->getLocalRowView(row, indices, vals);
149 RCP<std::vector<GO> > cnodeIds = Teuchos::rcp(
new std::vector<GO>);
151 for(LO col=0; col<Teuchos::as<LO>(nnz); col++) {
152 GO gcid = colMap->getGlobalElement(indices[col]);
156 cnodeIds->push_back(cnodeId);
161 Teuchos::ArrayRCP<GO> arr_cnodeIds = Teuchos::arcp( cnodeIds );
163 if(arr_cnodeIds.size() > 0 )
164 crsGraph->insertGlobalIndices(nodeId, arr_cnodeIds());
167 crsGraph->fillComplete(nodeMap,nodeMap);
170 #ifdef HAVE_MUELU_ISORROPIA 173 Teuchos::ParameterList paramlist;
174 paramlist.set(
"NUM PARTS",
toString(numParts));
182 Teuchos::ParameterList& sublist = paramlist.sublist(
"Zoltan");
183 sublist.set(
"LB_APPROACH",
"PARTITION");
187 #ifdef HAVE_MUELU_EPETRA 188 RCP< Xpetra::EpetraCrsGraphT<GO, Node> > epCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::EpetraCrsGraphT<GO, Node> >(crsGraph);
189 if(epCrsGraph != Teuchos::null) {
190 RCP< const Epetra_CrsGraph> epetraCrsGraph = epCrsGraph->getEpetra_CrsGraph();
192 RCP<Isorropia::Epetra::Partitioner> isoPart = Teuchos::rcp(
new Isorropia::Epetra::Partitioner(epetraCrsGraph,paramlist));
195 const int* array = NULL;
196 isoPart->extractPartsView(size,array);
198 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");
200 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(nodeMap,
false);
201 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
204 for(
int i = 0; i<size; i++) {
205 decompEntries[i] = Teuchos::as<GO>(array[i]);
208 Set(level,
"AmalgamatedPartition", decomposition);
211 #endif // ENDIF HAVE_MUELU_EPETRA 213 #ifdef HAVE_MUELU_TPETRA 214 #ifdef HAVE_MUELU_INST_DOUBLE_INT_INT 216 RCP< Xpetra::TpetraCrsGraph<LO, GO, Node> > tpCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::TpetraCrsGraph<LO, GO, Node> >(crsGraph);
217 if(tpCrsGraph != Teuchos::null) {
218 #ifdef HAVE_ISORROPIA_TPETRA 219 RCP< const Tpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > tpetraCrsGraph = tpCrsGraph->getTpetra_CrsGraph();
220 RCP<Isorropia::Tpetra::Partitioner<Node> > isoPart = rcp(
new Isorropia::Tpetra::Partitioner<Node>(tpetraCrsGraph, paramlist));
223 const int* array = NULL;
224 isoPart->extractPartsView(size,array);
226 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");
228 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(nodeMap,
false);
229 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
234 for(
int i = 0; i<size; i++) {
235 decompEntries[i] = Teuchos::as<GO>(array[i]);
238 Set(level,
"AmalgamatedPartition", decomposition);
241 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Tpetra is not enabled for Isorropia. Recompile Isorropia with Tpetra support.");
242 #endif // ENDIF HAVE_ISORROPIA_TPETRA 245 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Isorropia is an interface to Zoltan which only has support for LO=GO=int and SC=double.");
246 #endif // ENDIF HAVE_MUELU_INST_DOUBLE_INT_INT 247 #endif // ENDIF HAVE_MUELU_TPETRA 248 #endif // HAVE_MUELU_ISORROPIA 249 #else // if we don't have MPI 253 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
254 Set(level,
"AmalgamatedPartition", decomposition);
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Exception indicating invalid cast attempted.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
void Build(Level &level) const
Build an object with this factory.
Timer to be used in factories. Similar to Monitor but with additional timers.
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.
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
Exception throws to report errors in the internal logical of the program.