10#ifndef BELOS_TEUCHOS_DENSE_MAT_TRAITS_HPP
11#define BELOS_TEUCHOS_DENSE_MAT_TRAITS_HPP
18#include "Teuchos_RCP.hpp"
19#include "Teuchos_ScalarTraits.hpp"
20#include "Teuchos_SerialDenseMatrix.hpp"
21#include "Teuchos_SerialDenseSolver.hpp"
22#include "Teuchos_SerialSpdDenseSolver.hpp"
30 template<
class ScalarType>
82 if ( (dSolver_==Teuchos::null) && (spdSolver_==Teuchos::null) )
85 spdSolver_ = Teuchos::rcp(
new Teuchos::SerialSpdDenseSolver<int,ScalarType>() );
87 dSolver_ = Teuchos::rcp(
new Teuchos::SerialDenseSolver<int,ScalarType>() );
97 spdMatrix_ = Teuchos::rcp(
new Teuchos::SerialSymDenseMatrix<int,ScalarType>(Teuchos::View,
true,
A_->values(),
98 A_->numRows(),
A_->numCols()) );
100 spdSolver_->setMatrix( spdMatrix_ );
102 info = spdSolver_->factor();
106 dSolver_->setMatrix(
A_ );
107 dSolver_->solveWithTransposeFlag(
TRANS_ );
109 info = dSolver_->factor();
132 spdSolver_->setVectors(
X_,
B_ );
133 info = spdSolver_->solve();
137 dSolver_->setVectors(
X_,
B_ );
138 info = dSolver_->solve();
158 Teuchos::RCP<Teuchos::SerialDenseSolver<int,ScalarType>> dSolver_;
161 Teuchos::RCP<Teuchos::SerialSymDenseMatrix<int,ScalarType>> spdMatrix_;
162 Teuchos::RCP<Teuchos::SerialSpdDenseSolver<int,ScalarType>> spdSolver_;
168 template<
class ScalarType>
178 static Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType>>
Create() {
179 return Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>());
195 static Teuchos::RCP<Teuchos::SerialDenseMatrix<int,ScalarType>>
CreateCopy(
const Teuchos::SerialDenseMatrix<int,ScalarType> &
dm,
bool transpose=
false) {
197 return Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(
dm, Teuchos::CONJ_TRANS));
199 return Teuchos::rcp(
new Teuchos::SerialDenseMatrix<int,ScalarType>(Teuchos::Copy,
dm));
204 {
return dm.values(); }
227 static Teuchos::RCP<const Teuchos::SerialDenseMatrix<int,ScalarType>>
SubviewConst(
239 static int GetNumRows(
const Teuchos::SerialDenseMatrix<int,ScalarType>&
dm )
240 {
return dm.numRows(); }
243 static int GetNumCols(
const Teuchos::SerialDenseMatrix<int,ScalarType>&
dm )
244 {
return dm.numCols(); }
247 static int GetStride(
const Teuchos::SerialDenseMatrix<int,ScalarType>&
dm )
248 {
return dm.stride(); }
263 if(
err != 0){
throw std::runtime_error (
"Error in DenseMatrixTraits::shape. Teuchos::SerialDenseMatrix.shape failed.");}
267 if(
err != 0){
throw std::runtime_error (
"Error in DenseMatrixTraits::reshape. Teuchos::SerialDenseMatrix.reshape failed.");}
295 static void Add( Teuchos::SerialDenseMatrix<int,ScalarType>&
thisDM,
const Teuchos::SerialDenseMatrix<int,ScalarType>&
sourceDM){
300 static void PutScalar( Teuchos::SerialDenseMatrix<int,ScalarType> &
dm,
ScalarType value = Teuchos::ScalarTraits<ScalarType>::zero()){
312 static void Randomize( Teuchos::SerialDenseMatrix<int,ScalarType>&
dm){
317 static void Assign( Teuchos::SerialDenseMatrix<int,ScalarType>&
dest,
const Teuchos::SerialDenseMatrix<int,ScalarType>&
source){
322 static typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
NormFrobenius(
const Teuchos::SerialDenseMatrix<int,ScalarType>&
dm) {
323 return dm.normFrobenius();
327 static typename Teuchos::ScalarTraits<ScalarType>::magnitudeType
NormOne(
const Teuchos::SerialDenseMatrix<int,ScalarType>&
dm) {
335 static Teuchos::RCP<DenseSolver<ScalarType, Teuchos::SerialDenseMatrix<int,ScalarType>>>
338 Teuchos::RCP<DenseSolver<ScalarType, Teuchos::SerialDenseMatrix<int,ScalarType>>>
newSolver
Virtual base class which defines solvers for dense matrix type.
static void PutScalar(Teuchos::SerialDenseMatrix< int, ScalarType > &dm, ScalarType value=Teuchos::ScalarTraits< ScalarType >::zero())
Fill all entries with value. Value is zero if not specified.
static void Reshape(Teuchos::SerialDenseMatrix< int, ScalarType > &dm, const int numrows, const int numcols, bool initZero=false)
static int GetNumRows(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Obtain the number of rows of dm.
static Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > SubviewCopy(const Teuchos::SerialDenseMatrix< int, ScalarType > &source, int numRows, int numCols, int startRow=0, int startCol=0)
Returns a deep copy of the requested subview.
static Teuchos::RCP< const Teuchos::SerialDenseMatrix< int, ScalarType > > SubviewConst(const Teuchos::SerialDenseMatrix< int, ScalarType > &source, int numRows, int numCols, int startRow=0, int startCol=0)
static ScalarType const * GetConstRawHostPtr(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Returns a raw pointer to const data on the host.
static void Assign(Teuchos::SerialDenseMatrix< int, ScalarType > &dest, const Teuchos::SerialDenseMatrix< int, ScalarType > &source)
Copies entries of source to dest (deep copy).
static void Scale(Teuchos::SerialDenseMatrix< int, ScalarType > &dm, ScalarType value)
Multiply all entries by a scalar. DM = value.*DM.
static Teuchos::RCP< DenseSolver< ScalarType, Teuchos::SerialDenseMatrix< int, ScalarType > > > createDenseSolver()
Returns a dense solver object for the dense matrix.
static ScalarType * GetRawHostPtr(Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Returns a raw pointer to the (non-const) data on the host.
static ScalarType & Value(Teuchos::SerialDenseMatrix< int, ScalarType > &dm, const int i, const int j)
Access a reference to the (i,j) entry of dm, e_i^T dm e_j.
static void Randomize(Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Fill the DM with random entries.
static Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > CreateCopy(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm, bool transpose=false)
Create a new copy Teuchos::SerialDenseMatrix<int,ScalarType>, possibly transposed.
static int GetStride(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Obtain the stride between the columns of dm.
static Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Subview(Teuchos::SerialDenseMatrix< int, ScalarType > &source, int numRows, int numCols, int startRow=0, int startCol=0)
Marks host data modified to avoid device sync errors.
static void Add(Teuchos::SerialDenseMatrix< int, ScalarType > &thisDM, const Teuchos::SerialDenseMatrix< int, ScalarType > &sourceDM)
Adds sourceDM to thisDM and returns answer in thisDM.
static int GetNumCols(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Obtain the number of columns of dm.
static Teuchos::ScalarTraits< ScalarType >::magnitudeType NormOne(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Returns the one-norm of the dense matrix.
static Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Create(const int numrows, const int numcols, bool initZero=true)
Creates a new empty Teuchos::SerialDenseMatrix<int,ScalarType> containing numvecs columns....
static void SyncDeviceToHost(Teuchos::SerialDenseMatrix< int, ScalarType > &)
static void SyncHostToDevice(Teuchos::SerialDenseMatrix< int, ScalarType > &)
static const ScalarType & ValueConst(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm, const int i, const int j)
Access a const reference to the (i,j) entry of dm, e_i^T dm e_j.
static Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > Create()
Creates a new empty Teuchos::SerialDenseMatrix<int,ScalarType> with no dimension.
static Teuchos::ScalarTraits< ScalarType >::magnitudeType NormFrobenius(const Teuchos::SerialDenseMatrix< int, ScalarType > &dm)
Returns the Frobenius norm of the dense matrix.
Virtual base class which defines basic traits for the multi-vector type.
void setSPD(bool flag)
Set if dense matrix is symmetric positive definite.
void solveWithTransposeFlag(Teuchos::ETransp trans)
All subsequent function calls will work with the transpose-type set by this method (Teuchos::NO_TRANS...
virtual int setMatrix(const Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > &A)
Sets the pointers for coefficient matrix.
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > B_
virtual int setVectors(const Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > &X, const Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > &B)
Sets the pointers for left and right hand side vector(s).
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > X_
Teuchos::RCP< Teuchos::SerialDenseMatrix< int, ScalarType > > A_
void factorWithEquilibration(bool flag)
Causes equilibration to be called just before the matrix factorization as part of the call to factor.
Alternative run-time polymorphic interface for operators.
Full specialization of Belos::DenseSolver for Teuchos::SerialDenseMatrix<int,ST>.
int solve()
Computes the solution X to AX = B for the this matrix and the B provided.
int factor()
Computes the in-place LU factorization of the matrix.
virtual ~TeuchosDenseSolver()
TeuchosDenseSolver destructor.
TeuchosDenseSolver()
Default constructor; matrix should be set using setMatrix(), LHS and RHS set with setVectors().