/usr/include/trilinos/Tpetra_VbrMatrix_decl.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 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 | //@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_VBRMATRIX_DECL_HPP
#define TPETRA_VBRMATRIX_DECL_HPP
#include <Kokkos_DefaultNode.hpp>
#include <Kokkos_DefaultKernels.hpp>
#include <Kokkos_VbrMatrix.hpp>
#include <Teuchos_ScalarTraits.hpp>
#include <Teuchos_OrdinalTraits.hpp>
#include <Teuchos_SerializationTraits.hpp>
#include "Tpetra_ConfigDefs.hpp"
#include "Tpetra_Operator.hpp"
#include "Tpetra_BlockMap.hpp"
#include "Tpetra_CrsGraph.hpp"
/** \file Tpetra_VbrMatrix_decl.hpp
Declarations for the class Tpetra::VbrMatrix.
*/
namespace Tpetra {
//! \brief VbrMatrix: Variable block row matrix.
/**
The VbrMatrix class has two significant 'states', distinguished by whether or not
storage has been optimized (packed) or not.
When the matrix is in the non-optimized-storage state, internal data
storage is in an un-packed, non-contiguous data-structure that allows for
convenient insertion of data.
When the matrix is in the optimized-storage state, internal data is stored in
contiguous (packed) arrays. When in this state, existing entries may be updated
and replaced, but no new entries (indices and/or coefficients) may be inserted.
In other words, the sparsity pattern or structure of the matrix may not be
changed.
Use of the matrix as an Operator (performing matrix-vector multiplication) is
only allowed when it is in the optimized-storage state.
VbrMatrix has two constructors, one which leaves the matrix in the optimized-
storage stage, and another which leaves the matrix in the non-optimized-storage
stage.
When the VbrMatrix is constructed in the non-optimized-storage state, and then
filled using methods such as setGlobalBlockEntry etc., it can then be transformed
to the optimized-storage state by calling the method fillComplete().
Once in the optimized-storage state, the VbrMatrix can not be returned to the
non-optimized-storage state.
*/
template <class Scalar,
class LocalOrdinal = int,
class GlobalOrdinal = LocalOrdinal,
class Node = Kokkos::DefaultNode::DefaultNodeType,
class LocalMatOps = typename Kokkos::DefaultKernels<Scalar,LocalOrdinal,Node>::BlockSparseOps >
class VbrMatrix : public Tpetra::Operator<Scalar,LocalOrdinal,GlobalOrdinal,Node> {
public:
typedef Scalar scalar_type;
typedef LocalOrdinal local_ordinal_type;
typedef GlobalOrdinal global_ordinal_type;
typedef Node node_type;
typedef LocalMatOps mat_vec_type;
//! @name Constructor/Destructor Methods
//@{
//! Constructor specifying the row-map and the max number of (block) non-zeros for all rows.
/*! After this constructor completes, the VbrMatrix is in the non-packed,
non-optimized-storage, isFillComplete()==false state.
Block-entries (rectangular, dense submatrices) may be inserted using class
methods such as setGlobalBlockEntry(...), declared below.
*/
VbrMatrix(const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > &blkRowMap, size_t maxNumEntriesPerRow, ProfileType pftype = DynamicProfile);
//! Not Yet Implemented! Constructor specifying a pre-filled graph and block-maps for range and domain.
/*! Constructing a VbrMatrix with a pre-filled graph means that the matrix will
start out in the optimized-storage, isFillComplete()==true state.
The graph provided to this constructor must be already filled
(If blkGraph->isFillComplete() != true, an exception is thrown.)
Entries in the input CrsGraph will correspond to block-entries in the
VbrMatrix. In other words, the VbrMatrix will have a block-row corresponding
to each row in the graph, and a block-entry corresponding to each column-
index in the graph.
The block-maps provided for range and domain must be sized such that:
blkDomainMap->getGlobalNumBlocks() == blkGraph->getDomainMap()->getGlobalNumElements(),
blkRangeMap->getGlobalNumBlocks() == blkGraph->getRangeMap()->getGlobalNumElements(),
blkDomainMap->getNodeNumBlocks() == blkGraph->getDomainMap()->getNodeNumElements(),
blkRangeMap->getNodeNumBlocks() == blkGraph->getRangeMap()->getNodeNumElements().
If any of these conditions is not met, an exception is thrown.
*/
// VbrMatrix(const Teuchos::RCP<const CrsGraph<LocalOrdinal,GlobalOrdinal,Node> >& blkGraph, const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& blkDomainMap, const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& blkRangeMap);
//! Destructor
virtual ~VbrMatrix();
//@}
//! @name Advanced Matrix-vector multiplication method
//! Multiply this matrix by a MultiVector.
/*! \c X is required to be post-imported, i.e., described by the column map
of the matrix. \c Y is required to be pre-exported, i.e., described by
the row map of the matrix.
See also the Operator::apply method which is implemented below.
*/
template <class DomainScalar, class RangeScalar>
void multiply(const MultiVector<DomainScalar,LocalOrdinal,GlobalOrdinal,Node> & X, MultiVector<RangeScalar,LocalOrdinal,GlobalOrdinal,Node> &Y, Teuchos::ETransp trans, RangeScalar alpha, RangeScalar beta) const;
//@}
//! @name Operator Methods
//@{
//! Returns the Map associated with the domain of this operator, which must be compatible with X.getMap().
/*! Note that this is a point-entry map, not a block-map.
*/
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getDomainMap() const;
//! Returns the Map associated with the range of this operator, which must be compatible with Y.getMap().
/*! Note that this is a point-entry map, not a block-map.
*/
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getRangeMap() const;
//! \brief Computes the operator-multivector application.
/*! Loosely, performs \f$Y = \alpha \cdot A^{\textrm{trans}} \cdot X + \beta \cdot Y\f$. However, the details of operation
vary according to the values of \c alpha and \c beta. Specifically
- if <tt>beta == 0</tt>, apply() <b>must</b> overwrite \c Y, so that any values in \c Y (including NaNs) are ignored.
- if <tt>alpha == 0</tt>, apply() <b>may</b> short-circuit the operator, so that any values in \c X (including NaNs) are ignored.
*/
void apply(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &X,
MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> &Y,
Teuchos::ETransp trans = Teuchos::NO_TRANS,
Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
Scalar beta = Teuchos::ScalarTraits<Scalar>::zero()) const;
//! Indicates whether this operator supports applying the adjoint operator.
bool hasTransposeApply() const;
//@}
//! @name Attribute Query Methods
//@{
//! Returns the block-row map.
const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > & getBlockRowMap() const;
//! Returns the block-column map.
const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > & getBlockColMap() const;
//! Returns the point-row map.
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getPointRowMap() const;
//! Returns the point-column map.
const Teuchos::RCP<const Map<LocalOrdinal,GlobalOrdinal,Node> > & getPointColMap() const;
//! Return true if fillComplete has been called, false otherwise.
bool isFillComplete() const;
//@}
//! @name Insertion Methods
//@{
//! Set the specified scalar throughout the matrix.
/*!
This method may be called any time (before or after fillComplete()).
*/
void putScalar(Scalar s);
//!Copy the contents of the input block-entry into the matrix.
/*!
This method will create the specified block-entry if it doesn't already exist,
but only if fillComplete() has not yet been called.
If the specified block-entry already exists in the matrix, it will be
over-written (replaced) by the input block-entry.
This method may be called any time (before or after fillComplete()).
*/
void setGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, const Teuchos::SerialDenseMatrix<GlobalOrdinal,Scalar>& blockEntry);
//!Add the contents of the input block-entry into the matrix.
/*!
This method will create the specified block-entry if it doesn't already exist,
but only if fillComplete() has not yet been called.
If the specified block-entry already exists in the matrix, the contents of the
input block-entry will be added to the values that are already present.
This method may be called any time (before or after fillComplete()).
*/
void sumIntoGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, const Teuchos::SerialDenseMatrix<GlobalOrdinal,Scalar>& blockEntry);
//!Copy the contents of the input block-entry into the matrix.
/*!
This method will create the specified block-entry if it doesn't already exist,
but only if fillComplete() has not yet been called.
If the specified block-entry already exists in the matrix, it will be
over-written (replaced) by the input block-entry.
This method may be called any time (before or after fillComplete()).
*/
void setGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry);
//!Add the contents of the input block-entry into the matrix.
/*!
This method will create the specified block-entry if it doesn't already exist,
but only if fillComplete() has not yet been called.
If the specified block-entry already exists in the matrix, the contents of the
input block-entry will be added to the values that are already present.
This method may be called any time (before or after fillComplete()).
*/
void sumIntoGlobalBlockEntry(GlobalOrdinal globalBlockRow, GlobalOrdinal globalBlockCol, LocalOrdinal blkRowSize, LocalOrdinal blkColSize, LocalOrdinal LDA, const Teuchos::ArrayView<const Scalar>& blockEntry);
//@}
//! @name Transformational Methods
//@{
void fillComplete(const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& blockDomainMap, const Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> >& blockRangeMap);
void fillComplete();
//@}
//! @name Extraction Methods
//@{
//! Returns a const read-only view of a block-entry.
/*!
The arguments numPtRows and numPtCols are set to the dimensions of the block-
entry on output.
The stride (LDA in Blas terminology) is equal to numPtRows.
This method may be called any time (before or after fillComplete()), but will
throw an exception if the specified block-entry doesn't already exist.
*/
void getGlobalBlockEntryView(GlobalOrdinal globalBlockRow,
GlobalOrdinal globalBlockCol,
LocalOrdinal& numPtRows,
LocalOrdinal& numPtCols,
Teuchos::ArrayRCP<const Scalar>& blockEntry) const;
//! Returns a non-const read-write view of a block-entry.
/*! Creates the block-entry if it doesn't already exist, and if:
- the arguments numPtRows and numPtCols are set on entry (and nonzero),
- and if fillComplete() has not yet been called.
Important Note: Be very careful managing the lifetime of this view.
If fillComplete() has been called, and if you are running on a GPU,
this view may be a copy of memory from the GPU, and your changes to the
view won't be copied back to the GPU until your ArrayRCP is destroyed
or set to Teuchos::null.
*/
void getGlobalBlockEntryViewNonConst(GlobalOrdinal globalBlockRow,
GlobalOrdinal globalBlockCol,
LocalOrdinal& numPtRows,
LocalOrdinal& numPtCols,
Teuchos::ArrayRCP<Scalar>& blockEntry);
//! Returns a const read-only view of a block-entry.
/*!
The arguments numPtRows and numPtCols are set to the dimensions of the block-
entry on output.
The stride (LDA in Blas terminology) is equal to numPtRows.
Throws an exception if fillComplete() has not yet been called, or if the
specified block-entry doesn't exist.
This method may only be called after fillComplete() has been called, and will
throw an exception if the specified block-entry doesn't already exist.
*/
void getLocalBlockEntryView(LocalOrdinal localBlockRow,
LocalOrdinal localBlockCol,
LocalOrdinal& numPtRows,
LocalOrdinal& numPtCols,
Teuchos::ArrayRCP<const Scalar>& blockEntry) const;
//! Returns a non-const read-write view of a block-entry.
/*!
The arguments numPtRows and numPtCols are set to the dimensions of the block-
entry on output.
The stride (LDA in Blas terminology) is equal to numPtRows.
Throws an exception if fillComplete() has not yet been called, or if the
specified block-entry doesn't exist.
Important Note: Be very careful managing the lifetime of this view.
If fillComplete() has been called, and if you are running on a GPU,
this view may be a copy of memory from the GPU, and your changes to the
view won't be copied back to the GPU until your ArrayRCP is destroyed
or set to Teuchos::null.
This method may only be called after fillComplete() has been called, and will
throw an exception if the specified block-entry doesn't already exist.
*/
void getLocalBlockEntryViewNonConst(LocalOrdinal localBlockRow,
LocalOrdinal localBlockCol,
LocalOrdinal& numPtRows,
LocalOrdinal& numPtCols,
Teuchos::ArrayRCP<Scalar>& blockEntry);
//@}
//! @name Overridden from Teuchos::Describable
//@{
std::string description() const;
/** \brief Print the object with some verbosity level to a FancyOStream object.
*/
void describe(Teuchos::FancyOStream &out, const Teuchos::EVerbosityLevel verbLevel=Teuchos::Describable::verbLevel_default) const;
//@}
private:
//private methods:
Teuchos::RCP<Node> getNode() const;
void updateImport(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& X) const;
void updateExport(const MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node>& Y) const;
void optimizeStorage();
void fillLocalMatrix();
void fillLocalMatVec();
//private data members:
Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > blkRowMap_;
Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > blkColMap_;
Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > blkDomainMap_;
Teuchos::RCP<const BlockMap<LocalOrdinal,GlobalOrdinal,Node> > blkRangeMap_;
Teuchos::RCP<CrsGraph<LocalOrdinal,GlobalOrdinal,Node> > blkGraph_;
Kokkos::VbrMatrix<Scalar,LocalOrdinal,Node> lclMatrix_;
//It takes 6 arrays to adequately represent a variable-block-row
//matrix in packed (contiguous storage) form. For a description of these
//arrays, see the text at the bottom of this file.
//(Note that 2 of those arrays, rptr and cptr, are represented by arrays in the
//blkRowMap_ and blkColMap_ objects.)
//
//These arrays are handled as if they may point to memory that resides on
//a separate device (e.g., a GPU). In other words, when the contents of these
//arrays are manipulated, we use views or buffers obtained from the Node object.
Teuchos::ArrayRCP<Scalar> pbuf_values1D_;
Teuchos::ArrayRCP<LocalOrdinal> pbuf_bptr_;
Teuchos::ArrayRCP<LocalOrdinal> pbuf_bindx_;
Teuchos::ArrayRCP<LocalOrdinal> pbuf_indx_;
LocalMatOps lclMatVec_;
Teuchos::RCP<Tpetra::Import<LocalOrdinal,GlobalOrdinal,Node> > importer_;
Teuchos::RCP<Tpetra::Export<LocalOrdinal,GlobalOrdinal,Node> > exporter_;
mutable Teuchos::RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > importedVec_;
mutable Teuchos::RCP<Tpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> > exportedVec_;
typedef typename std::map<GlobalOrdinal,Teuchos::ArrayRCP<Scalar> > MapGlobalArrayRCP;
typedef typename std::map<LocalOrdinal,Teuchos::ArrayRCP<Scalar> > MapLocalArrayRCP;
//We use 2 arrays (well, array-of-maps, array-of-array-of-arrays...) to
//represent the variable-block-row matrix in un-packed '2D' form.
//
//Note that these arrays are assumed to be resident in CPU (host) memory.
//It doesn't make sense to copy this kind of data back and forth to a separate
//compute device (e.g., a GPU), since we don't support doing matrix-vector
//products until after fillComplete is called, at which time contiguous
//arrays are allocated on the device and matrix data is copied into them.
Teuchos::RCP<Teuchos::Array<MapGlobalArrayRCP> > col_ind_2D_global_;
Teuchos::RCP<Teuchos::Array<Teuchos::Array<Teuchos::ArrayRCP<Scalar> > > > values2D_;
bool is_fill_completed_;
bool is_storage_optimized_;
};//class VbrMatrix
}//namespace Tpetra
//----------------------------------------------------------------------------
// Description of arrays representing the VBR format:
//
// (For more description, see this URL (valid as of 5/26/2010):
// http://docs.sun.com/source/817-0086-10/prog-sparse-support.html)
// ...and of course more can be found using google...
// The old Aztec manual was a great resource for this but I can't
// find a copy of that these days...
//
// rptr: length num_block_rows + 1
// rptr[i]: the pt-row corresponding to the i-th block-row
//
// cptr: length num_distinct_block_cols + 1
// cptr[j]: the pt-col corresponding to the j-th block-col
//
// bptr: length num_block_rows + 1
// bptr[i]: location in bindx of the first nonzero block-entry
// of the i-th block-row
//
// bindx: length num-nonzero-block-entries
// bindx[j]: block-col-index of j-th block-entry
//
// indx: length num-nonzero-block-entries + 1
// indx[j] location in vals of the beginning of the j-th
// block-entry
//
// vals: length num-nonzero-scalar-entries
//
//
// Some example look-ups:
//
// int nbr = num_block_rows;
// int total_num_block_nonzeros = bptr[nbr];
// int total_num_scalar_nonzeros = indx[num_block_nonzeros];
//
// //get arrays for i-th block-row:
// int* bindx_i = &bindx[bptr[i]];
// double* vals_i = &val[indx[bptr[i]]];
// int num_block_nonzeros_in_row_i = bptr[i+1]-bptr[i];
//
//----------------------------------------------------------------------------
#endif //TPETRA_VBRMATRIX_DECL_HPP
|