template_lapack_gesv.h

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

Generated on Wed Nov 21 09:32:01 2012 for ergo by  doxygen 1.4.7