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