ergo
template_blas_axpy.h
Go to the documentation of this file.
1 /* Ergo, version 3.2, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2012 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_BLAS_AXPY_HEADER
36 #define TEMPLATE_BLAS_AXPY_HEADER
37 
38 #include "template_blas_common.h"
39 
40 template<class Treal>
41 int template_blas_axpy(const integer *n, const Treal *da, const Treal *dx,
42  const integer *incx, Treal *dy, const integer *incy)
43 {
44  /* System generated locals */
45  integer i__1;
46  /* Local variables */
47  integer i__, m, ix, iy, mp1;
48 /* constant times a vector plus a vector.
49  uses unrolled loops for increments equal to one.
50  jack dongarra, linpack, 3/11/78.
51  modified 12/3/93, array(1) declarations changed to array(*)
52  Parameter adjustments */
53  --dy;
54  --dx;
55  /* Function Body */
56  if (*n <= 0) {
57  return 0;
58  }
59  if (*da == 0.) {
60  return 0;
61  }
62  if (*incx == 1 && *incy == 1) {
63  goto L20;
64  }
65 /* code for unequal increments or equal increments
66  not equal to 1 */
67  ix = 1;
68  iy = 1;
69  if (*incx < 0) {
70  ix = (-(*n) + 1) * *incx + 1;
71  }
72  if (*incy < 0) {
73  iy = (-(*n) + 1) * *incy + 1;
74  }
75  i__1 = *n;
76  for (i__ = 1; i__ <= i__1; ++i__) {
77  dy[iy] += *da * dx[ix];
78  ix += *incx;
79  iy += *incy;
80 /* L10: */
81  }
82  return 0;
83 /* code for both increments equal to 1
84  clean-up loop */
85 L20:
86  m = *n % 4;
87  if (m == 0) {
88  goto L40;
89  }
90  i__1 = m;
91  for (i__ = 1; i__ <= i__1; ++i__) {
92  dy[i__] += *da * dx[i__];
93 /* L30: */
94  }
95  if (*n < 4) {
96  return 0;
97  }
98 L40:
99  mp1 = m + 1;
100  i__1 = *n;
101  for (i__ = mp1; i__ <= i__1; i__ += 4) {
102  dy[i__] += *da * dx[i__];
103  dy[i__ + 1] += *da * dx[i__ + 1];
104  dy[i__ + 2] += *da * dx[i__ + 2];
105  dy[i__ + 3] += *da * dx[i__ + 3];
106 /* L50: */
107  }
108  return 0;
109 } /* daxpy_ */
110 
111 #endif