HPL_pdmatgen.c 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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_pdmatgen
  53. (
  54. const HPL_T_grid * GRID,
  55. const int M,
  56. const int N,
  57. const int NB,
  58. double * A,
  59. const int LDA,
  60. const int ISEED
  61. )
  62. #else
  63. void HPL_pdmatgen
  64. ( GRID, M, N, NB, A, LDA, ISEED )
  65. const HPL_T_grid * GRID;
  66. const int M;
  67. const int N;
  68. const int NB;
  69. double * A;
  70. const int LDA;
  71. const int ISEED;
  72. #endif
  73. {
  74. /*
  75. * Purpose
  76. * =======
  77. *
  78. * HPL_pdmatgen generates (or regenerates) a parallel random matrix A.
  79. *
  80. * The pseudo-random generator uses the linear congruential algorithm:
  81. * X(n+1) = (a * X(n) + c) mod m as described in the Art of Computer
  82. * Programming, Knuth 1973, Vol. 2.
  83. *
  84. * Arguments
  85. * =========
  86. *
  87. * GRID (local input) const HPL_T_grid *
  88. * On entry, GRID points to the data structure containing the
  89. * process grid information.
  90. *
  91. * M (global input) const int
  92. * On entry, M specifies the number of rows of the matrix A.
  93. * M must be at least zero.
  94. *
  95. * N (global input) const int
  96. * On entry, N specifies the number of columns of the matrix A.
  97. * N must be at least zero.
  98. *
  99. * NB (global input) const int
  100. * On entry, NB specifies the blocking factor used to partition
  101. * and distribute the matrix A. NB must be larger than one.
  102. *
  103. * A (local output) double *
  104. * On entry, A points to an array of dimension (LDA,LocQ(N)).
  105. * On exit, this array contains the coefficients of the randomly
  106. * generated matrix.
  107. *
  108. * LDA (local input) const int
  109. * On entry, LDA specifies the leading dimension of the array A.
  110. * LDA must be at least max(1,LocP(M)).
  111. *
  112. * ISEED (global input) const int
  113. * On entry, ISEED specifies the seed number to generate the
  114. * matrix A. ISEED must be at least zero.
  115. *
  116. * ---------------------------------------------------------------------
  117. */
  118. /*
  119. * .. Local Variables ..
  120. */
  121. int iadd [2], ia1 [2], ia2 [2], ia3 [2],
  122. ia4 [2], ia5 [2], ib1 [2], ib2 [2],
  123. ib3 [2], ic1 [2], ic2 [2], ic3 [2],
  124. ic4 [2], ic5 [2], iran1[2], iran2[2],
  125. iran3[2], iran4[2], itmp1[2], itmp2[2],
  126. itmp3[2], jseed[2], mult [2];
  127. int ib, iblk, ik, jb, jblk, jk, jump1, jump2,
  128. jump3, jump4, jump5, jump6, jump7, lmb,
  129. lnb, mblks, mp, mycol, myrow, nblks,
  130. npcol, nprow, nq;
  131. /* ..
  132. * .. Executable Statements ..
  133. */
  134. (void) HPL_grid_info( GRID, &nprow, &npcol, &myrow, &mycol );
  135. mult [0] = HPL_MULT0; mult [1] = HPL_MULT1;
  136. iadd [0] = HPL_IADD0; iadd [1] = HPL_IADD1;
  137. jseed[0] = ISEED; jseed[1] = 0;
  138. /*
  139. * Generate an M by N matrix starting in process (0,0)
  140. */
  141. Mnumroc( mp, M, NB, NB, myrow, 0, nprow );
  142. Mnumroc( nq, N, NB, NB, mycol, 0, npcol );
  143. if( ( mp <= 0 ) || ( nq <= 0 ) ) return;
  144. /*
  145. * Local number of blocks and size of the last one
  146. */
  147. mblks = ( mp + NB - 1 ) / NB; lmb = mp - ( ( mp - 1 ) / NB ) * NB;
  148. nblks = ( nq + NB - 1 ) / NB; lnb = nq - ( ( nq - 1 ) / NB ) * NB;
  149. /*
  150. * Compute multiplier/adder for various jumps in random sequence
  151. */
  152. jump1 = 1; jump2 = nprow * NB; jump3 = M; jump4 = npcol * NB;
  153. jump5 = NB; jump6 = mycol; jump7 = myrow * NB;
  154. HPL_xjumpm( jump1, mult, iadd, jseed, iran1, ia1, ic1 );
  155. HPL_xjumpm( jump2, mult, iadd, iran1, itmp1, ia2, ic2 );
  156. HPL_xjumpm( jump3, mult, iadd, iran1, itmp1, ia3, ic3 );
  157. HPL_xjumpm( jump4, ia3, ic3, iran1, itmp1, ia4, ic4 );
  158. HPL_xjumpm( jump5, ia3, ic3, iran1, itmp1, ia5, ic5 );
  159. HPL_xjumpm( jump6, ia5, ic5, iran1, itmp3, itmp1, itmp2 );
  160. HPL_xjumpm( jump7, mult, iadd, itmp3, iran1, itmp1, itmp2 );
  161. HPL_setran( 0, iran1 ); HPL_setran( 1, ia1 ); HPL_setran( 2, ic1 );
  162. /*
  163. * Save value of first number in sequence
  164. */
  165. ib1[0] = iran1[0]; ib1[1] = iran1[1];
  166. ib2[0] = iran1[0]; ib2[1] = iran1[1];
  167. ib3[0] = iran1[0]; ib3[1] = iran1[1];
  168. for( jblk = 0; jblk < nblks; jblk++ )
  169. {
  170. jb = ( jblk == nblks - 1 ? lnb : NB );
  171. for( jk = 0; jk < jb; jk++ )
  172. {
  173. for( iblk = 0; iblk < mblks; iblk++ )
  174. {
  175. ib = ( iblk == mblks - 1 ? lmb : NB );
  176. for( ik = 0; ik < ib; A++, ik++ ) *A = HPL_rand();
  177. HPL_jumpit( ia2, ic2, ib1, iran2 );
  178. ib1[0] = iran2[0]; ib1[1] = iran2[1];
  179. }
  180. A += LDA - mp;
  181. HPL_jumpit( ia3, ic3, ib2, iran3 );
  182. ib1[0] = iran3[0]; ib1[1] = iran3[1];
  183. ib2[0] = iran3[0]; ib2[1] = iran3[1];
  184. }
  185. HPL_jumpit( ia4, ic4, ib3, iran4 );
  186. ib1[0] = iran4[0]; ib1[1] = iran4[1];
  187. ib2[0] = iran4[0]; ib2[1] = iran4[1];
  188. ib3[0] = iran4[0]; ib3[1] = iran4[1];
  189. }
  190. /*
  191. * End of HPL_pdmatgen
  192. */
  193. }