ergo
template_blas_idamax.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_IDAMAX_HEADER
36 #define TEMPLATE_BLAS_IDAMAX_HEADER
37 
38 
39 template<class Treal>
40 integer template_blas_idamax(const integer *n, const Treal *dx, const integer *incx)
41 {
42  /* System generated locals */
43  integer ret_val, i__1;
44  Treal d__1;
45  /* Local variables */
46  Treal dmax__;
47  integer i__, ix;
48 /* finds the index of element having max. absolute value.
49  jack dongarra, linpack, 3/11/78.
50  modified 3/93 to return if incx .le. 0.
51  modified 12/3/93, array(1) declarations changed to array(*)
52  Parameter adjustments */
53  --dx;
54  /* Function Body */
55  ret_val = 0;
56  if (*n < 1 || *incx <= 0) {
57  return ret_val;
58  }
59  ret_val = 1;
60  if (*n == 1) {
61  return ret_val;
62  }
63  if (*incx == 1) {
64  goto L20;
65  }
66 /* code for increment not equal to 1 */
67  ix = 1;
68  dmax__ = absMACRO(dx[1]);
69  ix += *incx;
70  i__1 = *n;
71  for (i__ = 2; i__ <= i__1; ++i__) {
72  if ((d__1 = dx[ix], absMACRO(d__1)) <= dmax__) {
73  goto L5;
74  }
75  ret_val = i__;
76  dmax__ = (d__1 = dx[ix], absMACRO(d__1));
77 L5:
78  ix += *incx;
79 /* L10: */
80  }
81  return ret_val;
82 /* code for increment equal to 1 */
83 L20:
84  dmax__ = absMACRO(dx[1]);
85  i__1 = *n;
86  for (i__ = 2; i__ <= i__1; ++i__) {
87  if ((d__1 = dx[i__], absMACRO(d__1)) <= dmax__) {
88  goto L30;
89  }
90  ret_val = i__;
91  dmax__ = (d__1 = dx[i__], absMACRO(d__1));
92 L30:
93  ;
94  }
95  return ret_val;
96 } /* idamax_ */
97 
98 #endif