MueLu Version of the Day
Loading...
Searching...
No Matches
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_fwd.hpp>
54#include <Xpetra_VectorFactory_fwd.hpp>
55
58
59#include "MueLu_Level_fwd.hpp"
61
62#if defined(HAVE_MUELU_ZOLTAN)
63#include "MueLu_ZoltanInterface.hpp"
64#endif
65
66namespace MueLu {
67
68
110
111 //FIXME: this class should not be templated
112 template <class Scalar,
115 class Node = DefaultNode>
117#undef MUELU_ZOLTAN2INTERFACE_SHORT
119
120 public:
121
123
124
127
129 virtual ~Zoltan2Interface() { }
131
132 RCP<const ParameterList> GetValidParameterList() const;
133
135
136 void DeclareInput(Level& currentLevel) const;
138
140
141 void Build(Level& currentLevel) const;
142
144
145 private:
146 RCP<ParameterList> defaultZoltan2Params;
147
148 }; //class Zoltan2Interface
149
150#ifdef HAVE_MUELU_EPETRA
151
152#if ((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
153 (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
154
155#if defined(HAVE_MUELU_ZOLTAN)
156 // Stub partial specialization of Zoltan2Interface for EpetraNode
157 // Use ZoltanInterface instead of Zoltan2Interface
158 template<>
159 class Zoltan2Interface<double,int,int,Xpetra::EpetraNode> : public SingleLevelFactoryBase {
160 typedef double Scalar;
161 typedef int LocalOrdinal;
162 typedef int GlobalOrdinal;
163 typedef Xpetra::EpetraNode Node;
164#undef MUELU_ZOLTAN2INTERFACE_SHORT
166 public:
167 typedef typename Teuchos::ScalarTraits<Scalar>::magnitudeType real_type;
168 typedef Xpetra::MultiVector<real_type,LO,GO,NO> RealValuedMultiVector;
169
171 level_ = rcp(new Level());
173
174 level_->SetLevelID(1);
175 }
177 zoltanInterface_ = Teuchos::null;
178 level_ = Teuchos::null;
179 }
180 RCP<const ParameterList> GetValidParameterList() const {
181 RCP<ParameterList> validParamList = rcp(new ParameterList());
182
183 validParamList->set< RCP<const FactoryBase> > ("A", Teuchos::null, "Factory of the matrix A");
184 validParamList->set< RCP<const FactoryBase> > ("Coordinates", Teuchos::null, "Factory of the coordinates");
185 validParamList->set< RCP<const FactoryBase> > ("number of partitions", Teuchos::null, "Instance of RepartitionHeuristicFactory.");
186 validParamList->set< RCP<const ParameterList> > ("ParameterList", Teuchos::null, "Zoltan2 parameters");
187
188 return validParamList;
189 };
190 void DeclareInput(Level& currentLevel) const {
191 Input(currentLevel, "A");
192 Input(currentLevel, "number of partitions");
193 const ParameterList& pL = GetParameterList();
194 // We do this dance, because we don't want "ParameterList" to be marked as used.
195 // Is there a better way?
196 Teuchos::ParameterEntry entry = pL.getEntry("ParameterList");
197 RCP<const Teuchos::ParameterList> providedList = Teuchos::any_cast<RCP<const Teuchos::ParameterList> >(entry.getAny(false));
198 if (providedList != Teuchos::null && providedList->isType<std::string>("algorithm")) {
199 const std::string algo = providedList->get<std::string>("algorithm");
200 if (algo == "multijagged" || algo == "rcb")
201 Input(currentLevel, "Coordinates");
202 } else
203 Input(currentLevel, "Coordinates");
204 };
205 void Build(Level& currentLevel) const {
206 this->GetOStream(Warnings0) << "Tpetra does not support <double,int,int,EpetraNode> instantiation, "
207 "switching Zoltan2Interface to ZoltanInterface" << std::endl;
208
209 // Put the data into a fake level
210 level_->Set("A", Get<RCP<Matrix> > (currentLevel, "A"));
211 level_->Set("Coordinates", Get<RCP<RealValuedMultiVector> >(currentLevel, "Coordinates"));
212 level_->Set("number of partitions", currentLevel.Get<GO>("number of partitions"));
213
214 level_->Request("Partition", zoltanInterface_.get());
215 zoltanInterface_->Build(*level_);
216
217 RCP<Xpetra::Vector<GO,LO,GO,NO> > decomposition;
218 level_->Get("Partition", decomposition, zoltanInterface_.get());
219 Set(currentLevel, "Partition", decomposition);
220 };
221
222 private:
223 RCP<Level> level_; // fake Level
224 RCP<ZoltanInterface> zoltanInterface_;
225 };
226#else
227 // Stub partial specialization of Zoltan2Interface for EpetraNode
228 template<>
229 class Zoltan2Interface<double,int,int,Xpetra::EpetraNode> : public SingleLevelFactoryBase {
230 public:
231 Zoltan2Interface() { throw Exceptions::RuntimeError("Tpetra does not support <double,int,int,EpetraNode> instantiation"); }
232 virtual ~Zoltan2Interface() { }
233 RCP<const ParameterList> GetValidParameterList() const { return Teuchos::null; };
234 void DeclareInput(Level& level) const {};
235 void Build(Level &level) const {};
236 };
237#endif // HAVE_MUELU_ZOLTAN
238
239#endif
240
241#endif // HAVE_MUELU_EPETRA
242
243} //namespace MueLu
244
245#define MUELU_ZOLTAN2INTERFACE_SHORT
246#endif //if defined(HAVE_MUELU_ZOLTAN2) && defined(HAVE_MPI)
247
248#endif // MUELU_ZOLTAN2INTERFACE_DECL_HPP
Tpetra::KokkosCompat::KokkosSerialWrapperNode EpetraNode
MueLu::DefaultLocalOrdinal LocalOrdinal
MueLu::DefaultScalar Scalar
MueLu::DefaultGlobalOrdinal GlobalOrdinal
MueLu::DefaultNode Node
Exception throws to report errors in the internal logical of the program.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
void Set(Level &level, const std::string &varName, const T &data) const
Class that holds all level-specific information.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual const Teuchos::ParameterList & GetParameterList() const
Base class for factories that use one level (currentLevel).
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
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.
void Build(Level &currentLevel) const
Build an object with this factory.
Interface to Zoltan2 library.
void DeclareInput(Level &currentLevel) const
Specifies the data that this class needs, and the factories that generate that data.
RCP< const ParameterList > GetValidParameterList() const
Return a const parameter list of valid parameters that setParameterList() will accept.
void Build(Level &currentLevel) const
Build an object with this factory.
Interface to Zoltan library.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line).
Tpetra::KokkosClassic::DefaultNode::DefaultNodeType DefaultNode