HPL_dlaswp10N.c 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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. * Define default value for unrolling factor
  53. */
  54. #ifndef HPL_LASWP10N_DEPTH
  55. #define HPL_LASWP10N_DEPTH 32
  56. #define HPL_LASWP10N_LOG2_DEPTH 5
  57. #endif
  58. #ifdef STDC_HEADERS
  59. void HPL_dlaswp10N
  60. (
  61. const int M,
  62. const int N,
  63. double * A,
  64. const int LDA,
  65. const int * IPIV
  66. )
  67. #else
  68. void HPL_dlaswp10N
  69. ( M, N, A, LDA, IPIV )
  70. const int M;
  71. const int N;
  72. double * A;
  73. const int LDA;
  74. const int * IPIV;
  75. #endif
  76. {
  77. /*
  78. * Purpose
  79. * =======
  80. *
  81. * HPL_dlaswp10N performs a sequence of local column interchanges on a
  82. * matrix A. One column interchange is initiated for columns 0 through
  83. * N-1 of A.
  84. *
  85. * Arguments
  86. * =========
  87. *
  88. * M (local input) const int
  89. * __arg0__
  90. *
  91. * N (local input) const int
  92. * On entry, M specifies the number of rows of the array A. M
  93. * must be at least zero.
  94. *
  95. * A (local input/output) double *
  96. * On entry, N specifies the number of columns of the array A. N
  97. * must be at least zero.
  98. *
  99. * LDA (local input) const int
  100. * On entry, A points to an array of dimension (LDA,N). This
  101. * array contains the columns onto which the interchanges should
  102. * be applied. On exit, A contains the permuted matrix.
  103. *
  104. * IPIV (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 r;
  114. double * a0, * a1;
  115. const int incA = ( 1 << HPL_LASWP10N_LOG2_DEPTH );
  116. int jp, mr, mu;
  117. register int i, j;
  118. /* ..
  119. * .. Executable Statements ..
  120. */
  121. if( ( M <= 0 ) || ( N <= 0 ) ) return;
  122. mr = M - ( mu = (int)( ( (unsigned int)(M) >> HPL_LASWP10N_LOG2_DEPTH )
  123. << HPL_LASWP10N_LOG2_DEPTH ) );
  124. for( j = 0; j < N; j++ )
  125. {
  126. if( j != ( jp = IPIV[j] ) )
  127. {
  128. a0 = A + j * LDA; a1 = A + jp * LDA;
  129. for( i = 0; i < mu; i += incA, a0 += incA, a1 += incA )
  130. {
  131. r = *a0; *a0 = *a1; *a1 = r;
  132. #if ( HPL_LASWP10N_DEPTH > 1 )
  133. r = a0[ 1]; a0[ 1] = a1[ 1]; a1[ 1] = r;
  134. #endif
  135. #if ( HPL_LASWP10N_DEPTH > 2 )
  136. r = a0[ 2]; a0[ 2] = a1[ 2]; a1[ 2] = r;
  137. r = a0[ 3]; a0[ 3] = a1[ 3]; a1[ 3] = r;
  138. #endif
  139. #if ( HPL_LASWP10N_DEPTH > 4 )
  140. r = a0[ 4]; a0[ 4] = a1[ 4]; a1[ 4] = r;
  141. r = a0[ 5]; a0[ 5] = a1[ 5]; a1[ 5] = r;
  142. r = a0[ 6]; a0[ 6] = a1[ 6]; a1[ 6] = r;
  143. r = a0[ 7]; a0[ 7] = a1[ 7]; a1[ 7] = r;
  144. #endif
  145. #if ( HPL_LASWP10N_DEPTH > 8 )
  146. r = a0[ 8]; a0[ 8] = a1[ 8]; a1[ 8] = r;
  147. r = a0[ 9]; a0[ 9] = a1[ 9]; a1[ 9] = r;
  148. r = a0[10]; a0[10] = a1[10]; a1[10] = r;
  149. r = a0[11]; a0[11] = a1[11]; a1[11] = r;
  150. r = a0[12]; a0[12] = a1[12]; a1[12] = r;
  151. r = a0[13]; a0[13] = a1[13]; a1[13] = r;
  152. r = a0[14]; a0[14] = a1[14]; a1[14] = r;
  153. r = a0[15]; a0[15] = a1[15]; a1[15] = r;
  154. #endif
  155. #if ( HPL_LASWP10N_DEPTH > 16 )
  156. r = a0[16]; a0[16] = a1[16]; a1[16] = r;
  157. r = a0[17]; a0[17] = a1[17]; a1[17] = r;
  158. r = a0[18]; a0[18] = a1[18]; a1[18] = r;
  159. r = a0[19]; a0[19] = a1[19]; a1[19] = r;
  160. r = a0[20]; a0[20] = a1[20]; a1[20] = r;
  161. r = a0[21]; a0[21] = a1[21]; a1[21] = r;
  162. r = a0[22]; a0[22] = a1[22]; a1[22] = r;
  163. r = a0[23]; a0[23] = a1[23]; a1[23] = r;
  164. r = a0[24]; a0[24] = a1[24]; a1[24] = r;
  165. r = a0[25]; a0[25] = a1[25]; a1[25] = r;
  166. r = a0[26]; a0[26] = a1[26]; a1[26] = r;
  167. r = a0[27]; a0[27] = a1[27]; a1[27] = r;
  168. r = a0[28]; a0[28] = a1[28]; a1[28] = r;
  169. r = a0[29]; a0[29] = a1[29]; a1[29] = r;
  170. r = a0[30]; a0[30] = a1[30]; a1[30] = r;
  171. r = a0[31]; a0[31] = a1[31]; a1[31] = r;
  172. #endif
  173. }
  174. for( i = 0; i < mr; i++ )
  175. { r = a0[i]; a0[i] = a1[i]; a1[i] = r; }
  176. }
  177. }
  178. /*
  179. * End of HPL_dlaswp10N
  180. */
  181. }