MueLu  Version of the Day
MueLu_Zoltan2Interface_decl.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef MUELU_ZOLTAN2INTERFACE_DECL_HPP
47 #define MUELU_ZOLTAN2INTERFACE_DECL_HPP
48 
49 #include "MueLu_ConfigDefs.hpp"
50 
51 #if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
52 
53 #include <Xpetra_Matrix.hpp>
54 #include <Xpetra_VectorFactory.hpp>
55 
58 
59 #include "MueLu_Level_fwd.hpp"
61 #include "MueLu_Utilities_fwd.hpp"
62 
63 #if defined(HAVE_MUELU_ZOLTAN)
64 #include "MueLu_ZoltanInterface.hpp"
65 #endif
66 
67 namespace MueLu {
68 
69 
113  //FIXME: this class should not be templated
114  template <class Scalar,
115  class LocalOrdinal = typename Xpetra::Matrix<Scalar>::local_ordinal_type,
116  class GlobalOrdinal = typename Xpetra::Matrix<Scalar, LocalOrdinal>::global_ordinal_type,
117  class Node = typename Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal>::node_type>
119 #undef MUELU_ZOLTAN2INTERFACE_SHORT
120 #include "MueLu_UseShortNames.hpp"
121 
122  public:
123 
125 
126 
129 
131  virtual ~Zoltan2Interface() { }
133 
135 
137 
138  void DeclareInput(Level& currentLevel) const;
140 
142 
143  void Build(Level& currentLevel) const;
144 
146 
147  private:
149 
150  }; //class Zoltan2Interface
151 
152 #ifdef HAVE_MUELU_EPETRA
153 
154 #if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
155  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
156 
157 #if defined(HAVE_MUELU_ZOLTAN)
158  // Stub partial specialization of Zoltan2Interface for EpetraNode
159  // Use ZoltanInterface instead of Zoltan2Interface
160  template<>
161  class Zoltan2Interface<double,int,int,Xpetra::EpetraNode> : public SingleLevelFactoryBase {
162  typedef double Scalar;
163  typedef int LocalOrdinal;
164  typedef int GlobalOrdinal;
166 #undef MUELU_ZOLTAN2INTERFACE_SHORT
167 #include "MueLu_UseShortNames.hpp"
168  public:
170  level_ = rcp(new Level());
171  zoltanInterface_ = rcp(new ZoltanInterface());
172 
173  level_->SetLevelID(1);
174  }
175  virtual ~Zoltan2Interface() {
176  zoltanInterface_ = Teuchos::null;
177  level_ = Teuchos::null;
178  }
180  RCP<ParameterList> validParamList = rcp(new ParameterList());
181 
182  validParamList->set< RCP<const FactoryBase> > ("A", Teuchos::null, "Factory of the matrix A");
183  validParamList->set< RCP<const FactoryBase> > ("Coordinates", Teuchos::null, "Factory of the coordinates");
184  validParamList->set< RCP<const FactoryBase> > ("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory.");
185  validParamList->set< RCP<const ParameterList> > ("ParameterList", Teuchos::null, "Zoltan2 parameters");
186 
187  return validParamList;
188  };
189  void DeclareInput(Level& currentLevel) const {
190  Input(currentLevel, "A");
191  Input(currentLevel, "number of partitions");
192  Input(currentLevel, "Coordinates");
193  };
194  void Build(Level& currentLevel) const {
195  this->GetOStream(Warnings0) << "Tpetra does not support <double,int,int,EpetraNode> instantiation, "
196  "switching Zoltan2Interface to ZoltanInterface" << std::endl;
197 
198  typedef Xpetra::MultiVector<double, LocalOrdinal, GlobalOrdinal, Node> dMultiVector;
199 
200  // Put the data into a fake level
201  level_->Set("A", Get<RCP<Matrix> > (currentLevel, "A"));
202  level_->Set("Coordinates", Get<RCP<dMultiVector> >(currentLevel, "Coordinates"));
203  level_->Set("number of partitions", currentLevel.Get<GO>("number of partitions"));
204 
205  level_->Request("Partition", zoltanInterface_.get());
206  zoltanInterface_->Build(*level_);
207 
208  RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition;
209  level_->Get("Partition", decomposition, zoltanInterface_.get());
210  Set(currentLevel, "Partition", decomposition);
211  };
212 
213  private:
214  RCP<Level> level_; // fake Level
216  };
217 #else
218  // Stub partial specialization of Zoltan2Interface for EpetraNode
219  template<>
220  class Zoltan2Interface<double,int,int,Xpetra::EpetraNode> : public SingleLevelFactoryBase {
221  public:
222  Zoltan2Interface() { throw Exceptions::RuntimeError("Tpetra does not support <double,int,int,EpetraNode> instantiation"); }
223  virtual ~Zoltan2Interface() { }
224  RCP<const ParameterList> GetValidParameterList() const { return Teuchos::null; };
225  void DeclareInput(Level& level) const {};
226  void Build(Level &level) const {};
227  };
228 #endif // HAVE_MUELU_ZOLTAN
229 
230 #endif
231 
232 #endif // HAVE_MUELU_EPETRA
233 
234 } //namespace MueLu
235 
236 #define MUELU_ZOLTAN2INTERFACE_SHORT
237 #endif //if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
238 
239 #endif // MUELU_ZOLTAN2INTERFACE_DECL_HPP
Important warning messages (one line)
void Build(Level &currentLevel) const
Build an object with this factory.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
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->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
Interface to Zoltan library.This interface provides access to partitioning methods in Zoltan...
void Build(Level &currentLevel) const
Build an object with this factory.
T * get() const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Definition: MueLu_Level.hpp:99
Interface to Zoltan2 library.This interface provides access to partitioning methods in Zoltan2...
T Get(Level &level, const std::string &varName) const
void Input(Level &level, const std::string &varName) const
Exception throws to report errors in the internal logical of the program.
Kokkos::Compat::KokkosSerialWrapperNode EpetraNode
void Set(Level &level, const std::string &varName, const T &data) const
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
Base class for factories that use one level (currentLevel).
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.