ergo
template_blas_dot.h
Go to the documentation of this file.
1 /* Ergo, version 3.7, a program for linear scaling electronic structure
2  * calculations.
3  * Copyright (C) 2018 Elias Rudberg, Emanuel H. Rubensson, Pawel Salek,
4  * and Anastasia Kruchinina.
5  *
6  * This program is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program. If not, see <http://www.gnu.org/licenses/>.
18  *
19  * Primary academic reference:
20  * Ergo: An open-source program for linear-scaling electronic structure
21  * calculations,
22  * Elias Rudberg, Emanuel H. Rubensson, Pawel Salek, and Anastasia
23  * Kruchinina,
24  * SoftwareX 7, 107 (2018),
25  * <http://dx.doi.org/10.1016/j.softx.2018.03.005>
26  *
27  * For further information about Ergo, see <http://www.ergoscf.org>.
28  */
29 
30  /* This file belongs to the template_lapack part of the Ergo source
31  * code. The source files in the template_lapack directory are modified
32  * versions of files originally distributed as CLAPACK, see the
33  * Copyright/license notice in the file template_lapack/COPYING.
34  */
35 
36 
37 #ifndef TEMPLATE_BLAS_DOT_HEADER
38 #define TEMPLATE_BLAS_DOT_HEADER
39 
40 #include "template_blas_common.h"
41 
42 template<class Treal>
43 Treal template_blas_dot(const integer *n, const Treal *dx, const integer *incx, const Treal *dy,
44  const integer *incy)
45 {
46  /* System generated locals */
47  integer i__1;
48  Treal ret_val;
49  /* Local variables */
50  integer i__, m;
51  Treal dtemp;
52  integer ix, iy, mp1;
53 /* forms the dot product of two vectors.
54  uses unrolled loops for increments equal to one.
55  jack dongarra, linpack, 3/11/78.
56  modified 12/3/93, array(1) declarations changed to array(*)
57  Parameter adjustments */
58  --dy;
59  --dx;
60  /* Function Body */
61  ret_val = 0.;
62  dtemp = 0.;
63  if (*n <= 0) {
64  return ret_val;
65  }
66  if (*incx == 1 && *incy == 1) {
67  goto L20;
68  }
69 /* code for unequal increments or equal increments
70  not equal to 1 */
71  ix = 1;
72  iy = 1;
73  if (*incx < 0) {
74  ix = (-(*n) + 1) * *incx + 1;
75  }
76  if (*incy < 0) {
77  iy = (-(*n) + 1) * *incy + 1;
78  }
79  i__1 = *n;
80  for (i__ = 1; i__ <= i__1; ++i__) {
81  dtemp += dx[ix] * dy[iy];
82  ix += *incx;
83  iy += *incy;
84 /* L10: */
85  }
86  ret_val = dtemp;
87  return ret_val;
88 /* code for both increments equal to 1
89  clean-up loop */
90 L20:
91  m = *n % 5;
92  if (m == 0) {
93  goto L40;
94  }
95  i__1 = m;
96  for (i__ = 1; i__ <= i__1; ++i__) {
97  dtemp += dx[i__] * dy[i__];
98 /* L30: */
99  }
100  if (*n < 5) {
101  goto L60;
102  }
103 L40:
104  mp1 = m + 1;
105  i__1 = *n;
106  for (i__ = mp1; i__ <= i__1; i__ += 5) {
107  dtemp = dtemp + dx[i__] * dy[i__] + dx[i__ + 1] * dy[i__ + 1] + dx[
108  i__ + 2] * dy[i__ + 2] + dx[i__ + 3] * dy[i__ + 3] + dx[i__ +
109  4] * dy[i__ + 4];
110 /* L50: */
111  }
112 L60:
113  ret_val = dtemp;
114  return ret_val;
115 } /* ddot_ */
116 
117 #endif
int integer
Definition: template_blas_common.h:40
Treal template_blas_dot(const integer *n, const Treal *dx, const integer *incx, const Treal *dy, const integer *incy)
Definition: template_blas_dot.h:43