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