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> >(
"UnAmalgamationInfo", Teuchos::null,
"Generating factory of UnAmalgamationInfo");
56 return validParamList;
60 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
62 Input(currentLevel,
"A");
63 Input(currentLevel,
"UnAmalgamationInfo");
66 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
70 RCP<Matrix> A = Get< RCP<Matrix> >(level,
"A");
71 RCP<AmalgamationInfo> amalInfo = Get< RCP<AmalgamationInfo> >(level,
"UnAmalgamationInfo");
72 GO numParts = level.Get<GO>(
"number of partitions");
74 RCP<const Map> rowMap = A->getRowMap();
75 RCP<const Map> colMap = A->getColMap();
79 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;
102 LO stridedblocksize = blockdim;
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];
118 stridedblocksize = Teuchos::as<LocalOrdinal>(stridingInfo[blockid]);
121 stridedblocksize = blockdim;
123 oldView = A->SwitchToView(oldView);
124 GetOStream(
Statistics0, -1) <<
"IsorropiaInterface::Build():" <<
" found blockdim=" << blockdim <<
" from strided maps (blockid=" << blockid <<
", strided block size=" << stridedblocksize <<
"). offset=" << offset << std::endl;
125 }
else GetOStream(
Statistics0, -1) <<
"IsorropiaInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
129 RCP<const Map> nodeMap = amalInfo->getNodeRowMap();
130 GetOStream(
Statistics0) <<
"IsorropiaInterface:Build(): nodeMap " << nodeMap->getNodeNumElements() <<
"/" << nodeMap->getGlobalNumElements() <<
" elements" << std::endl;
133 RCP<CrsGraph> crsGraph = CrsGraphFactory::Build(nodeMap, 10, Xpetra::DynamicProfile);
136 for(LO row=0; row<Teuchos::as<LO>(A->getRowMap()->getNodeNumElements()); row++) {
138 GO grid = rowMap->getGlobalElement(row);
143 size_t nnz = A->getNumEntriesInLocalRow(row);
144 Teuchos::ArrayView<const LO> indices;
145 Teuchos::ArrayView<const SC> vals;
146 A->getLocalRowView(row, indices, vals);
148 RCP<std::vector<GO> > cnodeIds = Teuchos::rcp(
new std::vector<GO>);
150 for(LO col=0; col<Teuchos::as<LO>(nnz); col++) {
151 GO gcid = colMap->getGlobalElement(indices[col]);
155 cnodeIds->push_back(cnodeId);
160 Teuchos::ArrayRCP<GO> arr_cnodeIds = Teuchos::arcp( cnodeIds );
162 if(arr_cnodeIds.size() > 0 )
163 crsGraph->insertGlobalIndices(nodeId, arr_cnodeIds());
166 crsGraph->fillComplete(nodeMap,nodeMap);
169 #ifdef HAVE_MUELU_ISORROPIA 172 Teuchos::ParameterList paramlist;
173 paramlist.set(
"NUM PARTS",
toString(numParts));
181 Teuchos::ParameterList& sublist = paramlist.sublist(
"Zoltan");
182 sublist.set(
"LB_APPROACH",
"PARTITION");
186 #ifdef HAVE_MUELU_EPETRA 187 RCP< Xpetra::EpetraCrsGraphT<GO, Node> > epCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::EpetraCrsGraphT<GO, Node> >(crsGraph);
188 if(epCrsGraph != Teuchos::null) {
189 RCP< const Epetra_CrsGraph> epetraCrsGraph = epCrsGraph->getEpetra_CrsGraph();
191 RCP<Isorropia::Epetra::Partitioner> isoPart = Teuchos::rcp(
new Isorropia::Epetra::Partitioner(epetraCrsGraph,paramlist));
194 const int* array = NULL;
195 isoPart->extractPartsView(size,array);
197 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");
199 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(nodeMap,
false);
200 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
203 for(
int i = 0; i<size; i++) {
204 decompEntries[i] = Teuchos::as<GO>(array[i]);
207 Set(level,
"AmalgamatedPartition", decomposition);
210 #endif // ENDIF HAVE_MUELU_EPETRA 212 #ifdef HAVE_MUELU_TPETRA 213 #ifdef HAVE_MUELU_INST_DOUBLE_INT_INT 215 RCP< Xpetra::TpetraCrsGraph<LO, GO, Node> > tpCrsGraph = Teuchos::rcp_dynamic_cast<Xpetra::TpetraCrsGraph<LO, GO, Node> >(crsGraph);
216 if(tpCrsGraph != Teuchos::null) {
217 #ifdef HAVE_ISORROPIA_TPETRA 218 RCP< const Tpetra::CrsGraph<LocalOrdinal, GlobalOrdinal, Node> > tpetraCrsGraph = tpCrsGraph->getTpetra_CrsGraph();
219 RCP<Isorropia::Tpetra::Partitioner<Node> > isoPart = rcp(
new Isorropia::Tpetra::Partitioner<Node>(tpetraCrsGraph, paramlist));
222 const int* array = NULL;
223 isoPart->extractPartsView(size,array);
225 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");
227 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(nodeMap,
false);
228 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
233 for(
int i = 0; i<size; i++) {
234 decompEntries[i] = Teuchos::as<GO>(array[i]);
237 Set(level,
"AmalgamatedPartition", decomposition);
240 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Tpetra is not enabled for Isorropia. Recompile Isorropia with Tpetra support.");
241 #endif // ENDIF HAVE_ISORROPIA_TPETRA 244 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Isorropia is an interface to Zoltan which only has support for LO=GO=int and SC=double.");
245 #endif // ENDIF HAVE_MUELU_INST_DOUBLE_INT_INT 246 #endif // ENDIF HAVE_MUELU_TPETRA 247 #endif // HAVE_MUELU_ISORROPIA 248 #else // if we don't have MPI 252 RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition = Xpetra::VectorFactory<GO, LO, GO, NO>::Build(rowMap,
true);
253 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.