HPL_dlange.c 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. #ifdef STDC_HEADERS
  52. double HPL_dlange
  53. (
  54. const HPL_T_NORM NORM,
  55. const int M,
  56. const int N,
  57. const double * A,
  58. const int LDA
  59. )
  60. #else
  61. double HPL_dlange
  62. ( NORM, M, N, A, LDA )
  63. const HPL_T_NORM NORM;
  64. const int M;
  65. const int N;
  66. const double * A;
  67. const int LDA;
  68. #endif
  69. {
  70. /*
  71. * Purpose
  72. * =======
  73. *
  74. * HPL_dlange returns the value of the one norm, or the infinity norm,
  75. * or the element of largest absolute value of a matrix A:
  76. *
  77. * max(abs(A(i,j))) when NORM = HPL_NORM_A,
  78. * norm1(A), when NORM = HPL_NORM_1,
  79. * normI(A), when NORM = HPL_NORM_I,
  80. *
  81. * where norm1 denotes the one norm of a matrix (maximum column sum) and
  82. * normI denotes the infinity norm of a matrix (maximum row sum). Note
  83. * that max(abs(A(i,j))) is not a matrix norm.
  84. *
  85. * Arguments
  86. * =========
  87. *
  88. * NORM (local input) const HPL_T_NORM
  89. * On entry, NORM specifies the value to be returned by this
  90. * function as described above.
  91. *
  92. * M (local input) const int
  93. * On entry, M specifies the number of rows of the matrix A.
  94. * M must be at least zero.
  95. *
  96. * N (local input) const int
  97. * On entry, N specifies the number of columns of the matrix A.
  98. * N must be at least zero.
  99. *
  100. * A (local input) const double *
  101. * On entry, A points to an array of dimension (LDA,N), that
  102. * contains the matrix A.
  103. *
  104. * LDA (local input) const int
  105. * On entry, LDA specifies the leading dimension of the array A.
  106. * LDA must be at least max(1,M).
  107. *
  108. * ---------------------------------------------------------------------
  109. */
  110. /*
  111. * .. Local Variables ..
  112. */
  113. double s, v0=HPL_rzero, * work = NULL;
  114. int i, j;
  115. /* ..
  116. * .. Executable Statements ..
  117. */
  118. if( ( M <= 0 ) || ( N <= 0 ) ) return( HPL_rzero );
  119. if( NORM == HPL_NORM_A )
  120. {
  121. /*
  122. * max( abs( A ) )
  123. */
  124. for( j = 0; j < N; j++ )
  125. {
  126. for( i = 0; i < M; i++ ) { v0 = Mmax( v0, Mabs( *A ) ); A++; }
  127. A += LDA - M;
  128. }
  129. }
  130. else if( NORM == HPL_NORM_1 )
  131. {
  132. /*
  133. * Find norm_1( A ).
  134. */
  135. work = (double*)malloc( (size_t)(N) * sizeof( double ) );
  136. if( work == NULL )
  137. { HPL_abort( __LINE__, "HPL_dlange", "Memory allocation failed" ); }
  138. else
  139. {
  140. for( j = 0; j < N; j++ )
  141. {
  142. s = HPL_rzero;
  143. for( i = 0; i < M; i++ ) { s += Mabs( *A ); A++; }
  144. work[j] = s; A += LDA - M;
  145. }
  146. /*
  147. * Find maximum sum of columns for 1-norm
  148. */
  149. v0 = work[HPL_idamax( N, work, 1 )]; v0 = Mabs( v0 );
  150. if( work ) free( work );
  151. }
  152. }
  153. else if( NORM == HPL_NORM_I )
  154. {
  155. /*
  156. * Find norm_inf( A )
  157. */
  158. work = (double*)malloc( (size_t)(M) * sizeof( double ) );
  159. if( work == NULL )
  160. { HPL_abort( __LINE__, "HPL_dlange", "Memory allocation failed" ); }
  161. else
  162. {
  163. for( i = 0; i < M; i++ ) { work[i] = HPL_rzero; }
  164. for( j = 0; j < N; j++ )
  165. {
  166. for( i = 0; i < M; i++ ) { work[i] += Mabs( *A ); A++; }
  167. A += LDA - M;
  168. }
  169. /*
  170. * Find maximum sum of rows for inf-norm
  171. */
  172. v0 = work[HPL_idamax( M, work, 1 )]; v0 = Mabs( v0 );
  173. if( work ) free( work );
  174. }
  175. }
  176. return( v0 );
  177. /*
  178. * End of HPL_dlange
  179. */
  180. }