root / src / blas / HPL_idamax.c
Historique | Voir | Annoter | Télécharger (7,03 ko)
1 |
/*
|
---|---|
2 |
* -- High Performance Computing Linpack Benchmark (HPL)
|
3 |
* HPL - 2.0 - September 10, 2008
|
4 |
* Antoine P. Petitet
|
5 |
* University of Tennessee, Knoxville
|
6 |
* Innovative Computing Laboratory
|
7 |
* (C) Copyright 2000-2008 All Rights Reserved
|
8 |
*
|
9 |
* -- Copyright notice and Licensing terms:
|
10 |
*
|
11 |
* Redistribution and use in source and binary forms, with or without
|
12 |
* modification, are permitted provided that the following conditions
|
13 |
* are met:
|
14 |
*
|
15 |
* 1. Redistributions of source code must retain the above copyright
|
16 |
* notice, this list of conditions and the following disclaimer.
|
17 |
*
|
18 |
* 2. Redistributions in binary form must reproduce the above copyright
|
19 |
* notice, this list of conditions, and the following disclaimer in the
|
20 |
* documentation and/or other materials provided with the distribution.
|
21 |
*
|
22 |
* 3. All advertising materials mentioning features or use of this
|
23 |
* software must display the following acknowledgement:
|
24 |
* This product includes software developed at the University of
|
25 |
* Tennessee, Knoxville, Innovative Computing Laboratory.
|
26 |
*
|
27 |
* 4. The name of the University, the name of the Laboratory, or the
|
28 |
* names of its contributors may not be used to endorse or promote
|
29 |
* products derived from this software without specific written
|
30 |
* permission.
|
31 |
*
|
32 |
* -- Disclaimer:
|
33 |
*
|
34 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
35 |
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
36 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
37 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY
|
38 |
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
39 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
40 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
41 |
* DATA OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
42 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
43 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
44 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
45 |
* ---------------------------------------------------------------------
|
46 |
*/
|
47 |
/*
|
48 |
* Include files
|
49 |
*/
|
50 |
#include "hpl.h" |
51 |
|
52 |
#ifndef HPL_idamax
|
53 |
|
54 |
#ifdef STDC_HEADERS
|
55 |
int HPL_idamax
|
56 |
( |
57 |
const int N, |
58 |
const double * X, |
59 |
const int INCX |
60 |
) |
61 |
#else
|
62 |
int HPL_idamax
|
63 |
( N, X, INCX ) |
64 |
const int N; |
65 |
const double * X; |
66 |
const int INCX; |
67 |
#endif
|
68 |
{ |
69 |
/*
|
70 |
* Purpose
|
71 |
* =======
|
72 |
*
|
73 |
* HPL_idamax returns the index in an n-vector x of the first element
|
74 |
* having maximum absolute value.
|
75 |
*
|
76 |
* Arguments
|
77 |
* =========
|
78 |
*
|
79 |
* N (local input) const int
|
80 |
* On entry, N specifies the length of the vector x. N must be
|
81 |
* at least zero.
|
82 |
*
|
83 |
* X (local input) const double *
|
84 |
* On entry, X is an incremented array of dimension at least
|
85 |
* ( 1 + ( n - 1 ) * abs( INCX ) ) that contains the vector x.
|
86 |
*
|
87 |
* INCX (local input) const int
|
88 |
* On entry, INCX specifies the increment for the elements of X.
|
89 |
* INCX must not be zero.
|
90 |
*
|
91 |
* ---------------------------------------------------------------------
|
92 |
*/
|
93 |
#ifdef HPL_CALL_CBLAS
|
94 |
return( (int)(cblas_idamax( N, X, INCX )) ); |
95 |
#endif
|
96 |
#ifdef HPL_CALL_GSLCBLAS
|
97 |
return( (int)(cblas_idamax( N, X, INCX )) ); |
98 |
#endif
|
99 |
#ifdef HPL_CALL_VSIPL
|
100 |
register double absxi, smax = HPL_rzero, x0, x1, x2, x3, |
101 |
x4, x5, x6, x7; |
102 |
const double * StX; |
103 |
register int imax = 0, i = 0, j; |
104 |
int nu;
|
105 |
const int incX2 = 2 * INCX, incX3 = 3 * INCX, |
106 |
incX4 = 4 * INCX, incX5 = 5 * INCX, |
107 |
incX6 = 6 * INCX, incX7 = 7 * INCX, |
108 |
incX8 = 8 * INCX;
|
109 |
|
110 |
if( N > 0 ) |
111 |
{ |
112 |
if( ( nu = ( N >> 3 ) << 3 ) != 0 ) |
113 |
{ |
114 |
StX = X + nu * INCX; |
115 |
|
116 |
do
|
117 |
{ |
118 |
x0 = (*X); x4 = X[incX4]; x1 = X[INCX ]; x5 = X[incX5]; |
119 |
x2 = X[incX2]; x6 = X[incX6]; x3 = X[incX3]; x7 = X[incX7]; |
120 |
|
121 |
absxi = Mabs( x0 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
122 |
i += 1;
|
123 |
absxi = Mabs( x1 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
124 |
i += 1;
|
125 |
absxi = Mabs( x2 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
126 |
i += 1;
|
127 |
absxi = Mabs( x3 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
128 |
i += 1;
|
129 |
absxi = Mabs( x4 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
130 |
i += 1;
|
131 |
absxi = Mabs( x5 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
132 |
i += 1;
|
133 |
absxi = Mabs( x6 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
134 |
i += 1;
|
135 |
absxi = Mabs( x7 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
136 |
i += 1;
|
137 |
|
138 |
X += incX8; |
139 |
|
140 |
} while( X != StX );
|
141 |
} |
142 |
|
143 |
for( j = N - nu; j != 0; j-- ) |
144 |
{ |
145 |
x0 = (*X); |
146 |
absxi = Mabs( x0 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
147 |
i += 1;
|
148 |
X += INCX; |
149 |
} |
150 |
} |
151 |
return( imax );
|
152 |
#endif
|
153 |
|
154 |
#ifdef HPL_CALL_FBLAS
|
155 |
#ifdef HPL_USE_F77_INTEGER_DEF
|
156 |
const F77_INTEGER F77N = N, F77incx = INCX;
|
157 |
#else
|
158 |
#define F77N N
|
159 |
#define F77incx INCX
|
160 |
#endif
|
161 |
int imax = 0; |
162 |
|
163 |
if( N > 0 ) imax = gsl_blas_idamax( &F77N, X, &F77incx ) - 1; |
164 |
return( imax );
|
165 |
#endif
|
166 |
|
167 |
#ifdef HPL_CALL_CUBLAS
|
168 |
#define CUBLASN N
|
169 |
#define CUBLASincx INCX
|
170 |
int imax = 0; |
171 |
|
172 |
if( N > 0 ) imax = CUBLAS_IDAMAX( &CUBLASN, X, &CUBLASincx ) - 1; |
173 |
return( imax );
|
174 |
#endif
|
175 |
|
176 |
#ifdef HPL_CALL_ACML
|
177 |
#define ACMLN N
|
178 |
#define ACMLincx INCX
|
179 |
int imax = 0; |
180 |
|
181 |
if( N > 0 ) imax = idamax_( &ACMLN, X, &ACMLincx ) - 1; |
182 |
return( imax );
|
183 |
#endif
|
184 |
/*
|
185 |
* End of HPL_idamax
|
186 |
*/
|
187 |
} |
188 |
|
189 |
#endif
|