HPL_dmatgen.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. void HPL_dmatgen
  53. (
  54. const int M,
  55. const int N,
  56. double * A,
  57. const int LDA,
  58. const int ISEED
  59. )
  60. #else
  61. void HPL_dmatgen
  62. ( M, N, A, LDA, ISEED )
  63. const int M;
  64. const int N;
  65. double * A;
  66. const int LDA;
  67. const int ISEED;
  68. #endif
  69. {
  70. /*
  71. * Purpose
  72. * =======
  73. *
  74. * HPL_dmatgen generates (or regenerates) a random matrix A.
  75. *
  76. * The pseudo-random generator uses the linear congruential algorithm:
  77. * X(n+1) = (a * X(n) + c) mod m as described in the Art of Computer
  78. * Programming, Knuth 1973, Vol. 2.
  79. *
  80. * Arguments
  81. * =========
  82. *
  83. * M (input) const int
  84. * On entry, M specifies the number of rows of the matrix A.
  85. * M must be at least zero.
  86. *
  87. * N (input) const int
  88. * On entry, N specifies the number of columns of the matrix A.
  89. * N must be at least zero.
  90. *
  91. * A (output) double *
  92. * On entry, A points to an array of dimension (LDA,N). On exit,
  93. * this array contains the coefficients of the randomly
  94. * generated matrix.
  95. *
  96. * LDA (input) const int
  97. * On entry, LDA specifies the leading dimension of the array A.
  98. * LDA must be at least max(1,M).
  99. *
  100. * ISEED (input) const int
  101. * On entry, ISEED specifies the seed number to generate the
  102. * matrix A. ISEED must be at least zero.
  103. *
  104. * ---------------------------------------------------------------------
  105. */
  106. /*
  107. * .. Local Variables ..
  108. */
  109. int iadd[2], ia1[2], ic1[2], iran1[2],
  110. jseed[2], mult[2];
  111. int i, incA = LDA - M, j;
  112. /* ..
  113. * .. Executable Statements ..
  114. */
  115. if( ( M <= 0 ) || ( N <= 0 ) ) return;
  116. /*
  117. * Initialize the random sequence
  118. */
  119. mult [0] = HPL_MULT0; mult [1] = HPL_MULT1;
  120. iadd [0] = HPL_IADD0; iadd [1] = HPL_IADD1;
  121. jseed[0] = ISEED; jseed[1] = 0;
  122. HPL_xjumpm( 1, mult, iadd, jseed, iran1, ia1, ic1 );
  123. HPL_setran( 0, iran1 ); HPL_setran( 1, ia1 ); HPL_setran( 2, ic1 );
  124. /*
  125. * Generate an M by N matrix
  126. */
  127. for( j = 0; j < N; A += incA, j++ )
  128. for( i = 0; i < M; A++, i++ ) *A = HPL_rand();
  129. /*
  130. * End of HPL_dmatgen
  131. */
  132. }