ergo
template_blas_dot.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_DOT_HEADER
36 #define TEMPLATE_BLAS_DOT_HEADER
37 
38 #include "template_blas_common.h"
39 
40 template<class Treal>
41 Treal template_blas_dot(const integer *n, const Treal *dx, const integer *incx, const Treal *dy,
42  const integer *incy)
43 {
44  /* System generated locals */
45  integer i__1;
46  Treal ret_val;
47  /* Local variables */
48  integer i__, m;
49  Treal dtemp;
50  integer ix, iy, mp1;
51 /* forms the dot product of two vectors.
52  uses unrolled loops for increments equal to one.
53  jack dongarra, linpack, 3/11/78.
54  modified 12/3/93, array(1) declarations changed to array(*)
55  Parameter adjustments */
56  --dy;
57  --dx;
58  /* Function Body */
59  ret_val = 0.;
60  dtemp = 0.;
61  if (*n <= 0) {
62  return ret_val;
63  }
64  if (*incx == 1 && *incy == 1) {
65  goto L20;
66  }
67 /* code for unequal increments or equal increments
68  not equal to 1 */
69  ix = 1;
70  iy = 1;
71  if (*incx < 0) {
72  ix = (-(*n) + 1) * *incx + 1;
73  }
74  if (*incy < 0) {
75  iy = (-(*n) + 1) * *incy + 1;
76  }
77  i__1 = *n;
78  for (i__ = 1; i__ <= i__1; ++i__) {
79  dtemp += dx[ix] * dy[iy];
80  ix += *incx;
81  iy += *incy;
82 /* L10: */
83  }
84  ret_val = dtemp;
85  return ret_val;
86 /* code for both increments equal to 1
87  clean-up loop */
88 L20:
89  m = *n % 5;
90  if (m == 0) {
91  goto L40;
92  }
93  i__1 = m;
94  for (i__ = 1; i__ <= i__1; ++i__) {
95  dtemp += dx[i__] * dy[i__];
96 /* L30: */
97  }
98  if (*n < 5) {
99  goto L60;
100  }
101 L40:
102  mp1 = m + 1;
103  i__1 = *n;
104  for (i__ = mp1; i__ <= i__1; i__ += 5) {
105  dtemp = dtemp + dx[i__] * dy[i__] + dx[i__ + 1] * dy[i__ + 1] + dx[
106  i__ + 2] * dy[i__ + 2] + dx[i__ + 3] * dy[i__ + 3] + dx[i__ +
107  4] * dy[i__ + 4];
108 /* L50: */
109  }
110 L60:
111  ret_val = dtemp;
112  return ret_val;
113 } /* ddot_ */
114 
115 #endif