RTOp Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
RTOpPack_LapackWrappers.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // RTOp: Interfaces and Support Software for Vector Reduction Transformation
4 // Operations
5 //
6 // Copyright 2006 NTESS and the RTOp contributors.
7 // SPDX-License-Identifier: BSD-3-Clause
8 // *****************************************************************************
9 // @HEADER
10 
11 #ifndef RTOPPACK_LAPACK_WRAPPERS_HPP
12 #define RTOPPACK_LAPACK_WRAPPERS_HPP
13 
14 
15 #include "RTOpPack_Types.hpp"
16 #include "Teuchos_LAPACK.hpp"
17 #include "Teuchos_as.hpp"
18 
19 
20 namespace RTOpPack {
21 
22 
24 enum ETransp {
26 };
27 const int NUM_ETRANS_ARGS = 3;
28 
31 
32 
43 template<class Scalar>
44 void getrf(
46  const ArrayView<int> &ipiv,
47  const Ptr<int> &rank
48  );
49 
50 
52 template<class Scalar>
53 void getrs(
55  const ArrayView<const int> &ipiv,
56  const ETransp transp,
57  const Ptr<const SubMultiVectorView<Scalar> > &BX
58  );
59 
60 
61 } // namespace RTOpPack
62 
63 
64 //
65 // Implementations
66 //
67 
68 
69 template<class Scalar>
72  const ArrayView<int> &ipiv,
73  const Ptr<int> &rank
74  )
75 {
76  using Teuchos::as;
77  const int maxRank = TEUCHOS_MIN( A.subDim(), A.numSubCols() );
78 #ifdef TEUCHOS_DEBUG
79  TEUCHOS_TEST_FOR_EXCEPT( A.subDim() == 0 );
82  TEUCHOS_ASSERT_EQUALITY( as<int>(ipiv.size()), maxRank );
83 #endif
84 
86  int info = -1;
87  lapack.GETRF( A.subDim(), A.numSubCols(), A.values().get(), A.leadingDim(),
88  &ipiv[0], &info );
89  *rank = maxRank;
91  info < 0, std::invalid_argument
92  ,"getrf(...): Error, Invalid argument "
93  << -info << " sent to LAPACK function xGETRF(...)" );
94  if (info > 0)
95  *rank = info - 1;
96 }
97 
98 
99 template<class Scalar>
102  const ArrayView<const int> &ipiv,
103  const ETransp transp,
104  const Ptr<const SubMultiVectorView<Scalar> > &BX
105  )
106 {
107  using Teuchos::as;
108 #ifdef TEUCHOS_DEBUG
109  TEUCHOS_ASSERT( !is_null(BX) );
110  TEUCHOS_ASSERT_EQUALITY( A.subDim(), BX->subDim() );
112  TEUCHOS_TEST_FOR_EXCEPT( A.subDim() == 0 );
115  TEUCHOS_ASSERT_EQUALITY( A.subDim(), ipiv.size() );
116 #endif
118  int info = -1;
119  lapack.GETRS(
120  transpMap[transp],
121  A.subDim(), BX->numSubCols(), A.values().get(), A.leadingDim(),
122  &ipiv[0], BX->values().get(), BX->leadingDim(), &info
123  );
125  info < 0, std::invalid_argument
126  ,"getrs(...): Error, Invalid argument "
127  << -info << " sent to LAPACK function xGETRS(...)" );
128  // If we get here B is the solution to the linear system.
129 }
130 
131 
132 #endif // RTOPPACK_LAPACK_WRAPPERS_HPP
bool is_null(const boost::shared_ptr< T > &p)
void getrs(const ConstSubMultiVectorView< Scalar > &A, const ArrayView< const int > &ipiv, const ETransp transp, const Ptr< const SubMultiVectorView< Scalar > > &BX)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
size_type size() const
const ArrayRCP< Scalar > values() const
const int NUM_ETRANS_ARGS
void GETRF(const OrdinalType &m, const OrdinalType &n, ScalarType *A, const OrdinalType &lda, OrdinalType *IPIV, OrdinalType *info) const
Class for a changeable sub-vector.
TypeTo as(const TypeFrom &t)
void getrf(const SubMultiVectorView< Scalar > &A, const ArrayView< int > &ipiv, const Ptr< int > &rank)
Peform an in-place factorization of a square or rectangular matrix.
const ArrayRCP< const Scalar > values() const
const Teuchos::Tuple< char, NUM_ETRANS_ARGS > transpMap
void GETRS(const char &TRANS, const OrdinalType &n, const OrdinalType &nrhs, const ScalarType *A, const OrdinalType &lda, const OrdinalType *IPIV, ScalarType *B, const OrdinalType &ldb, OrdinalType *info) const
Class for a non-changeable sub-multi-vector (submatrix).
#define TEUCHOS_ASSERT(assertion_test)
#define TEUCHOS_ASSERT_EQUALITY(val1, val2)
#define TEUCHOS_MIN(x, y)
T * get() const
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)