ergo
template_blas_asum.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_ASUM_HEADER
36 #define TEMPLATE_BLAS_ASUM_HEADER
37 
38 
39 template<class Treal>
40 Treal template_blas_asum(const integer *n, const Treal *dx, const integer *incx)
41 {
42  /* System generated locals */
43  integer i__1, i__2;
44  Treal ret_val, d__1, d__2, d__3, d__4, d__5, d__6;
45  /* Local variables */
46  integer i__, m;
47  Treal dtemp;
48  integer nincx, mp1;
49 /* takes the sum of the absolute values.
50  jack dongarra, linpack, 3/11/78.
51  modified 3/93 to return if incx .le. 0.
52  modified 12/3/93, array(1) declarations changed to array(*)
53  Parameter adjustments */
54  --dx;
55  /* Function Body */
56  ret_val = 0.;
57  dtemp = 0.;
58  if (*n <= 0 || *incx <= 0) {
59  return ret_val;
60  }
61  if (*incx == 1) {
62  goto L20;
63  }
64 /* code for increment not equal to 1 */
65  nincx = *n * *incx;
66  i__1 = nincx;
67  i__2 = *incx;
68  for (i__ = 1; i__2 < 0 ? i__ >= i__1 : i__ <= i__1; i__ += i__2) {
69  dtemp += (d__1 = dx[i__], absMACRO(d__1));
70 /* L10: */
71  }
72  ret_val = dtemp;
73  return ret_val;
74 /* code for increment equal to 1
75  clean-up loop */
76 L20:
77  m = *n % 6;
78  if (m == 0) {
79  goto L40;
80  }
81  i__2 = m;
82  for (i__ = 1; i__ <= i__2; ++i__) {
83  dtemp += (d__1 = dx[i__], absMACRO(d__1));
84 /* L30: */
85  }
86  if (*n < 6) {
87  goto L60;
88  }
89 L40:
90  mp1 = m + 1;
91  i__2 = *n;
92  for (i__ = mp1; i__ <= i__2; i__ += 6) {
93  dtemp = dtemp + (d__1 = dx[i__], absMACRO(d__1)) + (d__2 = dx[i__ + 1],
94  absMACRO(d__2)) + (d__3 = dx[i__ + 2], absMACRO(d__3)) + (d__4 = dx[i__
95  + 3], absMACRO(d__4)) + (d__5 = dx[i__ + 4], absMACRO(d__5)) + (d__6 =
96  dx[i__ + 5], absMACRO(d__6));
97 /* L50: */
98  }
99 L60:
100  ret_val = dtemp;
101  return ret_val;
102 } /* dasum_ */
103 
104 #endif