/usr/include/trilinos/MueLu_DirectSolver_def.hpp is in libtrilinos-muelu-dev 12.10.1-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 | // @HEADER
//
// ***********************************************************************
//
// MueLu: A package for multigrid based preconditioning
// Copyright 2012 Sandia Corporation
//
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
// the U.S. Government retains certain rights in this software.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// 1. Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
//
// 2. Redistributions in binary form must reproduce the above copyright
// notice, this list of conditions and the following disclaimer in the
// documentation and/or other materials provided with the distribution.
//
// 3. Neither the name of the Corporation nor the names of the
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Questions? Contact
// Jonathan Hu (jhu@sandia.gov)
// Andrey Prokopenko (aprokop@sandia.gov)
// Ray Tuminaro (rstumin@sandia.gov)
//
// ***********************************************************************
//
// @HEADER
#ifndef MUELU_DIRECTSOLVER_DEF_HPP
#define MUELU_DIRECTSOLVER_DEF_HPP
#include <Xpetra_Utils.hpp>
#include <Xpetra_Matrix.hpp>
#include "MueLu_DirectSolver_decl.hpp"
#include "MueLu_Exceptions.hpp"
#include "MueLu_Level.hpp"
#include "MueLu_Amesos2Smoother.hpp"
#include "MueLu_AmesosSmoother.hpp"
namespace MueLu {
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DirectSolver(const std::string& type, const Teuchos::ParameterList& paramListIn)
: type_(type) {
// The original idea behind all smoothers was to use prototype pattern. However, it does not fully work of the dependencies
// calculation. Particularly, we need to propagate DeclareInput to proper prototypes. Therefore, both TrilinosSmoother and
// DirectSolver do not follow the pattern exactly.
// The difference is that in order to propagate the calculation of dependencies, we need to call a DeclareInput on a
// constructed object (or objects, as we have two different code branches for Epetra and Tpetra). The only place where we
// could construct these objects is the constructor. Thus, we need to store RCPs, and both TrilinosSmoother and DirectSolver
// obtain a state: they contain RCP to smoother prototypes.
sEpetra_ = Teuchos::null;
sTpetra_ = Teuchos::null;
ParameterList paramList = paramListIn;
// We want DirectSolver to be able to work with both Epetra and Tpetra objects, therefore we try to construct both
// Amesos and Amesos2 solver prototypes. The construction really depends on configuration options.
triedEpetra_ = triedTpetra_ = false;
#if defined(HAVE_MUELU_TPETRA) && defined(HAVE_MUELU_AMESOS2)
try {
sTpetra_ = rcp(new Amesos2Smoother(type_, paramList));
TEUCHOS_TEST_FOR_EXCEPTION(sTpetra_.is_null(), Exceptions::RuntimeError, "Unable to construct Amesos2 direct solver");
} catch (Exceptions::RuntimeError& e) {
errorTpetra_ = e.what();
} catch (Exceptions::BadCast& e) {
errorTpetra_ = e.what();
}
triedTpetra_ = true;
#endif
#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_AMESOS)
try {
// GetAmesosSmoother masks the template argument matching, and simply throws if template arguments are incompatible with Epetra
sEpetra_ = GetAmesosSmoother<SC,LO,GO,NO>(type_, paramList);
TEUCHOS_TEST_FOR_EXCEPTION(sEpetra_.is_null(), Exceptions::RuntimeError, "Unable to construct Amesos direct solver");
} catch (Exceptions::RuntimeError& e) {
// AmesosSmoother throws if Scalar != double, LocalOrdinal != int, GlobalOrdinal != int
errorEpetra_ = e.what();
}
triedEpetra_ = true;
#endif
// Check if we were able to construct at least one solver. In many cases that's all we need, for instance if a user
// simply wants to use Tpetra only stack, never enables Amesos, and always runs Tpetra objects.
TEUCHOS_TEST_FOR_EXCEPTION(!triedEpetra_ && !triedTpetra_, Exceptions::RuntimeError, "Unable to construct any direct solver."
"Plase enable (TPETRA and AMESOS2) or (EPETRA and AMESOS)");
TEUCHOS_TEST_FOR_EXCEPTION(sEpetra_.is_null() && sTpetra_.is_null(), Exceptions::RuntimeError,
"Could not enable any direct solver:\n"
<< (triedEpetra_ ? "Epetra mode was disabled due to an error:\n" : "")
<< (triedEpetra_ ? errorEpetra_ : "")
<< (triedTpetra_ ? "Tpetra mode was disabled due to an error:\n" : "")
<< (triedTpetra_ ? errorTpetra_ : ""));
this->SetParameterList(paramList);
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::SetFactory(const std::string& varName, const RCP<const FactoryBase>& factory) {
// We need to propagate SetFactory to proper place
if (!sEpetra_.is_null()) sEpetra_->SetFactory(varName, factory);
if (!sTpetra_.is_null()) sTpetra_->SetFactory(varName, factory);
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::DeclareInput(Level& currentLevel) const {
// Decide whether we are running in Epetra or Tpetra mode
//
// Theoretically, we could make this decision in the constructor, and create only
// one of the smoothers. But we want to be able to reuse, so one can imagine a scenario
// where one first runs hierarchy with tpetra matrix, and then with epetra.
bool useTpetra = (currentLevel.lib() == Xpetra::UseTpetra);
s_ = (useTpetra ? sTpetra_ : sEpetra_);
if (s_.is_null()) {
if (useTpetra) {
#if not defined(HAVE_MUELU_AMESOS2)
TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError,
"Error: running in Tpetra mode, but MueLu with Amesos2 was disabled during the configure stage.\n"
"Please make sure that:\n"
" - Amesos2 is enabled (Trilinos_ENABLE_Amesos2=ON),\n"
" - Amesos2 is available for MueLu to use (MueLu_ENABLE_Amesos2=ON)\n");
#else
if (triedTpetra_)
this->GetOStream(Errors) << "Tpetra mode was disabled due to an error:\n" << errorTpetra_ << std::endl;
#endif
}
if (!useTpetra) {
#if not defined(HAVE_MUELU_AMESOS)
TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError,
"Error: running in Epetra mode, but MueLu with Amesos was disabled during the configure stage.\n"
"Please make sure that:\n"
" - Amesos is enabled (you can do that with Trilinos_ENABLE_Amesos=ON),\n"
" - Amesos is available for MueLu to use (MueLu_ENABLE_Amesos=ON)\n");
#else
if (triedEpetra_)
this->GetOStream(Errors) << "Epetra mode was disabled due to an error:\n" << errorEpetra_ << std::endl;
#endif
}
TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError,
"Direct solver for " << (useTpetra ? "Tpetra" : "Epetra") << " was not constructed");
}
s_->DeclareInput(currentLevel);
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Setup(Level& currentLevel) {
if (SmootherPrototype::IsSetup() == true)
this->GetOStream(Warnings0) << "MueLu::DirectSolver::Setup(): Setup() has already been called" << std::endl;
int oldRank = s_->SetProcRankVerbose(this->GetProcRankVerbose());
s_->Setup(currentLevel);
s_->SetProcRankVerbose(oldRank);
SmootherPrototype::IsSetup(true);
this->SetParameterList(s_->GetParameterList());
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::AmesosSmoother::Apply(): Setup() has not been called");
s_->Apply(X, B, InitialGuessIsZero);
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> > DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Copy() const {
RCP<DirectSolver> newSmoo = rcp(new DirectSolver(*this));
// We need to be quite careful with Copy
// We still want DirectSolver to follow Prototype Pattern, so we need to hide the fact that we do have some state
if (!sEpetra_.is_null())
newSmoo->sEpetra_ = sEpetra_->Copy();
if (!sTpetra_.is_null())
newSmoo->sTpetra_ = sTpetra_->Copy();
// Copy the default mode
newSmoo->s_ = (s_.get() == sTpetra_.get() ? newSmoo->sTpetra_ : newSmoo->sEpetra_);
newSmoo->SetParameterList(this->GetParameterList());
return newSmoo;
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
std::string DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::description() const {
std::ostringstream out;
if (s_ != Teuchos::null) {
out << s_->description();
} else {
out << SmootherPrototype::description();
out << "{type = " << type_ << "}";
}
return out.str();
}
template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
void DirectSolver<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream& out, const VerbLevel verbLevel) const {
MUELU_DESCRIBE;
if (verbLevel & Parameters0)
out0 << "Prec. type: " << type_ << std::endl;
if (verbLevel & Parameters1) {
out0 << "Parameter list: " << std::endl;
Teuchos::OSTab tab3(out);
out << this->GetParameterList();
}
if (verbLevel & Debug)
out0 << "IsSetup: " << Teuchos::toString(SmootherPrototype::IsSetup()) << std::endl;
}
} // namespace MueLu
#endif // MUELU_DIRECTSOLVER_DEF_HPP
|