root / src / blas / HPL_idamax.c @ 9
Historique | Voir | Annoter | Télécharger (6,74 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_VSIPL
|
97 |
register double absxi, smax = HPL_rzero, x0, x1, x2, x3, |
98 |
x4, x5, x6, x7; |
99 |
const double * StX; |
100 |
register int imax = 0, i = 0, j; |
101 |
int nu;
|
102 |
const int incX2 = 2 * INCX, incX3 = 3 * INCX, |
103 |
incX4 = 4 * INCX, incX5 = 5 * INCX, |
104 |
incX6 = 6 * INCX, incX7 = 7 * INCX, |
105 |
incX8 = 8 * INCX;
|
106 |
|
107 |
if( N > 0 ) |
108 |
{ |
109 |
if( ( nu = ( N >> 3 ) << 3 ) != 0 ) |
110 |
{ |
111 |
StX = X + nu * INCX; |
112 |
|
113 |
do
|
114 |
{ |
115 |
x0 = (*X); x4 = X[incX4]; x1 = X[INCX ]; x5 = X[incX5]; |
116 |
x2 = X[incX2]; x6 = X[incX6]; x3 = X[incX3]; x7 = X[incX7]; |
117 |
|
118 |
absxi = Mabs( x0 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
119 |
i += 1;
|
120 |
absxi = Mabs( x1 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
121 |
i += 1;
|
122 |
absxi = Mabs( x2 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
123 |
i += 1;
|
124 |
absxi = Mabs( x3 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
125 |
i += 1;
|
126 |
absxi = Mabs( x4 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
127 |
i += 1;
|
128 |
absxi = Mabs( x5 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
129 |
i += 1;
|
130 |
absxi = Mabs( x6 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
131 |
i += 1;
|
132 |
absxi = Mabs( x7 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
133 |
i += 1;
|
134 |
|
135 |
X += incX8; |
136 |
|
137 |
} while( X != StX );
|
138 |
} |
139 |
|
140 |
for( j = N - nu; j != 0; j-- ) |
141 |
{ |
142 |
x0 = (*X); |
143 |
absxi = Mabs( x0 ); if( absxi > smax ) { imax = i; smax = absxi; }
|
144 |
i += 1;
|
145 |
X += INCX; |
146 |
} |
147 |
} |
148 |
return( imax );
|
149 |
#endif
|
150 |
#ifdef HPL_CALL_FBLAS
|
151 |
#ifdef HPL_USE_F77_INTEGER_DEF
|
152 |
const F77_INTEGER F77N = N, F77incx = INCX;
|
153 |
#else
|
154 |
#define F77N N
|
155 |
#define F77incx INCX
|
156 |
#endif
|
157 |
int imax = 0; |
158 |
|
159 |
if( N > 0 ) imax = F77idamax( &F77N, X, &F77incx ) - 1; |
160 |
return( imax );
|
161 |
#endif
|
162 |
|
163 |
#ifdef HPL_CALL_CUBLAS
|
164 |
#define CUBLASN N
|
165 |
#define CUBLASincx INCX
|
166 |
int imax = 0; |
167 |
|
168 |
if( N > 0 ) imax = CUBLAS_IDAMAX( &CUBLASN, X, &CUBLASincx ) - 1; |
169 |
return( imax );
|
170 |
#endif
|
171 |
/*
|
172 |
* End of HPL_idamax
|
173 |
*/
|
174 |
} |
175 |
|
176 |
#endif
|