BELFEM 0.9.0
Berkeley Lab Finite Element Framework
Loading...
Searching...
No Matches
fn_getrf.hpp
Go to the documentation of this file.
1/*
2 * BELFEM -- The Berkeley Lab Finite Element Framework
3 * Copyright (c) 2026, The Regents of the University of California,
4 * through Lawrence Berkeley National Laboratory (subject to receipt of any required
5 * approvals from the U.S. Dept. of Energy). All rights reserved.
6 *
7 * Developers: Christian Messe, Gregory Giard
8 *
9 * See the top-level LICENSE file for the complete license and disclaimer.
10 */
11
21
22#ifndef BELFEM_FN_LAPACK_GETRF_HPP
23#define BELFEM_FN_LAPACK_GETRF_HPP
24
25#include "assert.hpp"
26#include "lapacktools.hpp"
27
28//------------------------------------------------------------------------------
29namespace belfem
30{
31 namespace lapack
32 {
33//------------------------------------------------------------------------------
34
35#ifdef __cplusplus
36 extern "C"
37 {
38#endif
39//------------------------------------------------------------------------------
40
41 void
43 int_t * n,
44 float * a,
45 int_t * lda,
46 int_t * ipiv,
47 int_t * info );
48
49//------------------------------------------------------------------------------
50
51 void
53 int_t * n,
54 double * a,
55 int_t * lda,
56 int_t * ipiv,
57 int_t * info );
58
59//------------------------------------------------------------------------------
60
61 void
63 int_t * n,
64 cplx_float_t * a,
65 int_t * lda,
66 int_t * ipiv,
67 int_t * info );
68
69//------------------------------------------------------------------------------
70
71 void
73 int_t * n,
74 cplx_double_t * a,
75 int_t * lda,
76 int_t * ipiv,
77 int_t * info );
78
79//------------------------------------------------------------------------------
80
81#ifdef __cplusplus
82}
83#endif
84
85//------------------------------------------------------------------------------
86
87 template< typename T >
88 void
89 getrf( const int_t * m,
90 const int_t * n,
91 T * a,
92 const int_t * lda,
93 int_t * ipiv,
94 int_t * info )
95 {
96 static_assert( dependent_false< T >,
97 "getrf not implemented for selected data type" );
98 }
99
100// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
101
102 template<>
103 inline void
104 getrf( const int_t * m,
105 const int_t * n,
106 float * a,
107 const int_t * lda,
108 int_t * ipiv,
109 int_t * info )
110 {
111 sgetrf_( const_cast< int_t * >( m ),
112 const_cast< int_t * >( n ),
113 a,
114 const_cast< int_t * >( lda ),
115 ipiv,
116 info );
117 }
118
119// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
120
121 template<>
122 inline void
123 getrf( const int_t * m,
124 const int_t * n,
125 double * a,
126 const int_t * lda,
127 int_t * ipiv,
128 int_t * info )
129 {
130 dgetrf_( const_cast< int_t * >( m ),
131 const_cast< int_t * >( n ),
132 a,
133 const_cast< int_t * >( lda ),
134 ipiv,
135 info );
136 }
137
138// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
139
140 template<>
141 inline void
142 getrf( const int_t * m,
143 const int_t * n,
144 std::complex< float > * a,
145 const int_t * lda,
146 int_t * ipiv,
147 int_t * info )
148 {
149 cgetrf_( const_cast< int_t * >( m ),
150 const_cast< int_t * >( n ),
151 reinterpret_cast< cplx_float_t * >( a ),
152 const_cast< int_t * >( lda ),
153 ipiv,
154 info );
155 }
156
157// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
158
159 template<>
160 inline void
161 getrf( const int_t * m,
162 const int_t * n,
163 std::complex< double > * a,
164 const int_t * lda,
165 int_t * ipiv,
166 int_t * info )
167 {
168 zgetrf_( const_cast< int_t * >( m ),
169 const_cast< int_t * >( n ),
170 reinterpret_cast< cplx_double_t * >( a ),
171 const_cast< int_t * >( lda ),
172 ipiv,
173 info );
174 }
175
176//------------------------------------------------------------------------------
177 } /* end namespace lapack */
178//------------------------------------------------------------------------------
179
191 template< typename T >
192 int_t
193 getrf( Matrix< T > & A , Vector< int_t > & Pivot, const bool AbortOnError = true )
194 {
195 int_t m = A.n_rows() ;
196 int_t n = A.n_cols() ;
198 int_t info = 0 ;
199
200 if ( ( int_t ) Pivot.length() < std::min( m, n ) )
201 {
202 Pivot.set_size( std::min( m, n ), 0 );
203 }
204
205 lapack::getrf( &m, &n, A.data(), &lda, Pivot.data(), & info );
206
207 BELFEM_ERROR( info == 0 || ! AbortOnError,
208 "LAPACK getrf has thrown an error: %i", ( int ) info );
209
210 return info ;
211 }
212
213//------------------------------------------------------------------------------
214
215} /* end namespace belfem */
216
217#endif //BELFEM_FN_LAPACK_GETRF_HPP
#define BELFEM_ERROR(aCheck,...)
Definition assert.hpp:264
Dense column-major matrix.
Definition cl_BZ_Matrix.hpp:28
size_t n_rows() const
Definition cl_AR_Matrix.hpp:205
size_t n_cols() const
Definition cl_AR_Matrix.hpp:213
T * data()
Definition cl_AR_Matrix.hpp:135
T * data()
expose the underlying raw pointer ( writable version )
Definition cl_AR_Vector.hpp:182
void set_size(const size_t aNumRows)
change the size of the vector
Definition cl_AR_Vector.hpp:237
size_t length() const
get the length of the vector
Definition cl_AR_Vector.hpp:257
Shared helpers for the LAPACK wrappers, such as leading_dimension().
Definition fn_gees.hpp:33
void zgetrf_(int_t *m, int_t *n, cplx_double_t *a, int_t *lda, int_t *ipiv, int_t *info)
constexpr bool dependent_false
Definition lapacktools.hpp:49
float cplx_float_t
Definition lapacktools.hpp:90
int_t leading_dimension(const Vector< T > &A)
logical length of a vector operand, as passed to LAPACK as LDB; vector storage is contiguous under bo...
Definition lapacktools.hpp:143
void dgetrf_(int_t *m, int_t *n, double *a, int_t *lda, int_t *ipiv, int_t *info)
double cplx_double_t
Definition lapacktools.hpp:91
void cgetrf_(int_t *m, int_t *n, cplx_float_t *a, int_t *lda, int_t *ipiv, int_t *info)
void getrf(const int_t *m, const int_t *n, T *a, const int_t *lda, int_t *ipiv, int_t *info)
Definition fn_getrf.hpp:89
void sgetrf_(int_t *m, int_t *n, float *a, int_t *lda, int_t *ipiv, int_t *info)
USER GUIDES:
Definition cl_Capacitor.cpp:16
int_t getrf(Matrix< T > &A, Vector< int_t > &Pivot, const bool AbortOnError=true)
LU factorization with partial pivoting via LAPACK ?getrf, A = P * L * U; use together with getri() to...
Definition fn_getrf.hpp:193
int32_t int_t
Definition typedefs.hpp:51