/usr/include/trilinos/Tpetra_CrsMatrixSolveOp_def.hpp is in libtrilinos-dev 10.4.0.dfsg-1ubuntu2.
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 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 | //@HEADER
// ************************************************************************
//
// Tpetra: Templated Linear Algebra Services Package
// Copyright (2008) Sandia Corporation
//
// Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
// license for use of this work by or on behalf of the U.S. Government.
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this library; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
// USA
// Questions? Contact Michael A. Heroux (maherou@sandia.gov)
//
// ************************************************************************
//@HEADER
#ifndef TPETRA_CRSMATRIXSOLVEOP_DEF_HPP
#define TPETRA_CRSMATRIXSOLVEOP_DEF_HPP
#include "Tpetra_CrsMatrix.hpp"
#ifdef DOXYGEN_USE_ONLY
#include "Tpetra_CrsMatrixSolveOp_decl.hpp"
#endif
/*! \file Tpetra_CrsMatrixSolveOp_def.hpp
The implementations for the members of Tpetra::CrsMatrixSolveOp and related non-member constructors.
*/
namespace Tpetra {
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::CrsMatrixSolveOp(const Teuchos::RCP<const CrsMatrix<MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> > &A)
: matrix_(A) {
}
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::~CrsMatrixSolveOp() {
}
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
void
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::apply(
const MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> & X,
MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> & Y,
Teuchos::ETransp mode, OpScalar alpha, OpScalar beta) const
{
TEST_FOR_EXCEPTION(!matrix_->isFillComplete(), std::runtime_error,
Teuchos::typeName(*this) << "::apply(): underlying matrix is not fill-complete.");
TEST_FOR_EXCEPTION(X.getNumVectors() != Y.getNumVectors(), std::runtime_error,
Teuchos::typeName(*this) << "::apply(X,Y): X and Y must have the same number of vectors.");
TEST_FOR_EXCEPTION(matrix_->isLowerTriangular() == false && matrix_->isUpperTriangular() == false, std::runtime_error,
Teuchos::typeName(*this) << "::apply() requires either upper or lower triangular structure in underlying matrix.");
TEST_FOR_EXCEPTION( alpha != Teuchos::ScalarTraits<OpScalar>::one() || beta != Teuchos::ScalarTraits<OpScalar>::zero(), std::runtime_error,
Teuchos::typeName(*this) << "::apply(): non-trivial alpha,beta not supported at this time.");
if (mode == Teuchos::NO_TRANS) {
applyNonTranspose(X,Y);
}
else {
applyTranspose(X,Y);
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
void
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::applyNonTranspose(
const MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> & X_in,
MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> & Y_in) const
{
// Solve U X = Y or L X = Y
// X belongs to domain map, while Y belongs to range map
typedef Teuchos::ScalarTraits<OpScalar> ST;
using Teuchos::null;
const size_t numVectors = X_in.getNumVectors();
Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > importer = matrix_->getGraph()->getImporter();
Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > exporter = matrix_->getGraph()->getExporter();
Teuchos::RCP<const MV> X;
// it is okay if X and Y reference the same data, because we can perform a triangular solve in-situ.
// however, we require that column access to each is strided.
// set up import/export temporary multivectors
if (importer != null) {
if (importMV_ != null && importMV_->getNumVectors() != numVectors) importMV_ = null;
if (importMV_ == null) {
importMV_ = Teuchos::rcp( new MV(matrix_->getColMap(),numVectors) );
}
}
if (exporter != null) {
if (exportMV_ != null && exportMV_->getNumVectors() != numVectors) exportMV_ = null;
if (exportMV_ == null) {
exportMV_ = Teuchos::rcp( new MV(matrix_->getRowMap(),numVectors) );
}
}
// solve(NO_TRANS): RangeMap -> DomainMap
// lclMatSolve_: RowMap -> ColMap
// importer: DomainMap -> ColMap
// exporter: RowMap -> RangeMap
//
// solve = reverse(exporter) o lclMatSolve_ o reverse(importer)
// RangeMap -> RowMap -> ColMap -> DomainMap
// If we have a non-trivial exporter, we must import elements that are permuted or are on other processors
if (exporter != null) {
exportMV_->doImport(X_in, *exporter, INSERT);
X = exportMV_;
}
else if (X_in.isConstantStride() == false) {
// cannot handle non-constant stride right now
// generate a copy of X_in
X = Teuchos::rcp(new MV(X_in));
}
else {
// just temporary, so this non-owning RCP is okay
X = Teuchos::rcp( &X_in, false );
}
// If we have a non-trivial importer, we must export elements that are permuted or belong to other processors
// We will compute solution into the to-be-exported MV
if (importer != null) {
matrix_->template solve<OpScalar,OpScalar>(*X,*importMV_,Teuchos::NO_TRANS);
// Make sure target is zero: necessary because we are adding.
Y_in.putScalar(ST::zero());
Y_in.doExport(*importMV_, *importer, ADD);
}
// otherwise, solve into Y
else {
// can't solve into non-strided multivector
if (Y_in.isConstantStride() == false) {
// generate a strided copy of Y
MV Y(Y_in);
matrix_->template solve<OpScalar,OpScalar>(*X,Y,Teuchos::NO_TRANS);
Y_in = Y;
}
else {
matrix_->template solve<OpScalar,OpScalar>(*X,Y_in,Teuchos::NO_TRANS);
}
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
void
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::applyTranspose(
const MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> & X_in,
MultiVector<OpScalar,LocalOrdinal,GlobalOrdinal,Node> &Y_in) const
{
typedef Teuchos::ScalarTraits<OpScalar> ST;
using Teuchos::null;
const size_t numVectors = X_in.getNumVectors();
Teuchos::RCP<const Import<LocalOrdinal,GlobalOrdinal,Node> > importer = matrix_->getGraph()->getImporter();
Teuchos::RCP<const Export<LocalOrdinal,GlobalOrdinal,Node> > exporter = matrix_->getGraph()->getExporter();
Teuchos::RCP<const MV> X;
// it is okay if X and Y reference the same data, because we can perform a triangular solve in-situ.
// however, we require that column access to each is strided.
// set up import/export temporary multivectors
if (importer != null) {
if (importMV_ != null && importMV_->getNumVectors() != numVectors) importMV_ = null;
if (importMV_ == null) {
importMV_ = Teuchos::rcp( new MV(matrix_->getColMap(),numVectors) );
}
}
if (exporter != null) {
if (exportMV_ != null && exportMV_->getNumVectors() != numVectors) exportMV_ = null;
if (exportMV_ == null) {
exportMV_ = Teuchos::rcp( new MV(matrix_->getRowMap(),numVectors) );
}
}
// solve(TRANS): DomainMap -> RangeMap
// lclMatSolve_(TRANS): ColMap -> RowMap
// importer: DomainMap -> ColMap
// exporter: RowMap -> RangeMap
//
// solve = importer o lclMatSolve_ o exporter
// Domainmap -> ColMap -> RowMap -> RangeMap
// If we have a non-trivial importer, we must import elements that are permuted or are on other processors
if (importer != null) {
importMV_->doImport(X_in,*importer,INSERT);
X = importMV_;
}
else if (X_in.isConstantStride() == false) {
// cannot handle non-constant stride right now
// generate a copy of X_in
X = Teuchos::rcp(new MV(X_in));
}
else {
// just temporary, so this non-owning RCP is okay
X = Teuchos::rcp( &X_in, false );
}
// If we have a non-trivial exporter, we must export elements that are permuted or belong to other processors
// We will compute solution into the to-be-exported MV; get a view
if (exporter != null) {
matrix_->template solve<OpScalar,OpScalar>(*X,*exportMV_,Teuchos::CONJ_TRANS);
// Make sure target is zero: necessary because we are adding
Y_in.putScalar(ST::zero());
Y_in.doExport(*importMV_, *importer, ADD);
}
// otherwise, solve into Y
else {
if (Y_in.isConstantStride() == false) {
// generate a strided copy of Y
MV Y(Y_in);
matrix_->template solve<OpScalar,OpScalar>(*X,Y,Teuchos::CONJ_TRANS);
Y_in = Y;
}
else {
matrix_->template solve<OpScalar,OpScalar>(*X,Y_in,Teuchos::CONJ_TRANS);
}
}
}
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
bool
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::hasTransposeApply() const {
return true;
}
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::getDomainMap() const {
return matrix_->getRangeMap();
}
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > &
CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>::getRangeMap() const {
return matrix_->getDomainMap();
}
} // end of namespace Tpetra
template <class OpScalar, class MatScalar, class LocalOrdinal, class GlobalOrdinal, class Node, class LocalMatOps>
Teuchos::RCP< Tpetra::CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> >
Tpetra::createCrsMatrixSolveOp(const Teuchos::RCP<const Tpetra::CrsMatrix<MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps> > &A) {
return Teuchos::rcp(new Tpetra::CrsMatrixSolveOp<OpScalar,MatScalar,LocalOrdinal,GlobalOrdinal,Node,LocalMatOps>(A) );
}
//
// Explicit instantiation macro
//
// Must be expanded from within the Tpetra namespace!
//
//! Explicit instantiation macro supporting the CrsMatrixSolveOp class. Instantiates the class, the non-member constructor, and the necessary CrsMatrix::solve() member.
#define TPETRA_CRSMATRIX_SOLVEOP_INSTANT(OPSCALAR,MATSCALAR,LO,GO,NODE) \
\
template class CrsMatrixSolveOp< OPSCALAR , MATSCALAR , LO , GO , NODE >; \
\
template Teuchos::RCP< Tpetra::CrsMatrixSolveOp<OPSCALAR,MATSCALAR,LO,GO,NODE> > \
createCrsMatrixSolveOp(const Teuchos::RCP<const Tpetra::CrsMatrix<MATSCALAR,LO,GO,NODE> > &A); \
\
template void CrsMatrix<MATSCALAR,LO,GO,NODE>::solve<OPSCALAR,OPSCALAR>( \
const MultiVector<OPSCALAR,LO,GO,NODE> &X, \
MultiVector<OPSCALAR,LO,GO,NODE> &Y, \
Teuchos::ETransp mode) const; \
#endif // TPETRA_CRSMATRIXSOLVEOP_DEF_HPP
|