root / src / pauxil / HPL_pdlange.c @ 1
Historique | Voir | Annoter | Télécharger (8,94 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 |
#ifdef STDC_HEADERS
|
53 |
double HPL_pdlange
|
54 |
( |
55 |
const HPL_T_grid * GRID,
|
56 |
const HPL_T_NORM NORM,
|
57 |
const int M, |
58 |
const int N, |
59 |
const int NB, |
60 |
const double * A, |
61 |
const int LDA |
62 |
) |
63 |
#else
|
64 |
double HPL_pdlange
|
65 |
( GRID, NORM, M, N, NB, A, LDA ) |
66 |
const HPL_T_grid * GRID;
|
67 |
const HPL_T_NORM NORM;
|
68 |
const int M; |
69 |
const int N; |
70 |
const int NB; |
71 |
const double * A; |
72 |
const int LDA; |
73 |
#endif
|
74 |
{ |
75 |
/*
|
76 |
* Purpose
|
77 |
* =======
|
78 |
*
|
79 |
* HPL_pdlange returns the value of the one norm, or the infinity norm,
|
80 |
* or the element of largest absolute value of a distributed matrix A:
|
81 |
*
|
82 |
*
|
83 |
* max(abs(A(i,j))) when NORM = HPL_NORM_A,
|
84 |
* norm1(A), when NORM = HPL_NORM_1,
|
85 |
* normI(A), when NORM = HPL_NORM_I,
|
86 |
*
|
87 |
* where norm1 denotes the one norm of a matrix (maximum column sum) and
|
88 |
* normI denotes the infinity norm of a matrix (maximum row sum). Note
|
89 |
* that max(abs(A(i,j))) is not a matrix norm.
|
90 |
*
|
91 |
* Arguments
|
92 |
* =========
|
93 |
*
|
94 |
* GRID (local input) const HPL_T_grid *
|
95 |
* On entry, GRID points to the data structure containing the
|
96 |
* process grid information.
|
97 |
*
|
98 |
* NORM (global input) const HPL_T_NORM
|
99 |
* On entry, NORM specifies the value to be returned by this
|
100 |
* function as described above.
|
101 |
*
|
102 |
* M (global input) const int
|
103 |
* On entry, M specifies the number of rows of the matrix A.
|
104 |
* M must be at least zero.
|
105 |
*
|
106 |
* N (global input) const int
|
107 |
* On entry, N specifies the number of columns of the matrix A.
|
108 |
* N must be at least zero.
|
109 |
*
|
110 |
* NB (global input) const int
|
111 |
* On entry, NB specifies the blocking factor used to partition
|
112 |
* and distribute the matrix. NB must be larger than one.
|
113 |
*
|
114 |
* A (local input) const double *
|
115 |
* On entry, A points to an array of dimension (LDA,LocQ(N)),
|
116 |
* that contains the local pieces of the distributed matrix A.
|
117 |
*
|
118 |
* LDA (local input) const int
|
119 |
* On entry, LDA specifies the leading dimension of the array A.
|
120 |
* LDA must be at least max(1,LocP(M)).
|
121 |
*
|
122 |
* ---------------------------------------------------------------------
|
123 |
*/
|
124 |
/*
|
125 |
* .. Local Variables ..
|
126 |
*/
|
127 |
double s, v0=HPL_rzero, * work = NULL; |
128 |
MPI_Comm Acomm, Ccomm, Rcomm; |
129 |
int ii, jj, mp, mycol, myrow, npcol, nprow,
|
130 |
nq; |
131 |
/* ..
|
132 |
* .. Executable Statements ..
|
133 |
*/
|
134 |
(void) HPL_grid_info( GRID, &nprow, &npcol, &myrow, &mycol );
|
135 |
Rcomm = GRID->row_comm; Ccomm = GRID->col_comm; |
136 |
Acomm = GRID->all_comm; |
137 |
|
138 |
Mnumroc( mp, M, NB, NB, myrow, 0, nprow );
|
139 |
Mnumroc( nq, N, NB, NB, mycol, 0, npcol );
|
140 |
|
141 |
if( Mmin( M, N ) == 0 ) { return( v0 ); } |
142 |
else if( NORM == HPL_NORM_A ) |
143 |
{ |
144 |
/*
|
145 |
* max( abs( A ) )
|
146 |
*/
|
147 |
if( ( nq > 0 ) && ( mp > 0 ) ) |
148 |
{ |
149 |
for( jj = 0; jj < nq; jj++ ) |
150 |
{ |
151 |
for( ii = 0; ii < mp; ii++ ) |
152 |
{ v0 = Mmax( v0, Mabs( *A ) ); A++; } |
153 |
A += LDA - mp; |
154 |
} |
155 |
} |
156 |
(void) HPL_reduce( (void *)(&v0), 1, HPL_DOUBLE, HPL_max, 0, |
157 |
Acomm ); |
158 |
} |
159 |
else if( NORM == HPL_NORM_1 ) |
160 |
{ |
161 |
/*
|
162 |
* Find norm_1( A ).
|
163 |
*/
|
164 |
if( nq > 0 ) |
165 |
{ |
166 |
work = (double*)malloc( (size_t)(nq) * sizeof( double ) ); |
167 |
if( work == NULL ) |
168 |
{ HPL_pabort( __LINE__, "HPL_pdlange", "Memory allocation failed" ); } |
169 |
|
170 |
for( jj = 0; jj < nq; jj++ ) |
171 |
{ |
172 |
s = HPL_rzero; |
173 |
for( ii = 0; ii < mp; ii++ ) { s += Mabs( *A ); A++; } |
174 |
work[jj] = s; A += LDA - mp; |
175 |
} |
176 |
/*
|
177 |
* Find sum of global matrix columns, store on row 0 of process grid
|
178 |
*/
|
179 |
(void) HPL_reduce( (void *)(work), nq, HPL_DOUBLE, HPL_sum, |
180 |
0, Ccomm );
|
181 |
/*
|
182 |
* Find maximum sum of columns for 1-norm
|
183 |
*/
|
184 |
if( myrow == 0 ) |
185 |
{ v0 = work[HPL_idamax( nq, work, 1 )]; v0 = Mabs( v0 ); }
|
186 |
if( work ) free( work );
|
187 |
} |
188 |
/*
|
189 |
* Find max in row 0, store result in process (0,0)
|
190 |
*/
|
191 |
if( myrow == 0 ) |
192 |
(void) HPL_reduce( (void *)(&v0), 1, HPL_DOUBLE, HPL_max, 0, |
193 |
Rcomm ); |
194 |
} |
195 |
else if( NORM == HPL_NORM_I ) |
196 |
{ |
197 |
/*
|
198 |
* Find norm_inf( A )
|
199 |
*/
|
200 |
if( mp > 0 ) |
201 |
{ |
202 |
work = (double*)malloc( (size_t)(mp) * sizeof( double ) ); |
203 |
if( work == NULL ) |
204 |
{ HPL_pabort( __LINE__, "HPL_pdlange", "Memory allocation failed" ); } |
205 |
|
206 |
for( ii = 0; ii < mp; ii++ ) { work[ii] = HPL_rzero; } |
207 |
|
208 |
for( jj = 0; jj < nq; jj++ ) |
209 |
{ |
210 |
for( ii = 0; ii < mp; ii++ ) |
211 |
{ work[ii] += Mabs( *A ); A++; } |
212 |
A += LDA - mp; |
213 |
} |
214 |
/*
|
215 |
* Find sum of global matrix rows, store on column 0 of process grid
|
216 |
*/
|
217 |
(void) HPL_reduce( (void *)(work), mp, HPL_DOUBLE, HPL_sum, |
218 |
0, Rcomm );
|
219 |
/*
|
220 |
* Find maximum sum of rows for inf-norm
|
221 |
*/
|
222 |
if( mycol == 0 ) |
223 |
{ v0 = work[HPL_idamax( mp, work, 1 )]; v0 = Mabs( v0 ); }
|
224 |
if( work ) free( work );
|
225 |
} |
226 |
/*
|
227 |
* Find max in column 0, store result in process (0,0)
|
228 |
*/
|
229 |
if( mycol == 0 ) |
230 |
(void) HPL_reduce( (void *)(&v0), 1, HPL_DOUBLE, HPL_max, |
231 |
0, Ccomm );
|
232 |
} |
233 |
/*
|
234 |
* Broadcast answer to every process in the grid
|
235 |
*/
|
236 |
(void) HPL_broadcast( (void *)(&v0), 1, HPL_DOUBLE, 0, Acomm ); |
237 |
|
238 |
return( v0 );
|
239 |
/*
|
240 |
* End of HPL_pdlange
|
241 |
*/
|
242 |
} |