ergo
template_lapack_larf.h
Go to the documentation of this file.
1 /* Ergo, version 3.3, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2013 Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  *
18  * Primary academic reference:
19  * Kohn−Sham Density Functional Theory Electronic Structure Calculations
20  * with Linearly Scaling Computational Time and Memory Usage,
21  * Elias Rudberg, Emanuel H. Rubensson, and Pawel Salek,
22  * J. Chem. Theory Comput. 7, 340 (2011),
23  * <http://dx.doi.org/10.1021/ct100611z>
24  *
25  * For further information about Ergo, see <http://www.ergoscf.org>.
26  */
27 
28  /* This file belongs to the template_lapack part of the Ergo source
29  * code. The source files in the template_lapack directory are modified
30  * versions of files originally distributed as CLAPACK, see the
31  * Copyright/license notice in the file template_lapack/COPYING.
32  */
33 
34 
35 #ifndef TEMPLATE_LAPACK_LARF_HEADER
36 #define TEMPLATE_LAPACK_LARF_HEADER
37 
38 
39 template<class Treal>
40 int template_lapack_larf(const char *side, const integer *m, const integer *n, const Treal *v,
41  const integer *incv, const Treal *tau, Treal *c__, const integer *ldc,
42  Treal *work)
43 {
44 /* -- LAPACK auxiliary routine (version 3.0) --
45  Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
46  Courant Institute, Argonne National Lab, and Rice University
47  February 29, 1992
48 
49 
50  Purpose
51  =======
52 
53  DLARF applies a real elementary reflector H to a real m by n matrix
54  C, from either the left or the right. H is represented in the form
55 
56  H = I - tau * v * v'
57 
58  where tau is a real scalar and v is a real vector.
59 
60  If tau = 0, then H is taken to be the unit matrix.
61 
62  Arguments
63  =========
64 
65  SIDE (input) CHARACTER*1
66  = 'L': form H * C
67  = 'R': form C * H
68 
69  M (input) INTEGER
70  The number of rows of the matrix C.
71 
72  N (input) INTEGER
73  The number of columns of the matrix C.
74 
75  V (input) DOUBLE PRECISION array, dimension
76  (1 + (M-1)*abs(INCV)) if SIDE = 'L'
77  or (1 + (N-1)*abs(INCV)) if SIDE = 'R'
78  The vector v in the representation of H. V is not used if
79  TAU = 0.
80 
81  INCV (input) INTEGER
82  The increment between elements of v. INCV <> 0.
83 
84  TAU (input) DOUBLE PRECISION
85  The value tau in the representation of H.
86 
87  C (input/output) DOUBLE PRECISION array, dimension (LDC,N)
88  On entry, the m by n matrix C.
89  On exit, C is overwritten by the matrix H * C if SIDE = 'L',
90  or C * H if SIDE = 'R'.
91 
92  LDC (input) INTEGER
93  The leading dimension of the array C. LDC >= max(1,M).
94 
95  WORK (workspace) DOUBLE PRECISION array, dimension
96  (N) if SIDE = 'L'
97  or (M) if SIDE = 'R'
98 
99  =====================================================================
100 
101 
102  Parameter adjustments */
103  /* Table of constant values */
104  Treal c_b4 = 1.;
105  Treal c_b5 = 0.;
106  integer c__1 = 1;
107 
108  /* System generated locals */
109  integer c_dim1, c_offset;
110  Treal d__1;
111 
112 
113  --v;
114  c_dim1 = *ldc;
115  c_offset = 1 + c_dim1 * 1;
116  c__ -= c_offset;
117  --work;
118 
119  /* Function Body */
120  if (template_blas_lsame(side, "L")) {
121 
122 /* Form H * C */
123 
124  if (*tau != 0.) {
125 
126 /* w := C' * v */
127 
128  template_blas_gemv("Transpose", m, n, &c_b4, &c__[c_offset], ldc, &v[1], incv,
129  &c_b5, &work[1], &c__1);
130 
131 /* C := C - v * w' */
132 
133  d__1 = -(*tau);
134  template_blas_ger(m, n, &d__1, &v[1], incv, &work[1], &c__1, &c__[c_offset],
135  ldc);
136  }
137  } else {
138 
139 /* Form C * H */
140 
141  if (*tau != 0.) {
142 
143 /* w := C * v */
144 
145  template_blas_gemv("No transpose", m, n, &c_b4, &c__[c_offset], ldc, &v[1],
146  incv, &c_b5, &work[1], &c__1);
147 
148 /* C := C - w * v' */
149 
150  d__1 = -(*tau);
151  template_blas_ger(m, n, &d__1, &work[1], &c__1, &v[1], incv, &c__[c_offset],
152  ldc);
153  }
154  }
155  return 0;
156 
157 /* End of DLARF */
158 
159 } /* dlarf_ */
160 
161 #endif
int integer
Definition: template_blas_common.h:38
int template_blas_ger(const integer *m, const integer *n, const Treal *alpha, const Treal *x, const integer *incx, const Treal *y, const integer *incy, Treal *a, const integer *lda)
Definition: template_blas_ger.h:40
int template_blas_gemv(const char *trans, const integer *m, const integer *n, const Treal *alpha, const Treal *a, const integer *lda, const Treal *x, const integer *incx, const Treal *beta, Treal *y, const integer *incy)
Definition: template_blas_gemv.h:41
side
Definition: Matrix.h:73
int template_lapack_larf(const char *side, const integer *m, const integer *n, const Treal *v, const integer *incv, const Treal *tau, Treal *c__, const integer *ldc, Treal *work)
Definition: template_lapack_larf.h:40
logical template_blas_lsame(const char *ca, const char *cb)
Definition: template_blas_common.cc:44