17 #ifndef MUELU_ISORROPIAINTERFACE_DEF_HPP_
18 #define MUELU_ISORROPIAINTERFACE_DEF_HPP_
26 #include <Xpetra_MapFactory.hpp>
28 #include <Xpetra_BlockedMap.hpp>
31 #ifdef HAVE_MUELU_ISORROPIA
32 #include <Isorropia_Exception.hpp>
34 #ifdef HAVE_MUELU_EPETRA
36 #include <Epetra_CrsGraph.h>
37 #include <Isorropia_EpetraPartitioner.hpp>
40 #include <Xpetra_TpetraCrsGraph.hpp>
41 #endif // ENDIF HAVE_MUELU_ISORROPIA
47 #include "MueLu_AmalgamationInfo.hpp"
51 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
56 validParamList->
set<
RCP<const FactoryBase> >(
"number of partitions", Teuchos::null,
"Instance of RepartitionHeuristicFactory.");
57 validParamList->
set<
RCP<const FactoryBase> >(
"UnAmalgamationInfo", Teuchos::null,
"Generating factory of UnAmalgamationInfo");
59 return validParamList;
62 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
64 Input(currentLevel,
"A");
65 Input(currentLevel,
"number of partitions");
66 Input(currentLevel,
"UnAmalgamationInfo");
69 template <
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 GO numParts = Get<int>(level,
"number of partitions");
81 if (numParts == 1 || numParts == -1) {
84 Set(level,
"AmalgamatedPartition", decomposition);
101 GO indexBase = rowMap->getIndexBase();
104 LO nStridedOffset = 0;
109 if (A->IsView(
"stridedMaps") &&
110 Teuchos::rcp_dynamic_cast<
const StridedMap>(A->getRowMap(
"stridedMaps")) != Teuchos::null) {
114 blockdim = strMap->getFixedBlockSize();
115 offset = strMap->getOffset();
116 blockid = strMap->getStridedBlockId();
118 std::vector<size_t> stridingInfo = strMap->getStridingData();
119 for (
size_t j = 0; j < Teuchos::as<size_t>(blockid); j++)
120 nStridedOffset += stridingInfo[j];
126 oldView = A->SwitchToView(oldView);
129 GetOStream(
Statistics0) <<
"IsorropiaInterface::Build(): no striding information available. Use blockdim=1 with offset=0" << std::endl;
135 if (!bnodeMap.
is_null()) nodeMap = bnodeMap->getMap();
137 GetOStream(
Statistics0) <<
"IsorropiaInterface:Build(): nodeMap " << nodeMap->getLocalNumElements() <<
"/" << nodeMap->getGlobalNumElements() <<
" elements" << std::endl;
140 RCP<CrsGraph> crsGraph = CrsGraphFactory::Build(nodeMap, A->getLocalMaxNumRowEntries() * blockdim);
143 for (
LO row = 0; row < Teuchos::as<LO>(A->getRowMap()->getLocalNumElements()); row++) {
145 GO grid = rowMap->getGlobalElement(row);
150 GO nodeId = (grid - offset - indexBase) / blockdim + indexBase;
152 size_t nnz = A->getNumEntriesInLocalRow(row);
155 A->getLocalRowView(row, indices, vals);
159 for (
LO col = 0; col < Teuchos::as<LO>(nnz); col++) {
160 GO gcid = colMap->getGlobalElement(indices[col]);
162 if (vals[col] != 0.0) {
165 GO cnodeId = (gcid - offset - indexBase) / blockdim + indexBase;
166 cnodeIds->push_back(cnodeId);
173 if (arr_cnodeIds.
size() > 0)
174 crsGraph->insertGlobalIndices(nodeId, arr_cnodeIds());
177 crsGraph->fillComplete(nodeMap, nodeMap);
180 #ifdef HAVE_MUELU_ISORROPIA
193 sublist.
set(
"LB_APPROACH",
"PARTITION");
195 #ifdef HAVE_MUELU_EPETRA
197 if (epCrsGraph != Teuchos::null) {
203 const int* array = NULL;
204 isoPart->extractPartsView(size, array);
209 ArrayRCP<GO> decompEntries = decomposition->getDataNonConst(0);
212 for (
int i = 0; i < size; i++) {
213 decompEntries[i] = Teuchos::as<GO>(array[i]);
216 Set(level,
"AmalgamatedPartition", decomposition);
218 #endif // ENDIF HAVE_MUELU_EPETRA
220 #ifdef HAVE_MUELU_INST_DOUBLE_INT_INT
224 TEUCHOS_TEST_FOR_EXCEPTION(
false,
Exceptions::RuntimeError,
"Isorropia is an interface to Zoltan which only has support for LO=GO=int and SC=double.");
225 #endif // ENDIF HAVE_MUELU_INST_DOUBLE_INT_INT
226 #endif // HAVE_MUELU_ISORROPIA
227 #else // if we don't have MPI
231 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.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Print statistics that do not involve significant additional computation.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
static RCP< Vector > Build(const Teuchos::RCP< const Map > &map, bool zeroOut=true)
void DeclareInput(Level &level) const
Specifies the data that this class needs, and the factories that generate that data.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Exception throws to report errors in the internal logical of the program.