libMesh
dense_matrix_blas_lapack.C
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 // Local Includes
20 #include "libmesh/dense_matrix.h"
21 #include "libmesh/dense_vector.h"
22 #include "libmesh/int_range.h"
23 
24 #if (LIBMESH_HAVE_PETSC)
25 # include "libmesh/petsc_macro.h"
26 # include "libmesh/ignore_warnings.h"
27 # include <petscblaslapack.h>
28 # include "libmesh/restore_warnings.h"
29 #endif
30 
31 namespace libMesh
32 {
33 
34 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
35 
36 template<typename T>
39 {
40  int result_size = 0;
41 
42  // For each case, determine the size of the final result make sure
43  // that the inner dimensions match
44  switch (flag)
45  {
46  case LEFT_MULTIPLY:
47  {
48  result_size = other.m() * this->n();
49  if (other.n() == this->m())
50  break;
51  }
52  libmesh_fallthrough();
53  case RIGHT_MULTIPLY:
54  {
55  result_size = other.n() * this->m();
56  if (other.m() == this->n())
57  break;
58  }
59  libmesh_fallthrough();
60  case LEFT_MULTIPLY_TRANSPOSE:
61  {
62  result_size = other.n() * this->n();
63  if (other.m() == this->m())
64  break;
65  }
66  libmesh_fallthrough();
67  case RIGHT_MULTIPLY_TRANSPOSE:
68  {
69  result_size = other.m() * this->m();
70  if (other.n() == this->n())
71  break;
72  }
73  libmesh_fallthrough();
74  default:
75  libmesh_error_msg("Unknown flag selected or matrices are incompatible for multiplication.");
76  }
77 
78  // For this to work, the passed arg. must actually be a DenseMatrix<T>
79  const DenseMatrix<T> * const_that = cast_ptr<const DenseMatrix<T> *>(&other);
80 
81  // Also, although 'that' is logically const in this BLAS routine,
82  // the PETSc BLAS interface does not specify that any of the inputs are
83  // const. To use it, I must cast away const-ness.
84  DenseMatrix<T> * that = const_cast<DenseMatrix<T> *> (const_that);
85 
86  // Initialize A, B pointers for LEFT_MULTIPLY* cases
87  DenseMatrix<T> * A = this;
88  DenseMatrix<T> * B = that;
89 
90  // For RIGHT_MULTIPLY* cases, swap the meaning of A and B.
91  // Here is a full table of combinations we can pass to BLASgemm, and what the answer is when finished:
92  // pass A B -> (Fortran) -> A^T B^T -> (C++) -> (A^T B^T)^T -> (identity) -> B A "lt multiply"
93  // pass B A -> (Fortran) -> B^T A^T -> (C++) -> (B^T A^T)^T -> (identity) -> A B "rt multiply"
94  // pass A B^T -> (Fortran) -> A^T B -> (C++) -> (A^T B)^T -> (identity) -> B^T A "lt multiply t"
95  // pass B^T A -> (Fortran) -> B A^T -> (C++) -> (B A^T)^T -> (identity) -> A B^T "rt multiply t"
96  if (flag==RIGHT_MULTIPLY || flag==RIGHT_MULTIPLY_TRANSPOSE)
97  std::swap(A,B);
98 
99  // transa, transb values to pass to blas
100  char
101  transa[] = "n",
102  transb[] = "n";
103 
104  // Integer values to pass to BLAS:
105  //
106  // M
107  // In Fortran, the number of rows of op(A),
108  // In the BLAS documentation, typically known as 'M'.
109  //
110  // In C/C++, we set:
111  // M = n_cols(A) if (transa='n')
112  // n_rows(A) if (transa='t')
113  PetscBLASInt M = static_cast<PetscBLASInt>( A->n() );
114 
115  // N
116  // In Fortran, the number of cols of op(B), and also the number of cols of C.
117  // In the BLAS documentation, typically known as 'N'.
118  //
119  // In C/C++, we set:
120  // N = n_rows(B) if (transb='n')
121  // n_cols(B) if (transb='t')
122  PetscBLASInt N = static_cast<PetscBLASInt>( B->m() );
123 
124  // K
125  // In Fortran, the number of cols of op(A), and also
126  // the number of rows of op(B). In the BLAS documentation,
127  // typically known as 'K'.
128  //
129  // In C/C++, we set:
130  // K = n_rows(A) if (transa='n')
131  // n_cols(A) if (transa='t')
132  PetscBLASInt K = static_cast<PetscBLASInt>( A->m() );
133 
134  // LDA (leading dimension of A). In our cases,
135  // LDA is always the number of columns of A.
136  PetscBLASInt LDA = static_cast<PetscBLASInt>( A->n() );
137 
138  // LDB (leading dimension of B). In our cases,
139  // LDB is always the number of columns of B.
140  PetscBLASInt LDB = static_cast<PetscBLASInt>( B->n() );
141 
142  if (flag == LEFT_MULTIPLY_TRANSPOSE)
143  {
144  transb[0] = 't';
145  N = static_cast<PetscBLASInt>( B->n() );
146  }
147 
148  else if (flag == RIGHT_MULTIPLY_TRANSPOSE)
149  {
150  transa[0] = 't';
151  std::swap(M,K);
152  }
153 
154  // LDC (leading dimension of C). LDC is the
155  // number of columns in the solution matrix.
156  PetscBLASInt LDC = M;
157 
158  // Scalar values to pass to BLAS
159  //
160  // scalar multiplying the whole product AB
161  T alpha = 1.;
162 
163  // scalar multiplying C, which is the original matrix.
164  T beta = 0.;
165 
166  // Storage for the result
167  std::vector<T> result (result_size);
168 
169  // Finally ready to call the BLAS
170  BLASgemm_(transa, transb, &M, &N, &K, pPS(&alpha),
171  pPS(A->get_values().data()), &LDA,
172  pPS(B->get_values().data()), &LDB, pPS(&beta),
173  pPS(result.data()), &LDC);
174 
175  // Update the relevant dimension for this matrix.
176  switch (flag)
177  {
178  case LEFT_MULTIPLY: { this->_m = other.m(); break; }
179  case RIGHT_MULTIPLY: { this->_n = other.n(); break; }
180  case LEFT_MULTIPLY_TRANSPOSE: { this->_m = other.n(); break; }
181  case RIGHT_MULTIPLY_TRANSPOSE: { this->_n = other.m(); break; }
182  default:
183  libmesh_error_msg("Unknown flag selected.");
184  }
185 
186  // Swap my data vector with the result
187  this->_val.swap(result);
188 }
189 
190 #else
191 
192 template<typename T>
194  _BLAS_Multiply_Flag)
195 {
196  libmesh_error_msg("No PETSc-provided BLAS/LAPACK available!");
197 }
198 
199 #endif
200 
201 
202 
203 
204 
205 
206 
207 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
208 
209 template<typename T>
211 {
212  // If this function was called, there better not be any
213  // previous decomposition of the matrix.
214  libmesh_assert_equal_to (this->_decomposition_type, NONE);
215 
216  // The calling sequence for dgetrf is:
217  // dgetrf(M, N, A, lda, ipiv, info)
218 
219  // M (input)
220  // The number of rows of the matrix A. M >= 0.
221  // In C/C++, pass the number of *cols* of A
222  PetscBLASInt M = this->n();
223 
224  // N (input)
225  // The number of columns of the matrix A. N >= 0.
226  // In C/C++, pass the number of *rows* of A
227  PetscBLASInt N = this->m();
228 
229  // A (input/output) double precision array, dimension (LDA,N)
230  // On entry, the M-by-N matrix to be factored.
231  // On exit, the factors L and U from the factorization
232  // A = P*L*U; the unit diagonal elements of L are not stored.
233 
234  // LDA (input)
235  // The leading dimension of the array A. LDA >= max(1,M).
236  PetscBLASInt LDA = M;
237 
238  // ipiv (output) integer array, dimension (min(m,n))
239  // The pivot indices; for 1 <= i <= min(m,n), row i of the
240  // matrix was interchanged with row IPIV(i).
241  // Here, we pass _pivots.data(), a private class member used to store pivots
242  this->_pivots.resize( std::min(M,N) );
243 
244  // info (output)
245  // = 0: successful exit
246  // < 0: if INFO = -i, the i-th argument had an illegal value
247  // > 0: if INFO = i, U(i,i) is exactly zero. The factorization
248  // has been completed, but the factor U is exactly
249  // singular, and division by zero will occur if it is used
250  // to solve a system of equations.
251  PetscBLASInt INFO = 0;
252 
253  // Ready to call the actual factorization routine through PETSc's interface
254  LAPACKgetrf_(&M, &N, pPS(this->_val.data()), &LDA, _pivots.data(),
255  &INFO);
256 
257  // Check return value for errors
258  if (INFO != 0)
259  libmesh_error_msg("INFO=" << INFO << ", Error during Lapack LU factorization!");
260 
261  // Set the flag for LU decomposition
262  this->_decomposition_type = LU_BLAS_LAPACK;
263 }
264 
265 #else
266 
267 template<typename T>
269 {
270  libmesh_error_msg("No PETSc-provided BLAS/LAPACK available!");
271 }
272 
273 #endif
274 
275 
276 
277 template<typename T>
279 {
280  // The calling sequence for dgetrf is:
281  // DGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK, LWORK, INFO )
282 
283  // JOBU (input)
284  // Specifies options for computing all or part of the matrix U:
285  // = 'A': all M columns of U are returned in array U:
286  // = 'S': the first min(m,n) columns of U (the left singular
287  // vectors) are returned in the array U;
288  // = 'O': the first min(m,n) columns of U (the left singular
289  // vectors) are overwritten on the array A;
290  // = 'N': no columns of U (no left singular vectors) are
291  // computed.
292  char JOBU = 'N';
293 
294  // JOBVT (input)
295  // Specifies options for computing all or part of the matrix
296  // V**T:
297  // = 'A': all N rows of V**T are returned in the array VT;
298  // = 'S': the first min(m,n) rows of V**T (the right singular
299  // vectors) are returned in the array VT;
300  // = 'O': the first min(m,n) rows of V**T (the right singular
301  // vectors) are overwritten on the array A;
302  // = 'N': no rows of V**T (no right singular vectors) are
303  // computed.
304  char JOBVT = 'N';
305 
306  std::vector<Real> sigma_val;
307  std::vector<Number> U_val;
308  std::vector<Number> VT_val;
309 
310  _svd_helper(JOBU, JOBVT, sigma_val, U_val, VT_val);
311 
312  // Copy the singular values into sigma, ignore U_val and VT_val
313  sigma.resize(cast_int<unsigned int>(sigma_val.size()));
314  for (auto i : IntRange<int>(0, sigma.size()))
315  sigma(i) = sigma_val[i];
316 }
317 
318 template<typename T>
321  DenseMatrix<Number> & VT)
322 {
323  // The calling sequence for dgetrf is:
324  // DGESVD( JOBU, JOBVT, M, N, A, LDA, S, U, LDU, VT, LDVT, WORK, LWORK, INFO )
325 
326  // JOBU (input)
327  // Specifies options for computing all or part of the matrix U:
328  // = 'A': all M columns of U are returned in array U:
329  // = 'S': the first min(m,n) columns of U (the left singular
330  // vectors) are returned in the array U;
331  // = 'O': the first min(m,n) columns of U (the left singular
332  // vectors) are overwritten on the array A;
333  // = 'N': no columns of U (no left singular vectors) are
334  // computed.
335  char JOBU = 'S';
336 
337  // JOBVT (input)
338  // Specifies options for computing all or part of the matrix
339  // V**T:
340  // = 'A': all N rows of V**T are returned in the array VT;
341  // = 'S': the first min(m,n) rows of V**T (the right singular
342  // vectors) are returned in the array VT;
343  // = 'O': the first min(m,n) rows of V**T (the right singular
344  // vectors) are overwritten on the array A;
345  // = 'N': no rows of V**T (no right singular vectors) are
346  // computed.
347  char JOBVT = 'S';
348 
349  // Note: Lapack is going to compute the singular values of A^T. If
350  // A=U * S * V^T, then A^T = V * S * U^T, which means that the
351  // values returned in the "U_val" array actually correspond to the
352  // entries of the V matrix, and the values returned in the VT_val
353  // array actually correspond to the entries of U^T. Therefore, we
354  // pass VT in the place of U and U in the place of VT below!
355  std::vector<Real> sigma_val;
356  int M = this->n();
357  int N = this->m();
358  int min_MN = (M < N) ? M : N;
359 
360  // Size user-provided storage appropriately. Inside svd_helper:
361  // U_val is sized to (M x min_MN)
362  // VT_val is sized to (min_MN x N)
363  // So, we set up U to have the shape of "VT_val^T", and VT to
364  // have the shape of "U_val^T".
365  //
366  // Finally, since the results are stored in column-major order by
367  // Lapack, but we actually want the transpose of what Lapack
368  // returns, this means (conveniently) that we don't even have to
369  // copy anything after the call to _svd_helper, it should already be
370  // in the correct order!
371  U.resize(N, min_MN);
372  VT.resize(min_MN, M);
373 
374  _svd_helper(JOBU, JOBVT, sigma_val, VT.get_values(), U.get_values());
375 
376  // Copy the singular values into sigma.
377  sigma.resize(cast_int<unsigned int>(sigma_val.size()));
378  for (auto i : IntRange<int>(0, sigma.size()))
379  sigma(i) = sigma_val[i];
380 }
381 
382 #if (LIBMESH_HAVE_PETSC)
383 
384 template<typename T>
386  char JOBVT,
387  std::vector<Real> & sigma_val,
388  std::vector<Number> & U_val,
389  std::vector<Number> & VT_val)
390 {
391 
392  // M (input)
393  // The number of rows of the matrix A. M >= 0.
394  // In C/C++, pass the number of *cols* of A
395  PetscBLASInt M = this->n();
396 
397  // N (input)
398  // The number of columns of the matrix A. N >= 0.
399  // In C/C++, pass the number of *rows* of A
400  PetscBLASInt N = this->m();
401 
402  PetscBLASInt min_MN = (M < N) ? M : N;
403  PetscBLASInt max_MN = (M > N) ? M : N;
404 
405  // A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
406  // On entry, the M-by-N matrix A.
407  // On exit,
408  // if JOBU = 'O', A is overwritten with the first min(m,n)
409  // columns of U (the left singular vectors,
410  // stored columnwise);
411  // if JOBVT = 'O', A is overwritten with the first min(m,n)
412  // rows of V**T (the right singular vectors,
413  // stored rowwise);
414  // if JOBU != 'O' and JOBVT != 'O', the contents of A are destroyed.
415 
416  // LDA (input)
417  // The leading dimension of the array A. LDA >= max(1,M).
418  PetscBLASInt LDA = M;
419 
420  // S (output) DOUBLE PRECISION array, dimension (min(M,N))
421  // The singular values of A, sorted so that S(i) >= S(i+1).
422  sigma_val.resize( min_MN );
423 
424  // LDU (input)
425  // The leading dimension of the array U. LDU >= 1; if
426  // JOBU = 'S' or 'A', LDU >= M.
427  PetscBLASInt LDU = M;
428 
429  // U (output) DOUBLE PRECISION array, dimension (LDU,UCOL)
430  // (LDU,M) if JOBU = 'A' or (LDU,min(M,N)) if JOBU = 'S'.
431  // If JOBU = 'A', U contains the M-by-M orthogonal matrix U;
432  // if JOBU = 'S', U contains the first min(m,n) columns of U
433  // (the left singular vectors, stored columnwise);
434  // if JOBU = 'N' or 'O', U is not referenced.
435  if (JOBU == 'S')
436  U_val.resize( LDU*min_MN );
437  else
438  U_val.resize( LDU*M );
439 
440  // LDVT (input)
441  // The leading dimension of the array VT. LDVT >= 1; if
442  // JOBVT = 'A', LDVT >= N; if JOBVT = 'S', LDVT >= min(M,N).
443  PetscBLASInt LDVT = N;
444  if (JOBVT == 'S')
445  LDVT = min_MN;
446 
447  // VT (output) DOUBLE PRECISION array, dimension (LDVT,N)
448  // If JOBVT = 'A', VT contains the N-by-N orthogonal matrix
449  // V**T;
450  // if JOBVT = 'S', VT contains the first min(m,n) rows of
451  // V**T (the right singular vectors, stored rowwise);
452  // if JOBVT = 'N' or 'O', VT is not referenced.
453  VT_val.resize( LDVT*N );
454 
455  // LWORK (input)
456  // The dimension of the array WORK.
457  // LWORK >= MAX(1,3*MIN(M,N)+MAX(M,N),5*MIN(M,N)).
458  // For good performance, LWORK should generally be larger.
459  //
460  // If LWORK = -1, then a workspace query is assumed; the routine
461  // only calculates the optimal size of the WORK array, returns
462  // this value as the first entry of the WORK array, and no error
463  // message related to LWORK is issued by XERBLA.
464  PetscBLASInt larger = (3*min_MN+max_MN > 5*min_MN) ? 3*min_MN+max_MN : 5*min_MN;
465  PetscBLASInt LWORK = (larger > 1) ? larger : 1;
466 
467 
468  // WORK (workspace/output) DOUBLE PRECISION array, dimension (MAX(1,LWORK))
469  // On exit, if INFO = 0, WORK(1) returns the optimal LWORK;
470  // if INFO > 0, WORK(2:MIN(M,N)) contains the unconverged
471  // superdiagonal elements of an upper bidiagonal matrix B
472  // whose diagonal is in S (not necessarily sorted). B
473  // satisfies A = U * B * VT, so it has the same singular values
474  // as A, and singular vectors related by U and VT.
475  std::vector<Number> WORK( LWORK );
476 
477  // INFO (output)
478  // = 0: successful exit.
479  // < 0: if INFO = -i, the i-th argument had an illegal value.
480  // > 0: if DBDSQR did not converge, INFO specifies how many
481  // superdiagonals of an intermediate bidiagonal form B
482  // did not converge to zero. See the description of WORK
483  // above for details.
484  PetscBLASInt INFO = 0;
485 
486  // Ready to call the actual factorization routine through PETSc's interface.
487 #ifdef LIBMESH_USE_REAL_NUMBERS
488  // Note that the call to LAPACKgesvd_ may modify _val
489  LAPACKgesvd_(&JOBU, &JOBVT, &M, &N, pPS(_val.data()), &LDA,
490  pPS(sigma_val.data()), pPS(U_val.data()), &LDU,
491  pPS(VT_val.data()), &LDVT, pPS(WORK.data()), &LWORK,
492  &INFO);
493 #else
494  // When we have LIBMESH_USE_COMPLEX_NUMBERS then we must pass an array of Complex
495  // numbers to LAPACKgesvd_, but _val may contain Reals so we copy to Number below to
496  // handle both the real-valued and complex-valued cases.
497  std::vector<Number> val_copy(_val.size());
498  for (auto i : IntRange<int>(0, _val.size()))
499  val_copy[i] = _val[i];
500 
501  std::vector<Real> RWORK(5 * min_MN);
502  LAPACKgesvd_(&JOBU, &JOBVT, &M, &N, val_copy.data(), &LDA, sigma_val.data(), U_val.data(),
503  &LDU, VT_val.data(), &LDVT, WORK.data(), &LWORK, RWORK.data(), &INFO);
504 #endif
505 
506  // Check return value for errors
507  if (INFO != 0)
508  libmesh_error_msg("INFO=" << INFO << ", Error during Lapack SVD calculation!");
509 }
510 
511 
512 #else
513 
514 template<typename T>
515 void DenseMatrix<T>::_svd_helper (char,
516  char,
517  std::vector<Real> &,
518  std::vector<Number> &,
519  std::vector<Number> &)
520 {
521  libmesh_error_msg("No PETSc-provided BLAS/LAPACK available!");
522 }
523 
524 #endif
525 
526 
527 
528 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
529 #if !PETSC_VERSION_LESS_THAN(3,1,0)
530 
531 template<typename T>
533  DenseVector<T> & x,
534  Real rcond) const
535 {
536  // Since BLAS is expecting column-major storage, we first need to
537  // make a transposed copy of *this, then pass it to the gelss
538  // routine instead of the original. This extra copy is kind of a
539  // bummer, it might be better if we could use the full SVD to
540  // compute the least-squares solution instead... Note that it isn't
541  // completely terrible either, since A_trans gets overwritten by
542  // Lapack, and we usually would end up making a copy of A outside
543  // the function call anyway.
544  DenseMatrix<T> A_trans;
545  this->get_transpose(A_trans);
546 
547  // M
548  // The number of rows of the input matrix. M >= 0.
549  // This is actually the number of *columns* of A_trans.
550  PetscBLASInt M = A_trans.n();
551 
552  // N
553  // The number of columns of the matrix A. N >= 0.
554  // This is actually the number of *rows* of A_trans.
555  PetscBLASInt N = A_trans.m();
556 
557  // We'll use the min and max of (M,N) several times below.
558  PetscBLASInt max_MN = std::max(M,N);
559  PetscBLASInt min_MN = std::min(M,N);
560 
561  // NRHS
562  // The number of right hand sides, i.e., the number of columns
563  // of the matrices B and X. NRHS >= 0.
564  // This could later be generalized to solve for multiple right-hand
565  // sides...
566  PetscBLASInt NRHS = 1;
567 
568  // A is double precision array, dimension (LDA,N)
569  // On entry, the M-by-N matrix A.
570  // On exit, the first min(m,n) rows of A are overwritten with
571  // its right singular vectors, stored rowwise.
572  //
573  // The data vector that will be passed to Lapack.
574  std::vector<T> & A_trans_vals = A_trans.get_values();
575 
576  // LDA
577  // The leading dimension of the array A. LDA >= max(1,M).
578  PetscBLASInt LDA = M;
579 
580  // B is double precision array, dimension (LDB,NRHS)
581  // On entry, the M-by-NRHS right hand side matrix B.
582  // On exit, B is overwritten by the N-by-NRHS solution
583  // matrix X. If m >= n and RANK = n, the residual
584  // sum-of-squares for the solution in the i-th column is given
585  // by the sum of squares of elements n+1:m in that column.
586  //
587  // Since we don't want the user's rhs vector to be overwritten by
588  // the solution, we copy the rhs values into the solution vector "x"
589  // now. x needs to be long enough to hold both the (Nx1) solution
590  // vector or the (Mx1) rhs, so size it to the max of those.
591  x.resize(max_MN);
592  for (auto i : IntRange<int>(0, rhs.size()))
593  x(i) = rhs(i);
594 
595  // Make the syntax below simpler by grabbing a reference to this array.
596  std::vector<T> & B = x.get_values();
597 
598  // LDB
599  // The leading dimension of the array B. LDB >= max(1,max(M,N)).
600  PetscBLASInt LDB = x.size();
601 
602  // S is double precision array, dimension (min(M,N))
603  // The singular values of A in decreasing order.
604  // The condition number of A in the 2-norm = S(1)/S(min(m,n)).
605  std::vector<T> S(min_MN);
606 
607  // RCOND
608  // Used to determine the effective rank of A. Singular values
609  // S(i) <= RCOND*S(1) are treated as zero. If RCOND < 0, machine
610  // precision is used instead.
611  PetscScalar RCOND = rcond;
612 
613  // RANK
614  // The effective rank of A, i.e., the number of singular values
615  // which are greater than RCOND*S(1).
616  PetscBLASInt RANK = 0;
617 
618  // LWORK
619  // The dimension of the array WORK. LWORK >= 1, and also:
620  // LWORK >= 3*min(M,N) + max( 2*min(M,N), max(M,N), NRHS )
621  // For good performance, LWORK should generally be larger.
622  //
623  // If LWORK = -1, then a workspace query is assumed; the routine
624  // only calculates the optimal size of the WORK array, returns
625  // this value as the first entry of the WORK array, and no error
626  // message related to LWORK is issued by XERBLA.
627  //
628  // The factor of 3/2 is arbitrary and is used to satisfy the "should
629  // generally be larger" clause.
630  PetscBLASInt LWORK = (3*min_MN + std::max(2*min_MN, std::max(max_MN, NRHS))) * 3/2;
631 
632  // WORK is double precision array, dimension (MAX(1,LWORK))
633  // On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
634  std::vector<T> WORK(LWORK);
635 
636  // INFO
637  // = 0: successful exit
638  // < 0: if INFO = -i, the i-th argument had an illegal value.
639  // > 0: the algorithm for computing the SVD failed to converge;
640  // if INFO = i, i off-diagonal elements of an intermediate
641  // bidiagonal form did not converge to zero.
642  PetscBLASInt INFO = 0;
643 
644  // LAPACKgelss_(const PetscBLASInt *, // M
645  // const PetscBLASInt *, // N
646  // const PetscBLASInt *, // NRHS
647  // PetscScalar *, // A
648  // const PetscBLASInt *, // LDA
649  // PetscScalar *, // B
650  // const PetscBLASInt *, // LDB
651  // PetscReal *, // S(out) = singular values of A in increasing order
652  // const PetscReal *, // RCOND = tolerance for singular values
653  // PetscBLASInt *, // RANK(out) = number of "non-zero" singular values
654  // PetscScalar *, // WORK
655  // const PetscBLASInt *, // LWORK
656  // PetscBLASInt *); // INFO
657  LAPACKgelss_(&M, &N, &NRHS, pPS(A_trans_vals.data()), &LDA,
658  pPS(B.data()), &LDB, pPS(S.data()), &RCOND, &RANK,
659  pPS(WORK.data()), &LWORK, &INFO);
660 
661  // Check for errors in the Lapack call
662  if (INFO < 0)
663  libmesh_error_msg("Error, argument " << -INFO << " to LAPACKgelss_ had an illegal value.");
664  if (INFO > 0)
665  libmesh_error_msg("The algorithm for computing the SVD failed to converge!");
666 
667  // Debugging: print singular values and information about condition number:
668  // libMesh::err << "RCOND=" << RCOND << std::endl;
669  // libMesh::err << "Singular values: " << std::endl;
670  // for (auto i : index_range(S))
671  // libMesh::err << S[i] << std::endl;
672  // libMesh::err << "The condition number of A is approximately: " << S[0]/S.back() << std::endl;
673 
674  // Lapack has already written the solution into B, but it will be
675  // the wrong size for non-square problems, so we need to resize it
676  // correctly. The size of the solution vector should be the number
677  // of columns of the original A matrix. Unfortunately, resizing a
678  // DenseVector currently also zeros it out (unlike a std::vector) so
679  // we'll resize the underlying storage directly (the size is not
680  // stored independently elsewhere).
681  x.get_values().resize(this->n());
682 }
683 
684 #else
685 
686 template<typename T>
688  DenseVector<T> & /*x*/,
689  Real /*rcond*/) const
690 {
691  libmesh_error_msg("svd_solve() requires PETSc >= 3.1!");
692 }
693 
694 #endif // !PETSC_VERSION_LESS_THAN(3,1,0)
695 
696 #else
697 template<typename T>
698 void DenseMatrix<T>::_svd_solve_lapack(const DenseVector<T>& /*rhs*/,
699  DenseVector<T> & /*x*/,
700  Real /*rcond*/) const
701 {
702  libmesh_not_implemented();
703 }
704 #endif // (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
705 
706 
707 
708 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
709 
710 template<typename T>
712  DenseVector<T> & lambda_imag,
713  DenseMatrix<T> * VL,
714  DenseMatrix<T> * VR)
715 {
716  // This algorithm only works for square matrices, so verify this up front.
717  if (this->m() != this->n())
718  libmesh_error_msg("Can only compute eigen-decompositions for square matrices.");
719 
720  // If the user requests left or right eigenvectors, we have to make
721  // sure and pass the transpose of this matrix to Lapack, otherwise
722  // it will compute the inverse transpose of what we are
723  // after... since we know the matrix is square, we can just swap
724  // entries in place. If the user does not request eigenvectors, we
725  // can skip this extra step, since the eigenvalues for A and A^T are
726  // the same.
727  if (VL || VR)
728  {
729  for (auto i : IntRange<int>(0, this->_m))
730  for (auto j : IntRange<int>(0, i))
731  std::swap((*this)(i,j), (*this)(j,i));
732  }
733 
734  // The calling sequence for dgeev is:
735  // DGEEV (character JOBVL,
736  // character JOBVR,
737  // integer N,
738  // double precision, dimension( lda, * ) A,
739  // integer LDA,
740  // double precision, dimension( * ) WR,
741  // double precision, dimension( * ) WI,
742  // double precision, dimension( ldvl, * ) VL,
743  // integer LDVL,
744  // double precision, dimension( ldvr, * ) VR,
745  // integer LDVR,
746  // double precision, dimension( * ) WORK,
747  // integer LWORK,
748  // integer INFO)
749 
750  // JOBVL (input)
751  // = 'N': left eigenvectors of A are not computed;
752  // = 'V': left eigenvectors of A are computed.
753  char JOBVL = VL ? 'V' : 'N';
754 
755  // JOBVR (input)
756  // = 'N': right eigenvectors of A are not computed;
757  // = 'V': right eigenvectors of A are computed.
758  char JOBVR = VR ? 'V' : 'N';
759 
760  // N (input)
761  // The number of rows/cols of the matrix A. N >= 0.
762  PetscBLASInt N = this->m();
763 
764  // A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
765  // On entry, the N-by-N matrix A.
766  // On exit, A has been overwritten.
767 
768  // LDA (input)
769  // The leading dimension of the array A. LDA >= max(1,N).
770  PetscBLASInt LDA = N;
771 
772  // WR (output) double precision array, dimension (N)
773  // WI (output) double precision array, dimension (N)
774  // WR and WI contain the real and imaginary parts,
775  // respectively, of the computed eigenvalues. Complex
776  // conjugate pairs of eigenvalues appear consecutively
777  // with the eigenvalue having the positive imaginary part
778  // first.
779  lambda_real.resize(N);
780  lambda_imag.resize(N);
781 
782  // VL (output) double precision array, dimension (LDVL,N)
783  // If JOBVL = 'V', the left eigenvectors u(j) are stored one
784  // after another in the columns of VL, in the same order
785  // as their eigenvalues.
786  // If JOBVL = 'N', VL is not referenced.
787  // If the j-th eigenvalue is real, then u(j) = VL(:,j),
788  // the j-th column of VL.
789  // If the j-th and (j+1)-st eigenvalues form a complex
790  // conjugate pair, then u(j) = VL(:,j) + i*VL(:,j+1) and
791  // u(j+1) = VL(:,j) - i*VL(:,j+1).
792  // Will be set below if needed.
793 
794  // LDVL (input)
795  // The leading dimension of the array VL. LDVL >= 1; if
796  // JOBVL = 'V', LDVL >= N.
797  PetscBLASInt LDVL = VL ? N : 1;
798 
799  // VR (output) DOUBLE PRECISION array, dimension (LDVR,N)
800  // If JOBVR = 'V', the right eigenvectors v(j) are stored one
801  // after another in the columns of VR, in the same order
802  // as their eigenvalues.
803  // If JOBVR = 'N', VR is not referenced.
804  // If the j-th eigenvalue is real, then v(j) = VR(:,j),
805  // the j-th column of VR.
806  // If the j-th and (j+1)-st eigenvalues form a complex
807  // conjugate pair, then v(j) = VR(:,j) + i*VR(:,j+1) and
808  // v(j+1) = VR(:,j) - i*VR(:,j+1).
809  // Will be set below if needed.
810 
811  // LDVR (input)
812  // The leading dimension of the array VR. LDVR >= 1; if
813  // JOBVR = 'V', LDVR >= N.
814  PetscBLASInt LDVR = VR ? N : 1;
815 
816  // WORK (workspace/output) double precision array, dimension (MAX(1,LWORK))
817  // On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
818  //
819  // LWORK (input)
820  // The dimension of the array WORK. LWORK >= max(1,3*N), and
821  // if JOBVL = 'V' or JOBVR = 'V', LWORK >= 4*N. For good
822  // performance, LWORK must generally be larger.
823  //
824  // If LWORK = -1, then a workspace query is assumed; the routine
825  // only calculates the optimal size of the WORK array, returns
826  // this value as the first entry of the WORK array, and no error
827  // message related to LWORK is issued by XERBLA.
828  PetscBLASInt LWORK = (VR || VL) ? 4*N : 3*N;
829  std::vector<T> WORK(LWORK);
830 
831  // INFO (output)
832  // = 0: successful exit
833  // < 0: if INFO = -i, the i-th argument had an illegal value.
834  // > 0: if INFO = i, the QR algorithm failed to compute all the
835  // eigenvalues, and no eigenvectors or condition numbers
836  // have been computed; elements 1:ILO-1 and i+1:N of WR
837  // and WI contain eigenvalues which have converged.
838  PetscBLASInt INFO = 0;
839 
840  // Get references to raw data
841  std::vector<T> & lambda_real_val = lambda_real.get_values();
842  std::vector<T> & lambda_imag_val = lambda_imag.get_values();
843 
844  // Set up eigenvector storage if necessary.
845  T * VR_ptr = nullptr;
846  if (VR)
847  {
848  VR->resize(N, N);
849  VR_ptr = VR->get_values().data();
850  }
851 
852  T * VL_ptr = nullptr;
853  if (VL)
854  {
855  VL->resize(N, N);
856  VL_ptr = VL->get_values().data();
857  }
858 
859  // Ready to call the Lapack routine through PETSc's interface
860  LAPACKgeev_(&JOBVL,
861  &JOBVR,
862  &N,
863  pPS(_val.data()),
864  &LDA,
865  pPS(lambda_real_val.data()),
866  pPS(lambda_imag_val.data()),
867  pPS(VL_ptr),
868  &LDVL,
869  pPS(VR_ptr),
870  &LDVR,
871  pPS(WORK.data()),
872  &LWORK,
873  &INFO);
874 
875  // Check return value for errors
876  if (INFO != 0)
877  libmesh_error_msg("INFO=" << INFO << ", Error during Lapack eigenvalue calculation!");
878 
879  // If the user requested either right or left eigenvectors, LAPACK
880  // has now computed the transpose of the desired matrix, i.e. V^T
881  // instead of V. We could leave this up to user code to handle, but
882  // rather than risking getting very unexpected results, we'll just
883  // transpose it in place before handing it back.
884  if (VR)
885  {
886  for (auto i : IntRange<int>(0, N))
887  for (auto j : IntRange<int>(0, i))
888  std::swap((*VR)(i,j), (*VR)(j,i));
889  }
890 
891  if (VL)
892  {
893  for (auto i : IntRange<int>(0, N))
894  for (auto j : IntRange<int>(0, i))
895  std::swap((*VL)(i,j), (*VL)(j,i));
896  }
897 }
898 
899 #else
900 
901 template<typename T>
903  DenseVector<T> &,
904  DenseMatrix<T> *,
905  DenseMatrix<T> *)
906 {
907  libmesh_error_msg("_evd_lapack is currently only available when LIBMESH_USE_REAL_NUMBERS is defined!");
908 }
909 
910 #endif
911 
912 
913 
914 
915 
916 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
917 
918 template<typename T>
920  DenseVector<T> & x)
921 {
922  // The calling sequence for getrs is:
923  // dgetrs(TRANS, N, NRHS, A, LDA, IPIV, B, LDB, INFO)
924 
925  // trans (input)
926  // 'n' for no transpose, 't' for transpose
927  char TRANS[] = "t";
928 
929  // N (input)
930  // The order of the matrix A. N >= 0.
931  PetscBLASInt N = this->m();
932 
933 
934  // NRHS (input)
935  // The number of right hand sides, i.e., the number of columns
936  // of the matrix B. NRHS >= 0.
937  PetscBLASInt NRHS = 1;
938 
939  // A (input) double precision array, dimension (LDA,N)
940  // The factors L and U from the factorization A = P*L*U
941  // as computed by dgetrf.
942 
943  // LDA (input)
944  // The leading dimension of the array A. LDA >= max(1,N).
945  PetscBLASInt LDA = N;
946 
947  // ipiv (input) int array, dimension (N)
948  // The pivot indices from DGETRF; for 1<=i<=N, row i of the
949  // matrix was interchanged with row IPIV(i).
950  // Here, we pass _pivots.data() which was computed in _lu_decompose_lapack
951 
952  // B (input/output) double precision array, dimension (LDB,NRHS)
953  // On entry, the right hand side matrix B.
954  // On exit, the solution matrix X.
955  // Here, we pass a copy of the rhs vector's data array in x, so that the
956  // passed right-hand side b is unmodified. I don't see a way around this
957  // copy if we want to maintain an unmodified rhs in LibMesh.
958  x = b;
959  std::vector<T> & x_vec = x.get_values();
960 
961  // We can avoid the copy if we don't care about overwriting the RHS: just
962  // pass b to the Lapack routine and then swap with x before exiting
963  // std::vector<T> & x_vec = b.get_values();
964 
965  // LDB (input)
966  // The leading dimension of the array B. LDB >= max(1,N).
967  PetscBLASInt LDB = N;
968 
969  // INFO (output)
970  // = 0: successful exit
971  // < 0: if INFO = -i, the i-th argument had an illegal value
972  PetscBLASInt INFO = 0;
973 
974  // Finally, ready to call the Lapack getrs function
975  LAPACKgetrs_(TRANS, &N, &NRHS, pPS(_val.data()), &LDA,
976  _pivots.data(), pPS(x_vec.data()), &LDB, &INFO);
977 
978  // Check return value for errors
979  if (INFO != 0)
980  libmesh_error_msg("INFO=" << INFO << ", Error during Lapack LU solve!");
981 
982  // Don't do this if you already made a copy of b above
983  // Swap b and x. The solution will then be in x, and whatever was originally
984  // in x, maybe garbage, maybe nothing, will be in b.
985  // FIXME: Rewrite the LU and Cholesky solves to just take one input, and overwrite
986  // the input. This *should* make user code simpler, as they don't have to create
987  // an extra vector just to pass it in to the solve function!
988  // b.swap(x);
989 }
990 
991 #else
992 
993 template<typename T>
995  DenseVector<T> &)
996 {
997  libmesh_error_msg("No PETSc-provided BLAS/LAPACK available!");
998 }
999 
1000 #endif
1001 
1002 
1003 
1004 
1005 
1006 #if (LIBMESH_HAVE_PETSC && LIBMESH_USE_REAL_NUMBERS)
1007 
1008 template<typename T>
1010  T beta,
1011  DenseVector<T> & dest,
1012  const DenseVector<T> & arg,
1013  bool trans) const
1014 {
1015  // Ensure that dest and arg sizes are compatible
1016  if (!trans)
1017  {
1018  // dest ~ A * arg
1019  // (mx1) (mxn) * (nx1)
1020  if ((dest.size() != this->m()) || (arg.size() != this->n()))
1021  libmesh_error_msg("Improper input argument sizes!");
1022  }
1023 
1024  else // trans == true
1025  {
1026  // Ensure that dest and arg are proper size
1027  // dest ~ A^T * arg
1028  // (nx1) (nxm) * (mx1)
1029  if ((dest.size() != this->n()) || (arg.size() != this->m()))
1030  libmesh_error_msg("Improper input argument sizes!");
1031  }
1032 
1033  // Calling sequence for dgemv:
1034  //
1035  // dgemv(TRANS,M,N,ALPHA,A,LDA,X,INCX,BETA,Y,INCY)
1036 
1037  // TRANS (input)
1038  // 't' for transpose, 'n' for non-transpose multiply
1039  // We store everything in row-major order, so pass the transpose flag for
1040  // non-transposed matvecs and the 'n' flag for transposed matvecs
1041  char TRANS[] = "t";
1042  if (trans)
1043  TRANS[0] = 'n';
1044 
1045  // M (input)
1046  // On entry, M specifies the number of rows of the matrix A.
1047  // In C/C++, pass the number of *cols* of A
1048  PetscBLASInt M = this->n();
1049 
1050  // N (input)
1051  // On entry, N specifies the number of columns of the matrix A.
1052  // In C/C++, pass the number of *rows* of A
1053  PetscBLASInt N = this->m();
1054 
1055  // ALPHA (input)
1056  // The scalar constant passed to this function
1057 
1058  // A (input) double precision array of DIMENSION ( LDA, n ).
1059  // Before entry, the leading m by n part of the array A must
1060  // contain the matrix of coefficients.
1061  // The matrix, *this. Note that _matvec_blas is called from
1062  // a const function, vector_mult(), and so we have made this function const
1063  // as well. Since BLAS knows nothing about const, we have to cast it away
1064  // now.
1065  DenseMatrix<T> & a_ref = const_cast<DenseMatrix<T> &> ( *this );
1066  std::vector<T> & a = a_ref.get_values();
1067 
1068  // LDA (input)
1069  // On entry, LDA specifies the first dimension of A as declared
1070  // in the calling (sub) program. LDA must be at least
1071  // max( 1, m ).
1072  PetscBLASInt LDA = M;
1073 
1074  // X (input) double precision array of DIMENSION at least
1075  // ( 1 + ( n - 1 )*abs( INCX ) ) when TRANS = 'N' or 'n'
1076  // and at least
1077  // ( 1 + ( m - 1 )*abs( INCX ) ) otherwise.
1078  // Before entry, the incremented array X must contain the
1079  // vector x.
1080  // Here, we must cast away the const-ness of "arg" since BLAS knows
1081  // nothing about const
1082  DenseVector<T> & x_ref = const_cast<DenseVector<T> &> ( arg );
1083  std::vector<T> & x = x_ref.get_values();
1084 
1085  // INCX (input)
1086  // On entry, INCX specifies the increment for the elements of
1087  // X. INCX must not be zero.
1088  PetscBLASInt INCX = 1;
1089 
1090  // BETA (input)
1091  // On entry, BETA specifies the scalar beta. When BETA is
1092  // supplied as zero then Y need not be set on input.
1093  // The second scalar constant passed to this function
1094 
1095  // Y (input) double precision array of DIMENSION at least
1096  // ( 1 + ( m - 1 )*abs( INCY ) ) when TRANS = 'N' or 'n'
1097  // and at least
1098  // ( 1 + ( n - 1 )*abs( INCY ) ) otherwise.
1099  // Before entry with BETA non-zero, the incremented array Y
1100  // must contain the vector y. On exit, Y is overwritten by the
1101  // updated vector y.
1102  // The input vector "dest"
1103  std::vector<T> & y = dest.get_values();
1104 
1105  // INCY (input)
1106  // On entry, INCY specifies the increment for the elements of
1107  // Y. INCY must not be zero.
1108  PetscBLASInt INCY = 1;
1109 
1110  // Finally, ready to call the BLAS function
1111  BLASgemv_(TRANS, &M, &N, pPS(&alpha), pPS(a.data()), &LDA,
1112  pPS(x.data()), &INCX, pPS(&beta), pPS(y.data()), &INCY);
1113 }
1114 
1115 
1116 #else
1117 
1118 
1119 template<typename T>
1121  T,
1122  DenseVector<T> &,
1123  const DenseVector<T> &,
1124  bool) const
1125 {
1126  libmesh_error_msg("No PETSc-provided BLAS/LAPACK available!");
1127 }
1128 
1129 
1130 #endif
1131 
1132 
1133 //--------------------------------------------------------------
1134 // Explicit instantiations
1135 template void DenseMatrix<Real>::_multiply_blas(const DenseMatrixBase<Real> &, _BLAS_Multiply_Flag);
1137 template void DenseMatrix<Real>::_lu_back_substitute_lapack(const DenseVector<Real> &,
1138  DenseVector<Real> &);
1140  Real,
1141  DenseVector<Real> &,
1142  const DenseVector<Real> &,
1143  bool) const;
1144 template void DenseMatrix<Real>::_svd_lapack(DenseVector<Real> &);
1145 template void DenseMatrix<Real>::_svd_lapack(DenseVector<Real> &,
1146  DenseMatrix<Number> &,
1147  DenseMatrix<Number> &);
1148 template void DenseMatrix<Real>::_svd_helper (char,
1149  char,
1150  std::vector<Real> &,
1151  std::vector<Number> &,
1152  std::vector<Number> &);
1153 template void DenseMatrix<Real>::_svd_solve_lapack (const DenseVector<Real> &, DenseVector<Real> &, Real) const;
1154 template void DenseMatrix<Real>::_evd_lapack(DenseVector<Real> &,
1155  DenseVector<Real> &,
1156  DenseMatrix<Real> *,
1157  DenseMatrix<Real> *);
1158 
1159 #if !(LIBMESH_USE_REAL_NUMBERS)
1160 template void DenseMatrix<Number>::_multiply_blas(const DenseMatrixBase<Number> &, _BLAS_Multiply_Flag);
1162 template void DenseMatrix<Number>::_lu_back_substitute_lapack(const DenseVector<Number> &,
1163  DenseVector<Number> &);
1165  Number,
1166  DenseVector<Number> &,
1167  const DenseVector<Number> &,
1168  bool) const;
1169 template void DenseMatrix<Number>::_svd_lapack(DenseVector<Real> &);
1170 template void DenseMatrix<Number>::_svd_lapack(DenseVector<Real> &,
1171  DenseMatrix<Number> &,
1172  DenseMatrix<Number> &);
1173 template void DenseMatrix<Number>::_svd_helper (char,
1174  char,
1175  std::vector<Real> &,
1176  std::vector<Number> &,
1177  std::vector<Number> &);
1178 template void DenseMatrix<Number>::_svd_solve_lapack (const DenseVector<Number> &, DenseVector<Number> &, Real) const;
1179 template void DenseMatrix<Number>::_evd_lapack(DenseVector<Number> &,
1180  DenseVector<Number> &,
1181  DenseMatrix<Number> *,
1182  DenseMatrix<Number> *);
1183 
1184 #endif
1185 
1186 } // namespace libMesh
libMesh::DenseMatrix::_svd_lapack
void _svd_lapack(DenseVector< Real > &sigma)
Computes an SVD of the matrix using the Lapack routine "getsvd".
Definition: dense_matrix_blas_lapack.C:278
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::DenseMatrix::_svd_solve_lapack
void _svd_solve_lapack(const DenseVector< T > &rhs, DenseVector< T > &x, Real rcond) const
Called by svd_solve(rhs).
Definition: dense_matrix_blas_lapack.C:532
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
B
Definition: assembly.h:38
libMesh::DenseMatrix::_svd_helper
void _svd_helper(char JOBU, char JOBVT, std::vector< Real > &sigma_val, std::vector< Number > &U_val, std::vector< Number > &VT_val)
Helper function that actually performs the SVD.
Definition: dense_matrix_blas_lapack.C:385
libMesh::pPS
PetscScalar * pPS(T *ptr)
Definition: petsc_macro.h:174
libMesh::DenseMatrix
Defines a dense matrix for use in Finite Element-type computations.
Definition: dof_map.h:73
libMesh::DenseMatrixBase::n
unsigned int n() const
Definition: dense_matrix_base.h:109
libMesh::DenseMatrix::get_values
std::vector< T > & get_values()
Definition: dense_matrix.h:371
libMesh::DenseMatrix::resize
void resize(const unsigned int new_m, const unsigned int new_n)
Resize the matrix.
Definition: dense_matrix.h:822
libMesh::DenseMatrixBase::m
unsigned int m() const
Definition: dense_matrix_base.h:104
libMesh::IntRange
The IntRange templated class is intended to make it easy to loop over integers which are indices of a...
Definition: int_range.h:53
libMesh::DenseMatrix::_matvec_blas
void _matvec_blas(T alpha, T beta, DenseVector< T > &dest, const DenseVector< T > &arg, bool trans=false) const
Uses the BLAS GEMV function (through PETSc) to compute.
Definition: dense_matrix_blas_lapack.C:1009
libMesh::DenseMatrixBase
Defines an abstract dense matrix base class for use in Finite Element-type computations.
Definition: dense_matrix_base.h:46
A
static PetscErrorCode Mat * A
Definition: petscdmlibmeshimpl.C:1026
libMesh::DenseVector::size
virtual unsigned int size() const override
Definition: dense_vector.h:92
libMesh::DenseMatrix< Real >::_BLAS_Multiply_Flag
_BLAS_Multiply_Flag
Enumeration used to determine the behavior of the _multiply_blas function.
Definition: dense_matrix.h:618
libMesh::DenseMatrix::_lu_back_substitute_lapack
void _lu_back_substitute_lapack(const DenseVector< T > &b, DenseVector< T > &x)
Companion function to _lu_decompose_lapack().
Definition: dense_matrix_blas_lapack.C:919
libMesh::DenseVector::resize
void resize(const unsigned int n)
Resize the vector.
Definition: dense_vector.h:355
libMesh::DenseMatrix::_lu_decompose_lapack
void _lu_decompose_lapack()
Computes an LU factorization of the matrix using the Lapack routine "getrf".
Definition: dense_matrix_blas_lapack.C:210
swap
void swap(Iterator &lhs, Iterator &rhs)
swap, used to implement op=
Definition: variant_filter_iterator.h:478
libMesh::DenseMatrix::_multiply_blas
void _multiply_blas(const DenseMatrixBase< T > &other, _BLAS_Multiply_Flag flag)
The _multiply_blas function computes A <- op(A) * op(B) using BLAS gemm function.
Definition: dense_matrix_blas_lapack.C:37
libMesh::DenseVector::get_values
std::vector< T > & get_values()
Definition: dense_vector.h:256
libMesh::DenseMatrix::_evd_lapack
void _evd_lapack(DenseVector< T > &lambda_real, DenseVector< T > &lambda_imag, DenseMatrix< T > *VL=nullptr, DenseMatrix< T > *VR=nullptr)
Computes the eigenvalues of the matrix using the Lapack routine "DGEEV".
Definition: dense_matrix_blas_lapack.C:711
libMesh::Real
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Definition: libmesh_common.h:121
libMesh::DenseVector
Defines a dense vector for use in Finite Element-type computations.
Definition: meshless_interpolation_function.h:39