/usr/include/trilinos/Ifpack2_LocalSparseTriangularSolver_def.hpp is in libtrilinos-ifpack2-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 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 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 | /*@HEADER
// ***********************************************************************
//
// Ifpack2: Templated Object-Oriented Algebraic Preconditioner Package
// Copyright (2009) 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.
//
// 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 Michael A. Heroux (maherou@sandia.gov)
//
// ***********************************************************************
//@HEADER
*/
#ifndef IFPACK2_LOCALSPARSETRIANGULARSOLVER_DEF_HPP
#define IFPACK2_LOCALSPARSETRIANGULARSOLVER_DEF_HPP
#include "Tpetra_CrsMatrix.hpp"
#include "Tpetra_DefaultPlatform.hpp"
namespace Ifpack2 {
template<class MatrixType>
LocalSparseTriangularSolver<MatrixType>::
LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A) :
A_ (A),
isInitialized_ (false),
isComputed_ (false),
numInitialize_ (0),
numCompute_ (0),
numApply_ (0),
initializeTime_ (0.0),
computeTime_ (0.0),
applyTime_ (0.0)
{
typedef typename Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
global_ordinal_type, node_type> crs_matrix_type;
if (! A.is_null ()) {
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (A);
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs.is_null (), std::invalid_argument,
"Ifpack2::LocalSparseTriangularSolver constructor: "
"The input matrix A is not a Tpetra::CrsMatrix.");
A_crs_ = A_crs;
}
}
template<class MatrixType>
LocalSparseTriangularSolver<MatrixType>::
LocalSparseTriangularSolver (const Teuchos::RCP<const row_matrix_type>& A,
const Teuchos::RCP<Teuchos::FancyOStream>& out) :
A_ (A),
out_ (out),
isInitialized_ (false),
isComputed_ (false),
numInitialize_ (0),
numCompute_ (0),
numApply_ (0),
initializeTime_ (0.0),
computeTime_ (0.0),
applyTime_ (0.0)
{
if (! out_.is_null ()) {
*out_ << ">>> DEBUG Ifpack2::LocalSparseTriangularSolver constructor"
<< std::endl;
}
typedef typename Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
global_ordinal_type, node_type> crs_matrix_type;
if (! A.is_null ()) {
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (A);
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs.is_null (), std::invalid_argument,
"Ifpack2::LocalSparseTriangularSolver constructor: "
"The input matrix A is not a Tpetra::CrsMatrix.");
A_crs_ = A_crs;
}
}
template<class MatrixType>
LocalSparseTriangularSolver<MatrixType>::
~LocalSparseTriangularSolver ()
{}
template<class MatrixType>
void
LocalSparseTriangularSolver<MatrixType>::
setParameters (const Teuchos::ParameterList& /*params*/)
{}
template<class MatrixType>
void
LocalSparseTriangularSolver<MatrixType>::
initialize ()
{
const char prefix[] = "Ifpack2::LocalSparseTriangularSolver::initialize: ";
if (! out_.is_null ()) {
*out_ << ">>> DEBUG " << prefix << std::endl;
}
TEUCHOS_TEST_FOR_EXCEPTION
(A_.is_null (), std::runtime_error, prefix << "You must call "
"setMatrix() with a nonnull input matrix before you may call "
"initialize() or compute().");
if (A_crs_.is_null ()) {
typedef typename Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
global_ordinal_type, node_type> crs_matrix_type;
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (A_);
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs.is_null (), std::invalid_argument, prefix <<
"The input matrix A is not a Tpetra::CrsMatrix.");
A_crs_ = A_crs;
}
auto G = A_->getGraph ();
TEUCHOS_TEST_FOR_EXCEPTION
(G.is_null (), std::logic_error, prefix << "A_ and A_crs_ are nonnull, "
"but A_'s RowGraph G is null. "
"Please report this bug to the Ifpack2 developers.");
// At this point, the graph MUST be fillComplete. The "initialize"
// (symbolic) part of setup only depends on the graph structure, so
// the matrix itself need not be fill complete.
TEUCHOS_TEST_FOR_EXCEPTION
(! G->isFillComplete (), std::runtime_error, "If you call this method, "
"the matrix's graph must be fill complete. It is not.");
isInitialized_ = true;
++numInitialize_;
}
template<class MatrixType>
void
LocalSparseTriangularSolver<MatrixType>::
compute ()
{
const char prefix[] = "Ifpack2::LocalSparseTriangularSolver::compute: ";
if (! out_.is_null ()) {
*out_ << ">>> DEBUG " << prefix << std::endl;
}
TEUCHOS_TEST_FOR_EXCEPTION
(A_.is_null (), std::runtime_error, prefix << "You must call "
"setMatrix() with a nonnull input matrix before you may call "
"initialize() or compute().");
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs_.is_null (), std::logic_error, prefix << "A_ is nonnull, but "
"A_crs_ is null. Please report this bug to the Ifpack2 developers.");
// At this point, the matrix MUST be fillComplete.
TEUCHOS_TEST_FOR_EXCEPTION
(! A_crs_->isFillComplete (), std::runtime_error, "If you call this "
"method, the matrix must be fill complete. It is not.");
if (! isInitialized_) {
initialize ();
}
TEUCHOS_TEST_FOR_EXCEPTION
(! isInitialized_, std::logic_error, prefix << "initialize() should have "
"been called by this point, but isInitialized_ is false. "
"Please report this bug to the Ifpack2 developers.");
isComputed_ = true;
++numCompute_;
}
template<class MatrixType>
void LocalSparseTriangularSolver<MatrixType>::
apply (const Tpetra::MultiVector<scalar_type, local_ordinal_type,
global_ordinal_type, node_type>& X,
Tpetra::MultiVector<scalar_type, local_ordinal_type,
global_ordinal_type, node_type>& Y,
Teuchos::ETransp mode,
scalar_type alpha,
scalar_type beta) const
{
using Teuchos::RCP;
using Teuchos::rcp;
using Teuchos::rcpFromRef;
typedef scalar_type ST;
typedef Teuchos::ScalarTraits<ST> STS;
const char prefix[] = "Ifpack2::LocalSparseTriangularSolver::apply: ";
if (! out_.is_null ()) {
*out_ << ">>> DEBUG " << prefix;
if (A_crs_.is_null ()) {
*out_ << "A_crs_ is null!" << std::endl;
}
else {
const std::string uplo = A_crs_->isUpperTriangular () ? "U" :
(A_crs_->isLowerTriangular () ? "L" : "N");
const std::string trans = (mode == Teuchos::CONJ_TRANS) ? "C" :
(mode == Teuchos::TRANS ? "T" : "N");
const std::string diag =
(A_crs_->getNodeNumDiags () < A_crs_->getNodeNumRows ()) ? "U" : "N";
*out_ << "uplo=\"" << uplo
<< "\", trans=\"" << trans
<< "\", diag=\"" << diag << "\"" << std::endl;
}
}
TEUCHOS_TEST_FOR_EXCEPTION
(! isComputed (), std::runtime_error, prefix << "If compute() has not yet "
"been called, or if you have changed the matrix via setMatrix(), you must "
"call compute() before you may call this method.");
// If isComputed() is true, it's impossible for the matrix to be
// null, or for it not to be a Tpetra::CrsMatrix.
TEUCHOS_TEST_FOR_EXCEPTION
(A_.is_null (), std::logic_error, prefix << "A_ is null. "
"Please report this bug to the Ifpack2 developers.");
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs_.is_null (), std::logic_error, prefix << "A_crs_ is null. "
"Please report this bug to the Ifpack2 developers.");
// However, it _is_ possible that the user called resumeFill() on
// the matrix, after calling compute(). This is NOT allowed.
TEUCHOS_TEST_FOR_EXCEPTION
(! A_crs_->isFillComplete (), std::runtime_error, "If you call this "
"method, the matrix must be fill complete. It is not. This means that "
" you must have called resumeFill() on the matrix before calling apply(). "
"This is NOT allowed. Note that this class may use the matrix's data in "
"place without copying it. Thus, you cannot change the matrix and expect "
"the solver to stay the same. If you have changed the matrix, first call "
"fillComplete() on it, then call compute() on this object, before you call"
" apply(). You do NOT need to call setMatrix, as long as the matrix "
"itself (that is, its address in memory) is the same.");
auto G = A_->getGraph ();
TEUCHOS_TEST_FOR_EXCEPTION
(G.is_null (), std::logic_error, prefix << "A_ and A_crs_ are nonnull, "
"but A_'s RowGraph G is null. "
"Please report this bug to the Ifpack2 developers.");
auto importer = G->getImporter ();
auto exporter = G->getExporter ();
if (! importer.is_null ()) {
if (X_colMap_.is_null () || X_colMap_->getNumVectors () != X.getNumVectors ()) {
X_colMap_ = rcp (new MV (importer->getTargetMap (), X.getNumVectors ()));
}
else {
X_colMap_->putScalar (STS::zero ());
}
// See discussion of Github Issue #672 for why the Import needs to
// use the ZERO CombineMode. The case where the Export is
// nontrivial is likely never exercised.
X_colMap_->doImport (X, *importer, Tpetra::ZERO);
}
RCP<const MV> X_cur = importer.is_null () ? rcpFromRef (X) :
Teuchos::rcp_const_cast<const MV> (X_colMap_);
if (! exporter.is_null ()) {
if (Y_rowMap_.is_null () || Y_rowMap_->getNumVectors () != Y.getNumVectors ()) {
Y_rowMap_ = rcp (new MV (exporter->getSourceMap (), Y.getNumVectors ()));
}
else {
Y_rowMap_->putScalar (STS::zero ());
}
Y_rowMap_->doExport (Y, *importer, Tpetra::ADD);
}
RCP<MV> Y_cur = exporter.is_null () ? rcpFromRef (Y) : Y_rowMap_;
localApply (*X_cur, *Y_cur, mode, alpha, beta);
if (! exporter.is_null ()) {
Y.putScalar (STS::zero ());
Y.doExport (*Y_cur, *exporter, Tpetra::ADD);
}
++numApply_;
}
template<class MatrixType>
void
LocalSparseTriangularSolver<MatrixType>::
localApply (const MV& X,
MV& Y,
const Teuchos::ETransp mode,
const scalar_type& alpha,
const scalar_type& beta) const
{
using Teuchos::RCP;
typedef scalar_type ST;
typedef Teuchos::ScalarTraits<ST> STS;
if (beta == STS::zero ()) {
if (alpha == STS::zero ()) {
Y.putScalar (STS::zero ()); // Y := 0 * Y (ignore contents of Y)
}
else { // alpha != 0
A_crs_->template localSolve<ST, ST> (X, Y, mode);
if (alpha != STS::one ()) {
Y.scale (alpha);
}
}
}
else { // beta != 0
if (alpha == STS::zero ()) {
Y.scale (beta); // Y := beta * Y
}
else { // alpha != 0
MV Y_tmp (Y, Teuchos::Copy);
A_crs_->template localSolve<ST, ST> (X, Y_tmp, mode); // Y_tmp := M * X
Y.update (alpha, Y_tmp, beta); // Y := beta * Y + alpha * Y_tmp
}
}
}
template <class MatrixType>
int
LocalSparseTriangularSolver<MatrixType>::
getNumInitialize () const {
return numInitialize_;
}
template <class MatrixType>
int
LocalSparseTriangularSolver<MatrixType>::
getNumCompute () const {
return numCompute_;
}
template <class MatrixType>
int
LocalSparseTriangularSolver<MatrixType>::
getNumApply () const {
return numApply_;
}
template <class MatrixType>
double
LocalSparseTriangularSolver<MatrixType>::
getInitializeTime () const {
return initializeTime_;
}
template<class MatrixType>
double
LocalSparseTriangularSolver<MatrixType>::
getComputeTime () const {
return computeTime_;
}
template<class MatrixType>
double
LocalSparseTriangularSolver<MatrixType>::
getApplyTime() const {
return applyTime_;
}
template <class MatrixType>
std::string
LocalSparseTriangularSolver<MatrixType>::
description () const
{
std::ostringstream os;
// Output is a valid YAML dictionary in flow style. If you don't
// like everything on a single line, you should call describe()
// instead.
os << "\"Ifpack2::LocalSparseTriangularSolver\": {";
if (this->getObjectLabel () != "") {
os << "Label: \"" << this->getObjectLabel () << "\", ";
}
os << "Initialized: " << (isInitialized () ? "true" : "false") << ", "
<< "Computed: " << (isComputed () ? "true" : "false") << ", ";
if (A_.is_null ()) {
os << "Matrix: null";
}
else {
os << "Matrix: not null"
<< ", Global matrix dimensions: ["
<< A_->getGlobalNumRows () << ", "
<< A_->getGlobalNumCols () << "]";
}
os << "}";
return os.str ();
}
template <class MatrixType>
void LocalSparseTriangularSolver<MatrixType>::
describe (Teuchos::FancyOStream& out,
const Teuchos::EVerbosityLevel verbLevel) const
{
using std::endl;
// Default verbosity level is VERB_LOW, which prints only on Process
// 0 of the matrix's communicator.
const Teuchos::EVerbosityLevel vl
= (verbLevel == Teuchos::VERB_DEFAULT) ? Teuchos::VERB_LOW : verbLevel;
if (vl != Teuchos::VERB_NONE) {
// Print only on Process 0 in the matrix's communicator. If the
// matrix is null, though, we have to get the communicator from
// somewhere, so we ask Tpetra for its default communicator. If
// MPI is enabled, this wraps MPI_COMM_WORLD or a clone thereof.
auto comm = A_.is_null () ?
Tpetra::DefaultPlatform::getDefaultPlatform ().getComm () :
A_->getComm ();
// Users aren't supposed to do anything with the matrix on
// processes where its communicator is null.
if (! comm.is_null () && comm->getRank () == 0) {
// By convention, describe() should always begin with a tab.
Teuchos::OSTab tab0 (out);
// Output is in YAML format. We have to escape the class name,
// because it has a colon.
out << "\"Ifpack2::LocalSparseTriangularSolver\":" << endl;
Teuchos::OSTab tab1 (out);
out << "Scalar: " << Teuchos::TypeNameTraits<scalar_type>::name () << endl
<< "LocalOrdinal: " << Teuchos::TypeNameTraits<local_ordinal_type>::name () << endl
<< "GlobalOrdinal: " << Teuchos::TypeNameTraits<global_ordinal_type>::name () << endl
<< "Node: " << Teuchos::TypeNameTraits<node_type>::name () << endl;
}
}
}
template <class MatrixType>
Teuchos::RCP<const typename LocalSparseTriangularSolver<MatrixType>::map_type>
LocalSparseTriangularSolver<MatrixType>::
getDomainMap () const
{
TEUCHOS_TEST_FOR_EXCEPTION
(A_.is_null (), std::runtime_error,
"Ifpack2::LocalSparseTriangularSolver::getDomainMap: "
"The matrix is null. Please call setMatrix() with a nonnull input "
"before calling this method.");
return A_->getDomainMap ();
}
template <class MatrixType>
Teuchos::RCP<const typename LocalSparseTriangularSolver<MatrixType>::map_type>
LocalSparseTriangularSolver<MatrixType>::
getRangeMap () const
{
TEUCHOS_TEST_FOR_EXCEPTION
(A_.is_null (), std::runtime_error,
"Ifpack2::LocalSparseTriangularSolver::getRangeMap: "
"The matrix is null. Please call setMatrix() with a nonnull input "
"before calling this method.");
return A_->getRangeMap ();
}
template<class MatrixType>
void LocalSparseTriangularSolver<MatrixType>::
setMatrix (const Teuchos::RCP<const row_matrix_type>& A)
{
const char prefix[] = "Ifpack2::LocalSparseTriangularSolver::setMatrix: ";
// If the pointer didn't change, do nothing. This is reasonable
// because users are supposed to call this method with the same
// object over all participating processes, and pointer identity
// implies object identity.
if (A.getRawPtr () != A_.getRawPtr ()) {
// Check in serial or one-process mode if the matrix is square.
TEUCHOS_TEST_FOR_EXCEPTION
(! A.is_null () && A->getComm ()->getSize () == 1 &&
A->getNodeNumRows () != A->getNodeNumCols (),
std::runtime_error, prefix << "If A's communicator only contains one "
"process, then A must be square. Instead, you provided a matrix A with "
<< A->getNodeNumRows () << " rows and " << A->getNodeNumCols ()
<< " columns.");
// It's legal for A to be null; in that case, you may not call
// initialize() until calling setMatrix() with a nonnull input.
// Regardless, setting the matrix invalidates the preconditioner.
isInitialized_ = false;
isComputed_ = false;
typedef typename Tpetra::CrsMatrix<scalar_type, local_ordinal_type,
global_ordinal_type, node_type> crs_matrix_type;
if (A.is_null ()) {
A_crs_ = Teuchos::null;
A_ = Teuchos::null;
}
else { // A is not null
Teuchos::RCP<const crs_matrix_type> A_crs =
Teuchos::rcp_dynamic_cast<const crs_matrix_type> (A);
TEUCHOS_TEST_FOR_EXCEPTION
(A_crs.is_null (), std::invalid_argument, prefix <<
"The input matrix A is not a Tpetra::CrsMatrix.");
A_crs_ = A_crs;
A_ = A;
}
} // pointers are not the same
}
} // namespace Ifpack2
#define IFPACK2_LOCALSPARSETRIANGULARSOLVER_INSTANT(S,LO,GO,N) \
template class Ifpack2::LocalSparseTriangularSolver< Tpetra::RowMatrix<S, LO, GO, N> >;
#endif // IFPACK2_LOCALSPARSETRIANGULARSOLVER_DEF_HPP
|