00001 /* Ergo, version 3.7, a program for linear scaling electronic structure 00002 * calculations. 00003 * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, 00004 * and Anastasia Kruchinina. 00005 * 00006 * This program is free software: you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation, either version 3 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program. If not, see <http://www.gnu.org/licenses/>. 00018 * 00019 * Primary academic reference: 00020 * Ergo: An open-source program for linear-scaling electronic structure 00021 * calculations, 00022 * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia 00023 * Kruchinina, 00024 * SoftwareX 7, 107 (2018), 00025 * <http://dx.doi.org/10.1016/j.softx.2018.03.005> 00026 * 00027 * For further information about Ergo, see <http://www.ergoscf.org>. 00028 */ 00029 00030 /* This file belongs to the template_lapack part of the Ergo source 00031 * code. The source files in the template_lapack directory are modified 00032 * versions of files originally distributed as CLAPACK, see the 00033 * Copyright/license notice in the file template_lapack/COPYING. 00034 */ 00035 00036 00037 #ifndef TEMPLATE_LAPACK_GESV_HEADER 00038 #define TEMPLATE_LAPACK_GESV_HEADER 00039 00040 00041 template<class Treal> 00042 int template_lapack_gesv(const integer *n, const integer *nrhs, Treal *a, const integer 00043 *lda, integer *ipiv, Treal *b, const integer *ldb, integer *info) 00044 { 00045 /* -- LAPACK driver routine (version 3.0) -- 00046 Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd., 00047 Courant Institute, Argonne National Lab, and Rice University 00048 March 31, 1993 00049 00050 00051 Purpose 00052 ======= 00053 00054 DGESV computes the solution to a real system of linear equations 00055 A * X = B, 00056 where A is an N-by-N matrix and X and B are N-by-NRHS matrices. 00057 00058 The LU decomposition with partial pivoting and row interchanges is 00059 used to factor A as 00060 A = P * L * U, 00061 where P is a permutation matrix, L is unit lower triangular, and U is 00062 upper triangular. The factored form of A is then used to solve the 00063 system of equations A * X = B. 00064 00065 Arguments 00066 ========= 00067 00068 N (input) INTEGER 00069 The number of linear equations, i.e., the order of the 00070 matrix A. N >= 0. 00071 00072 NRHS (input) INTEGER 00073 The number of right hand sides, i.e., the number of columns 00074 of the matrix B. NRHS >= 0. 00075 00076 A (input/output) DOUBLE PRECISION array, dimension (LDA,N) 00077 On entry, the N-by-N coefficient matrix A. 00078 On exit, the factors L and U from the factorization 00079 A = P*L*U; the unit diagonal elements of L are not stored. 00080 00081 LDA (input) INTEGER 00082 The leading dimension of the array A. LDA >= max(1,N). 00083 00084 IPIV (output) INTEGER array, dimension (N) 00085 The pivot indices that define the permutation matrix P; 00086 row i of the matrix was interchanged with row IPIV(i). 00087 00088 B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) 00089 On entry, the N-by-NRHS matrix of right hand side matrix B. 00090 On exit, if INFO = 0, the N-by-NRHS solution matrix X. 00091 00092 LDB (input) INTEGER 00093 The leading dimension of the array B. LDB >= max(1,N). 00094 00095 INFO (output) INTEGER 00096 = 0: successful exit 00097 < 0: if INFO = -i, the i-th argument had an illegal value 00098 > 0: if INFO = i, U(i,i) is exactly zero. The factorization 00099 has been completed, but the factor U is exactly 00100 singular, so the solution could not be computed. 00101 00102 ===================================================================== 00103 00104 00105 Test the input parameters. 00106 00107 Parameter adjustments */ 00108 /* System generated locals */ 00109 integer a_dim1, a_offset, b_dim1, b_offset, i__1; 00110 /* Local variables */ 00111 00112 a_dim1 = *lda; 00113 a_offset = 1 + a_dim1 * 1; 00114 a -= a_offset; 00115 --ipiv; 00116 b_dim1 = *ldb; 00117 b_offset = 1 + b_dim1 * 1; 00118 b -= b_offset; 00119 00120 /* Function Body */ 00121 *info = 0; 00122 if (*n < 0) { 00123 *info = -1; 00124 } else if (*nrhs < 0) { 00125 *info = -2; 00126 } else if (*lda < maxMACRO(1,*n)) { 00127 *info = -4; 00128 } else if (*ldb < maxMACRO(1,*n)) { 00129 *info = -7; 00130 } 00131 if (*info != 0) { 00132 i__1 = -(*info); 00133 template_blas_erbla("GESV ", &i__1); 00134 return 0; 00135 } 00136 00137 /* Compute the LU factorization of A. */ 00138 00139 template_lapack_getrf(n, n, &a[a_offset], lda, &ipiv[1], info); 00140 if (*info == 0) { 00141 00142 /* Solve the system A*X = B, overwriting B with X. */ 00143 00144 template_lapack_getrs("No transpose", n, nrhs, &a[a_offset], lda, &ipiv[1], &b[ 00145 b_offset], ldb, info); 00146 } 00147 return 0; 00148 00149 /* End of DGESV */ 00150 00151 } /* dgesv_ */ 00152 00153 #endif