You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

linpack.c 6.3 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202
  1. /*********************************************************************/
  2. /* Copyright 2009, 2010 The University of Texas at Austin. */
  3. /* All rights reserved. */
  4. /* */
  5. /* Redistribution and use in source and binary forms, with or */
  6. /* without modification, are permitted provided that the following */
  7. /* conditions are met: */
  8. /* */
  9. /* 1. Redistributions of source code must retain the above */
  10. /* copyright notice, this list of conditions and the following */
  11. /* disclaimer. */
  12. /* */
  13. /* 2. Redistributions in binary form must reproduce the above */
  14. /* copyright notice, this list of conditions and the following */
  15. /* disclaimer in the documentation and/or other materials */
  16. /* provided with the distribution. */
  17. /* */
  18. /* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY OF TEXAS AT */
  19. /* AUSTIN ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, */
  20. /* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF */
  21. /* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE */
  22. /* DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OF TEXAS AT */
  23. /* AUSTIN OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, */
  24. /* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES */
  25. /* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE */
  26. /* GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR */
  27. /* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF */
  28. /* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT */
  29. /* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT */
  30. /* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE */
  31. /* POSSIBILITY OF SUCH DAMAGE. */
  32. /* */
  33. /* The views and conclusions contained in the software and */
  34. /* documentation are those of the authors and should not be */
  35. /* interpreted as representing official policies, either expressed */
  36. /* or implied, of The University of Texas at Austin. */
  37. /*********************************************************************/
  38. #include "bench.h"
  39. double fabs(double);
  40. #undef GETRF
  41. #undef GETRS
  42. #ifndef COMPLEX
  43. #ifdef XDOUBLE
  44. #define GETRF BLASFUNC(qgetrf)
  45. #define GETRS BLASFUNC(qgetrs)
  46. #elif defined(DOUBLE)
  47. #define GETRF BLASFUNC(dgetrf)
  48. #define GETRS BLASFUNC(dgetrs)
  49. #else
  50. #define GETRF BLASFUNC(sgetrf)
  51. #define GETRS BLASFUNC(sgetrs)
  52. #endif
  53. #else
  54. #ifdef XDOUBLE
  55. #define GETRF BLASFUNC(xgetrf)
  56. #define GETRS BLASFUNC(xgetrs)
  57. #elif defined(DOUBLE)
  58. #define GETRF BLASFUNC(zgetrf)
  59. #define GETRS BLASFUNC(zgetrs)
  60. #else
  61. #define GETRF BLASFUNC(cgetrf)
  62. #define GETRS BLASFUNC(cgetrs)
  63. #endif
  64. #endif
  65. int main(int argc, char *argv[]){
  66. FLOAT *a, *b;
  67. blasint *ipiv;
  68. blasint m, i, j, info;
  69. blasint unit = 1;
  70. int from = 1;
  71. int to = 200;
  72. int step = 1;
  73. FLOAT maxerr;
  74. double time1, time2;
  75. argc--;argv++;
  76. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  77. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  78. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  79. fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
  80. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  81. fprintf(stderr,"Out of Memory!!\n");exit(1);
  82. }
  83. if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){
  84. fprintf(stderr,"Out of Memory!!\n");exit(1);
  85. }
  86. if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){
  87. fprintf(stderr,"Out of Memory!!\n");exit(1);
  88. }
  89. #ifdef __linux
  90. srandom(getpid());
  91. #endif
  92. fprintf(stderr, " SIZE Residual Decompose Solve Total\n");
  93. for(m = from; m <= to; m += step){
  94. fprintf(stderr, " %6d : ", (int)m);
  95. for(j = 0; j < m; j++){
  96. for(i = 0; i < m * COMPSIZE; i++){
  97. a[(long)i + (long)j * (long)m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  98. }
  99. }
  100. for (i = 0; i < m * COMPSIZE; ++i) b[i] = 0.;
  101. for (j = 0; j < m; ++j) {
  102. for (i = 0; i < m * COMPSIZE; ++i) {
  103. b[i] += a[(long)i + (long)j * (long)m * COMPSIZE];
  104. }
  105. }
  106. begin();
  107. GETRF (&m, &m, a, &m, ipiv, &info);
  108. end();
  109. if (info) {
  110. fprintf(stderr, "Matrix is not singular .. %d\n", info);
  111. exit(1);
  112. }
  113. time1 = getsec();
  114. begin();
  115. GETRS("N", &m, &unit, a, &m, ipiv, b, &m, &info);
  116. end();
  117. if (info) {
  118. fprintf(stderr, "Matrix is not singular .. %d\n", info);
  119. exit(1);
  120. }
  121. time2 = getsec();
  122. maxerr = 0.;
  123. for(i = 0; i < m; i++){
  124. #ifndef XDOUBLE
  125. if (maxerr < fabs(b[i * COMPSIZE] - 1.0)) maxerr = fabs(b[i * COMPSIZE] - 1.0);
  126. #ifdef COMPLEX
  127. if (maxerr < fabs(b[i * COMPSIZE] + 1)) maxerr = fabs(b[i * COMPSIZE + 1]);
  128. #endif
  129. #else
  130. if (maxerr < fabsl(b[i * COMPSIZE] - 1.0L)) maxerr = fabsl(b[i * COMPSIZE] - 1.0L);
  131. #ifdef COMPLEX
  132. if (maxerr < fabsl(b[i * COMPSIZE] + 1)) maxerr = fabsl(b[i * COMPSIZE + 1]);
  133. #endif
  134. #endif
  135. }
  136. #ifdef XDOUBLE
  137. fprintf(stderr," %Le ", maxerr);
  138. #else
  139. fprintf(stderr," %e ", maxerr);
  140. #endif
  141. fprintf(stderr,
  142. " %10.2f MFlops %10.2f MFlops %10.2f MFlops\n",
  143. COMPSIZE * COMPSIZE * 2. / 3. * (double)m * (double)m * (double)m / time1 * 1.e-6,
  144. COMPSIZE * COMPSIZE * 2. * (double)m * (double)m / time2 * 1.e-6,
  145. COMPSIZE * COMPSIZE * (2. / 3. * (double)m * (double)m * (double)m + 2. * (double)m * (double)m) / (time1 + time2) * 1.e-6);
  146. #if 0
  147. if (
  148. #ifdef DOUBLE
  149. maxerr > 1.e-8
  150. #else
  151. maxerr > 1.e-1
  152. #endif
  153. ) {
  154. fprintf(stderr, "Error is too large.\n");
  155. exit(1);
  156. }
  157. #endif
  158. }
  159. return 0;
  160. }
  161. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));