Statistiques
| Révision :

root / src / auxil / HPL_dlange.c @ 1

Historique | Voir | Annoter | Télécharger (6,84 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_dlange
54
(
55
   const HPL_T_NORM                 NORM,
56
   const int                        M,
57
   const int                        N,
58
   const double *                   A,
59
   const int                        LDA
60
)
61
#else
62
double HPL_dlange
63
( NORM, M, N, A, LDA )
64
   const HPL_T_NORM                 NORM;
65
   const int                        M;
66
   const int                        N;
67
   const double *                   A;
68
   const int                        LDA;
69
#endif
70
{
71
/* 
72
 * Purpose
73
 * =======
74
 *
75
 * HPL_dlange returns  the value of the one norm,  or the infinity norm,
76
 * or the element of largest absolute value of a matrix A:              
77
 *  
78
 *    max(abs(A(i,j))) when NORM = HPL_NORM_A,                          
79
 *    norm1(A),        when NORM = HPL_NORM_1,                          
80
 *    normI(A),        when NORM = HPL_NORM_I,                          
81
 *  
82
 * where norm1 denotes the one norm of a matrix (maximum column sum) and
83
 * normI denotes  the infinity norm of a matrix (maximum row sum).  Note
84
 * that max(abs(A(i,j))) is not a matrix norm.
85
 *
86
 * Arguments
87
 * =========
88
 *
89
 * NORM    (local input)                 const HPL_T_NORM
90
 *         On entry,  NORM  specifies  the  value to be returned by this
91
 *         function as described above.
92
 *
93
 * M       (local input)                 const int
94
 *         On entry,  M  specifies  the number  of rows of the matrix A.
95
 *         M must be at least zero.
96
 *
97
 * N       (local input)                 const int
98
 *         On entry,  N specifies the number of columns of the matrix A.
99
 *         N must be at least zero.
100
 *
101
 * A       (local input)                 const double *
102
 *         On entry,  A  points to an  array of dimension  (LDA,N), that
103
 *         contains the matrix A.
104
 *
105
 * LDA     (local input)                 const int
106
 *         On entry, LDA specifies the leading dimension of the array A.
107
 *         LDA must be at least max(1,M).
108
 *
109
 * ---------------------------------------------------------------------
110
 */ 
111
/*
112
 * .. Local Variables ..
113
 */
114
   double                     s, v0=HPL_rzero, * work = NULL;
115
   int                        i, j;
116
/* ..
117
 * .. Executable Statements ..
118
 */
119
   if( ( M <= 0 ) || ( N <= 0 ) ) return( HPL_rzero );
120

    
121
   if(      NORM == HPL_NORM_A )
122
   {
123
/*
124
 * max( abs( A ) )
125
 */
126
      for( j = 0; j < N; j++ )
127
      {
128
         for( i = 0; i < M; i++ ) { v0 = Mmax( v0, Mabs( *A ) ); A++; }
129
         A += LDA - M;
130
      }
131
   }
132
   else if( NORM == HPL_NORM_1 )
133
   {
134
/*
135
 * Find norm_1( A ).
136
 */
137
      work = (double*)malloc( (size_t)(N) * sizeof( double ) );
138
      if( work == NULL )
139
      { HPL_abort( __LINE__, "HPL_dlange", "Memory allocation failed" ); }
140
      else
141
      {
142
         for( j = 0; j < N; j++ )
143
         {
144
            s = HPL_rzero;
145
            for( i = 0; i < M; i++ ) { s += Mabs( *A ); A++; }
146
            work[j] = s; A += LDA - M;
147
         }
148
/*
149
 * Find maximum sum of columns for 1-norm
150
 */
151
         v0 = work[HPL_idamax( N, work, 1 )]; v0 = Mabs( v0 );
152
         if( work ) free( work );
153
      }
154
   }
155
   else if( NORM == HPL_NORM_I )
156
   {
157
/*
158
 * Find norm_inf( A )
159
 */
160
      work = (double*)malloc( (size_t)(M) * sizeof( double ) );
161
      if( work == NULL )
162
      { HPL_abort( __LINE__, "HPL_dlange", "Memory allocation failed" ); }
163
      else
164
      {
165
         for( i = 0; i < M; i++ ) { work[i] = HPL_rzero; }
166

    
167
         for( j = 0; j < N; j++ )
168
         {
169
            for( i = 0; i < M; i++ ) { work[i] += Mabs( *A ); A++; }
170
            A += LDA - M;
171
         }
172
/*       
173
 * Find maximum sum of rows for inf-norm
174
 */      
175
         v0 = work[HPL_idamax( M, work, 1 )]; v0 = Mabs( v0 );
176
         if( work ) free( work );
177
      }
178
   }
179

    
180
   return( v0 );
181
/*
182
 * End of HPL_dlange
183
 */
184
}