MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_Zoltan2Interface_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_ZOLTAN2INTERFACE_DECL_HPP
11 #define MUELU_ZOLTAN2INTERFACE_DECL_HPP
12 
13 #include "MueLu_ConfigDefs.hpp"
14 
15 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
16 
17 #include <Xpetra_Matrix_fwd.hpp>
19 
22 
23 #include "MueLu_Level_fwd.hpp"
25 
26 #if defined(HAVE_MUELU_ZOLTAN)
27 #include "MueLu_ZoltanInterface.hpp"
28 #endif
29 
30 namespace MueLu {
31 
74 // FIXME: this class should not be templated
75 template <class Scalar,
78  class Node = DefaultNode>
80 #undef MUELU_ZOLTAN2INTERFACE_SHORT
81 #include "MueLu_UseShortNames.hpp"
82 
83  public:
85 
86 
89 
91  virtual ~Zoltan2Interface() {}
93 
95 
97 
98  void DeclareInput(Level& currentLevel) const;
100 
102 
103  void Build(Level& currentLevel) const;
104 
106 
107  private:
109 
110 }; // class Zoltan2Interface
111 
112 #ifdef HAVE_MUELU_EPETRA
113 
114 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
115  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
116 
117 #if defined(HAVE_MUELU_ZOLTAN)
118 // Stub partial specialization of Zoltan2Interface for EpetraNode
119 // Use ZoltanInterface instead of Zoltan2Interface
120 template <>
121 class Zoltan2Interface<double, int, int, Xpetra::EpetraNode> : public SingleLevelFactoryBase {
122  typedef double Scalar;
123  typedef int LocalOrdinal;
124  typedef int GlobalOrdinal;
126 #undef MUELU_ZOLTAN2INTERFACE_SHORT
127 #include "MueLu_UseShortNames.hpp"
128  public:
131 
133  level_ = rcp(new Level());
134  zoltanInterface_ = rcp(new ZoltanInterface());
135 
136  level_->SetLevelID(1);
137  }
138  virtual ~Zoltan2Interface() {
139  zoltanInterface_ = Teuchos::null;
140  level_ = Teuchos::null;
141  }
143  RCP<ParameterList> validParamList = rcp(new ParameterList());
144 
145  validParamList->set<RCP<const FactoryBase> >("A", Teuchos::null, "Factory of the matrix A");
146  validParamList->set<RCP<const FactoryBase> >("Coordinates", Teuchos::null, "Factory of the coordinates");
147  validParamList->set<RCP<const FactoryBase> >("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory.");
148  validParamList->set<RCP<const ParameterList> >("ParameterList", Teuchos::null, "Zoltan2 parameters");
149 
150  return validParamList;
151  };
152  void DeclareInput(Level& currentLevel) const {
153  Input(currentLevel, "A");
154  Input(currentLevel, "number of partitions");
155  const ParameterList& pL = GetParameterList();
156  // We do this dance, because we don't want "ParameterList" to be marked as used.
157  // Is there a better way?
158  Teuchos::ParameterEntry entry = pL.getEntry("ParameterList");
159  RCP<const Teuchos::ParameterList> providedList = Teuchos::any_cast<RCP<const Teuchos::ParameterList> >(entry.getAny(false));
160  if (providedList != Teuchos::null && providedList->isType<std::string>("algorithm")) {
161  const std::string algo = providedList->get<std::string>("algorithm");
162  if (algo == "multijagged" || algo == "rcb")
163  Input(currentLevel, "Coordinates");
164  } else
165  Input(currentLevel, "Coordinates");
166  };
167  void Build(Level& currentLevel) const {
168  this->GetOStream(Warnings0) << "Tpetra does not support <double,int,int,EpetraNode> instantiation, "
169  "switching Zoltan2Interface to ZoltanInterface"
170  << std::endl;
171 
172  // Put the data into a fake level
173  level_->Set("A", Get<RCP<Matrix> >(currentLevel, "A"));
174  level_->Set("Coordinates", Get<RCP<RealValuedMultiVector> >(currentLevel, "Coordinates"));
175  level_->Set("number of partitions", currentLevel.Get<GO>("number of partitions"));
176 
177  level_->Request("Partition", zoltanInterface_.get());
178  zoltanInterface_->Build(*level_);
179 
180  RCP<Xpetra::Vector<GO, LO, GO, NO> > decomposition;
181  level_->Get("Partition", decomposition, zoltanInterface_.get());
182  Set(currentLevel, "Partition", decomposition);
183  };
184 
185  private:
186  RCP<Level> level_; // fake Level
188 };
189 #else
190 // Stub partial specialization of Zoltan2Interface for EpetraNode
191 template <>
192 class Zoltan2Interface<double, int, int, Xpetra::EpetraNode> : public SingleLevelFactoryBase {
193  public:
194  Zoltan2Interface() { throw Exceptions::RuntimeError("Tpetra does not support <double,int,int,EpetraNode> instantiation"); }
195  virtual ~Zoltan2Interface() {}
196  RCP<const ParameterList> GetValidParameterList() const { return Teuchos::null; };
197  void DeclareInput(Level& level) const {};
198  void Build(Level& level) const {};
199 };
200 #endif // HAVE_MUELU_ZOLTAN
201 
202 #endif
203 
204 #endif // HAVE_MUELU_EPETRA
205 
206 } // namespace MueLu
207 
208 #define MUELU_ZOLTAN2INTERFACE_SHORT
209 #endif // if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
210 
211 #endif // MUELU_ZOLTAN2INTERFACE_DECL_HPP
Important warning messages (one line)
virtual const Teuchos::ParameterList & GetParameterList() const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
MueLu::DefaultLocalOrdinal LocalOrdinal
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode
GlobalOrdinal GO
T & get(const std::string &name, T def_value)
T Get(Level &level, const std::string &varName) const
T * get() const
void Build(Level &currentLevel) const
Build an object with this factory.
Interface to Zoltan library.This interface provides access to partitioning methods in Zoltan...
virtual ~Zoltan2Interface()
Destructor.
MueLu::DefaultNode Node
void Build(Level &currentLevel) const
Build an object with this factory.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:63
Interface to Zoltan2 library.This interface provides access to partitioning methods in Zoltan2...
void Set(Level &level, const std::string &varName, const T &data) const
any & getAny(bool activeQry=true)
bool isType(const std::string &name) const
Exception throws to report errors in the internal logical of the program.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
ParameterEntry & getEntry(const std::string &name)
void Input(Level &level, const std::string &varName) const
Base class for factories that use one level (currentLevel).
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.