10 #ifndef XPETRA_TPETRAHALFPRECISIONOPEARTOR_HPP
11 #define XPETRA_TPETRAHALFPRECISIONOPEARTOR_HPP
15 #include <Teuchos_ScalarTraits.hpp>
17 #include <Tpetra_CrsMatrix.hpp>
19 #include <Xpetra_MultiVector.hpp>
20 #include <Xpetra_CrsMatrixWrap.hpp>
21 #include <Xpetra_MultiVectorFactory.hpp>
25 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
26 RCP<Xpetra::Matrix<typename Teuchos::ScalarTraits<Scalar>::halfPrecision, LocalOrdinal, GlobalOrdinal, Node>>
28 #if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT)
29 using HalfScalar =
typename Teuchos::ScalarTraits<Scalar>::halfPrecision;
34 auto newTpCrs = tpCrs->template convert<HalfScalar>();
41 "Xpetra::convertToHalfPrecision only available for Tpetra with SC=double and SC=float enabled");
42 TEUCHOS_UNREACHABLE_RETURN(
false);
46 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
47 RCP<Xpetra::MultiVector<typename Teuchos::ScalarTraits<Scalar>::halfPrecision, LocalOrdinal, GlobalOrdinal, Node>>
49 #if defined(HAVE_TPETRA_INST_DOUBLE) && defined(HAVE_TPETRA_INST_FLOAT)
50 using HalfScalar =
typename Teuchos::ScalarTraits<Scalar>::halfPrecision;
53 auto newTpX = tpX.template convert<HalfScalar>();
59 "Xpetra::convertToHalfPrecision only available for Tpetra with SC=double and SC=float enabled");
60 TEUCHOS_UNREACHABLE_RETURN(
false);
66 template <
class Scalar,
69 class Node = Tpetra::KokkosClassic::DefaultNode::DefaultNodeType>
72 typedef typename Teuchos::ScalarTraits<Scalar>::halfPrecision
HalfScalar;
94 const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
getDomainMap()
const {
95 return Op_->getDomainMap();
99 const Teuchos::RCP<const Xpetra::Map<LocalOrdinal, GlobalOrdinal, Node>>
getRangeMap()
const {
100 return Op_->getRangeMap();
110 Teuchos::ETransp mode = Teuchos::NO_TRANS,
111 Scalar alpha = Teuchos::ScalarTraits<Scalar>::one(),
112 Scalar beta = Teuchos::ScalarTraits<Scalar>::one())
const {
114 Tpetra::deep_copy(*Teuchos::rcp_dynamic_cast<tMVHalf>(
X_)->getTpetra_MultiVector(),
116 Op_->apply(*
X_, *
Y_, mode, Teuchos::as<HalfScalar>(alpha), Teuchos::as<HalfScalar>(beta));
118 *Teuchos::rcp_dynamic_cast<tMVHalf>(
Y_)->getTpetra_MultiVector());
128 using STS = Teuchos::ScalarTraits<Scalar>;
129 R.
update(STS::one(), B, STS::zero());
130 this->
apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
144 RCP<Xpetra::Operator<HalfScalar, LocalOrdinal, GlobalOrdinal, Node>>
Op_;
145 RCP<Xpetra::MultiVector<HalfScalar, LocalOrdinal, GlobalOrdinal, Node>>
X_,
Y_;
150 #endif // XPETRA_TPETRAHALFPRECISIONOPEARTOR_HPP
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
Constructor specifying the number of non-zeros for all rows.
Teuchos::ScalarTraits< Scalar >::halfPrecision HalfScalar
void SetHalfPrecisionOperator(const RCP< Xpetra::Operator< HalfScalar, LocalOrdinal, GlobalOrdinal, Node >> &op)
RCP< Xpetra::Matrix< typename Teuchos::ScalarTraits< Scalar >::halfPrecision, LocalOrdinal, GlobalOrdinal, Node > > convertToHalfPrecision(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> &A)
Wraps an existing halfer precision Xpetra::Operator as a Xpetra::Operator.
RCP< Xpetra::Operator< HalfScalar, LocalOrdinal, GlobalOrdinal, Node > > GetHalfPrecisionOperator() const
Direct access to the underlying TpetraOperator.
Exception throws to report errors in the internal logical of the program.
RCP< Xpetra::MultiVector< HalfScalar, LocalOrdinal, GlobalOrdinal, Node > > X_
void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::one()) const
Returns in Y the result of a Xpetra::TpetraOperator applied to a Xpetra::MultiVector X...
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
Update multi-vector values with scaled values of A, this = beta*this + alpha*A.
TpetraHalfPrecisionOperator(const RCP< Xpetra::Operator< HalfScalar, LocalOrdinal, GlobalOrdinal, Node >> &op)
Constructor.
void residual(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
RCP< const Tpetra::CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > toTpetra(const RCP< const CrsGraph< LocalOrdinal, GlobalOrdinal, Node > > &graph)
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this TpetraOperator.
RCP< Xpetra::MultiVector< HalfScalar, LocalOrdinal, GlobalOrdinal, Node > > Y_
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this TpetraOperator. ...
Concrete implementation of Xpetra::Matrix.
bool hasTransposeApply() const
Indicates whether this TpetraOperator supports applying the adjoint TpetraOperator.
void Allocate(int numVecs)
RCP< Xpetra::Operator< HalfScalar, LocalOrdinal, GlobalOrdinal, Node > > Op_
Xpetra-specific matrix class.
virtual ~TpetraHalfPrecisionOperator()
Destructor.