42 #ifndef TPETRA_EXPERIMENTAL_BLOCKVIEW_HPP 43 #define TPETRA_EXPERIMENTAL_BLOCKVIEW_HPP 48 #include "Tpetra_ConfigDefs.hpp" 49 #include "Teuchos_ScalarTraits.hpp" 50 #include "Teuchos_LAPACK.hpp" 51 #ifdef HAVE_TPETRA_INST_FLOAT128 52 # include "Teuchos_BLAS.hpp" 53 #endif // HAVE_TPETRA_INST_FLOAT128 55 #include "Kokkos_ArithTraits.hpp" 56 #include "Kokkos_Complex.hpp" 58 #ifdef HAVE_TPETRA_INST_FLOAT128 59 # include "Teuchos_Details_Lapack128.hpp" 60 #endif // HAVE_TPETRA_INST_FLOAT128 74 template<
class Scalar>
76 typedef Scalar lapack_scalar_type;
77 typedef Teuchos::LAPACK<int, Scalar> lapack_type;
82 typedef std::complex<T> lapack_scalar_type;
83 typedef Teuchos::LAPACK<int, std::complex<T> > lapack_type;
86 #ifdef HAVE_TPETRA_INST_FLOAT128 89 typedef __float128 lapack_scalar_type;
93 typedef Teuchos::Details::Lapack128 lapack_type;
95 #endif // HAVE_TPETRA_INST_FLOAT128 114 namespace Experimental {
130 template<
class Scalar,
class LO>
133 typedef Scalar scalar_type;
134 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
137 typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
149 A_ (reinterpret_cast<impl_scalar_type*> (A)),
150 blockSize_ (blockSize),
177 typename std::enable_if<
178 ! std::is_same<Scalar, T>::value &&
179 std::is_convertible<Scalar, T>::value &&
180 sizeof (Scalar) ==
sizeof (T),
181 int*>::type ignoreMe = NULL) :
182 A_ (reinterpret_cast<impl_scalar_type*> (A)),
183 blockSize_ (blockSize),
195 return reinterpret_cast<Scalar*
> (A_);
208 impl_scalar_type& operator() (
const LO i,
const LO j)
const {
209 return A_[i * strideX_ + j * strideY_];
213 template<
class LittleBlockType>
214 void update (
const Scalar& alpha,
const LittleBlockType& X)
const {
215 const impl_scalar_type theAlpha =
static_cast<Scalar
> (alpha);
216 for (LO j = 0; j < blockSize_; ++j) {
217 for (LO i = 0; i < blockSize_; ++i) {
218 (*this)(i,j) += theAlpha * X(i,j);
224 template<
class LittleBlockType>
225 void assign (
const LittleBlockType& X)
const {
226 for (LO j = 0; j < blockSize_; ++j) {
227 for (LO i = 0; i < blockSize_; ++i) {
228 (*this)(i,j) = X(i,j);
234 void scale (
const Scalar& alpha)
const {
235 const impl_scalar_type theAlpha =
static_cast<Scalar
> (alpha);
236 for (LO j = 0; j < blockSize_; ++j) {
237 for (LO i = 0; i < blockSize_; ++i) {
238 (*this)(i,j) *= theAlpha;
244 void fill (
const Scalar& alpha)
const {
245 const impl_scalar_type theAlpha =
static_cast<Scalar
> (alpha);
246 for (LO j = 0; j < blockSize_; ++j) {
247 for (LO i = 0; i < blockSize_; ++i) {
248 (*this)(i,j) = theAlpha;
257 template<
class LittleBlockType>
258 void absmax (
const LittleBlockType& X)
const {
259 for (LO j = 0; j < blockSize_; ++j) {
260 for (LO i = 0; i < blockSize_; ++i) {
261 impl_scalar_type& Y_ij = (*this)(i,j);
262 const impl_scalar_type X_ij = X(i,j);
263 Y_ij = std::max (STS::magnitude (Y_ij), STS::magnitude (X_ij));
268 void factorize (
int* ipiv,
int & info)
270 typedef typename Tpetra::Details::GetLapackType<Scalar>::lapack_scalar_type LST;
271 typedef typename Tpetra::Details::GetLapackType<Scalar>::lapack_type lapack_type;
273 LST*
const A_raw =
reinterpret_cast<LST*
> (A_);
278 lapack.GETRF(blockSize_, blockSize_, A_raw, blockSize_, ipiv, &info);
281 template<
class LittleVectorType>
282 void solve (LittleVectorType & X,
const int* ipiv)
const 284 typedef typename Tpetra::Details::GetLapackType<Scalar>::lapack_scalar_type LST;
285 typedef typename Tpetra::Details::GetLapackType<Scalar>::lapack_type lapack_type;
291 LST*
const A_raw =
reinterpret_cast<LST*
> (A_);
292 LST*
const X_raw =
reinterpret_cast<LST*
> (X.getRawPtr ());
297 lapack.GETRS(trans, blockSize_, 1, A_raw, blockSize_, ipiv, X_raw, blockSize_, &info);
301 impl_scalar_type*
const A_;
324 template<
class Scalar,
class LO>
327 typedef Scalar scalar_type;
328 typedef typename Kokkos::Details::ArithTraits<Scalar>::val_type impl_scalar_type;
331 typedef Kokkos::Details::ArithTraits<impl_scalar_type> STS;
339 A_ (reinterpret_cast<impl_scalar_type*> (A)),
340 blockSize_ (blockSize),
364 typename std::enable_if<
365 ! std::is_same<Scalar, T>::value &&
366 std::is_convertible<Scalar, T>::value &&
367 sizeof (Scalar) ==
sizeof (T),
368 int*>::type ignoreMe = NULL) :
369 A_ (reinterpret_cast<impl_scalar_type*> (A)),
370 blockSize_ (blockSize),
376 return reinterpret_cast<Scalar*
> (A_);
399 impl_scalar_type& operator() (
const LO i)
const {
400 return A_[i * strideX_];
404 template<
class LittleVectorType>
405 void update (
const Scalar& alpha,
const LittleVectorType& X)
const {
406 const impl_scalar_type theAlpha =
static_cast<impl_scalar_type
> (alpha);
407 for (LO i = 0; i < blockSize_; ++i) {
408 (*this)(i) += theAlpha * X(i);
413 template<
class LittleVectorType>
414 void assign (
const LittleVectorType& X)
const {
415 for (LO i = 0; i < blockSize_; ++i) {
421 void scale (
const Scalar& alpha)
const {
422 const impl_scalar_type theAlpha =
static_cast<impl_scalar_type
> (alpha);
423 for (LO i = 0; i < blockSize_; ++i) {
424 (*this)(i) *= theAlpha;
429 void fill (
const Scalar& alpha)
const {
430 const impl_scalar_type theAlpha =
static_cast<impl_scalar_type
> (alpha);
431 for (LO i = 0; i < blockSize_; ++i) {
432 (*this)(i) = theAlpha;
440 template<
class LittleVectorType>
441 void absmax (
const LittleVectorType& X)
const {
442 for (LO i = 0; i < blockSize_; ++i) {
443 impl_scalar_type& Y_i = (*this)(i);
444 Y_i = std::max (STS::magnitude (Y_i), STS::magnitude (X (i)));
449 template<
class LittleVectorType>
450 bool equal (
const LittleVectorType& X)
const {
451 if (getBlockSize () != X.getBlockSize ()) {
454 for (LO i = 0; i < blockSize_; ++i) {
455 if ((*
this)(i) != X(i)) {
463 template<
class LittleBlockType,
class LittleVectorType>
466 const LittleBlockType& A,
467 const LittleVectorType& X)
const 469 const impl_scalar_type theAlpha =
static_cast<impl_scalar_type
> (alpha);
473 for (LO i = 0; i < blockSize_; ++i) {
474 for (LO j = 0; j < blockSize_; ++j) {
475 (*this)(i) += theAlpha * A(i,j) * X(j);
481 impl_scalar_type*
const A_;
489 #endif // TPETRA_EXPERIMENTAL_BLOCKVIEW_HPP Namespace Tpetra contains the class and methods constituting the Tpetra library.
void fill(const Scalar &alpha) const
(*this)(i,j) := alpha for all (i,j).
void scale(const Scalar &alpha) const
(*this)(i,j) := alpha * (*this)(i,j) for all (i,j).
Scalar * getRawPtr() const
Pointer to the block's entries, as Scalar*.
void matvecUpdate(const Scalar &alpha, const LittleBlockType &A, const LittleVectorType &X) const
(*this) := (*this) + alpha * A * X (matrix-vector multiply).
void absmax(const LittleBlockType &X) const
(*this)(i,j) := max(abs((*this)(i,j)), abs(X(i,j))) for all (i,j).
Nonowning view of a square dense block in a block matrix.
void scale(const Scalar &alpha) const
(*this)(i,j) := alpha * (*this)(i,j) for all (i,j).
LO getStride() const
Stride between consecutive entries.
void assign(const LittleVectorType &X) const
*this := X.
LittleVector(T *const A, const LO blockSize, const LO stride, typename std::enable_if< !std::is_same< Scalar, T >::value &&std::is_convertible< Scalar, T >::value &&sizeof(Scalar)==sizeof(T), int * >::type ignoreMe=NULL)
Constructor that takes an impl_scalar_type pointer.
bool equal(const LittleVectorType &X) const
true if and only if all entries of this equal all entries of X.
Implementation details of Tpetra.
LittleBlock(Scalar *const A, const LO blockSize, const LO strideX, const LO strideY)
Constructor.
void update(const Scalar &alpha, const LittleBlockType &X) const
*this := *this + alpha * X.
Scalar * getRawPtr() const
Pointer to the block's entries.
Nonowning view of a set of degrees of freedom corresponding to a mesh point in a block vector or mult...
LO getBlockSize() const
The block size (number of rows, and number of columns).
void fill(const Scalar &alpha) const
(*this)(i,j) := alpha for all (i,j).
LittleVector(Scalar *const A, const LO blockSize, const LO stride)
Constructor.
LO getBlockSize() const
The block size (number of degrees of freedom per mesh point).
void update(const Scalar &alpha, const LittleVectorType &X) const
*this := *this + alpha * X.
void assign(const LittleBlockType &X) const
*this := X.
Return the Teuchos::LAPACK specialization corresponding to the given Scalar type. ...
LittleBlock(T *const A, const LO blockSize, const LO strideX, const LO strideY, typename std::enable_if< !std::is_same< Scalar, T >::value &&std::is_convertible< Scalar, T >::value &&sizeof(Scalar)==sizeof(T), int * >::type ignoreMe=NULL)
Constructor that takes an impl_scalar_type pointer.
void absmax(const LittleVectorType &X) const
(*this)(i,j) := max(abs((*this)(i,j)), abs(X(i,j))) for all (i,j).