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.6 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  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, l, info;
  69. blasint unit = 1;
  70. int from = 1;
  71. int to = 200;
  72. int step = 1;
  73. int loops = 1;
  74. FLOAT maxerr;
  75. double time1, time2, timeg1,timeg2;
  76. char *p;
  77. if ((p = getenv("OPENBLAS_LOOPS"))) loops=atoi(p);
  78. argc--;argv++;
  79. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  80. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  81. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  82. fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
  83. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  84. fprintf(stderr,"Out of Memory!!\n");exit(1);
  85. }
  86. if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){
  87. fprintf(stderr,"Out of Memory!!\n");exit(1);
  88. }
  89. if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){
  90. fprintf(stderr,"Out of Memory!!\n");exit(1);
  91. }
  92. #ifdef __linux
  93. srandom(getpid());
  94. #endif
  95. fprintf(stderr, " SIZE Residual Decompose Solve Total\n");
  96. for(m = from; m <= to; m += step){
  97. timeg1 = timeg2 = 0.;
  98. fprintf(stderr, " %6d : ", (int)m);
  99. for (l = 0; l < loops; l++) {
  100. for(j = 0; j < m; j++){
  101. for(i = 0; i < m * COMPSIZE; i++){
  102. a[(long)i + (long)j * (long)m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  103. }
  104. }
  105. for (i = 0; i < m * COMPSIZE; ++i) b[i] = 0.;
  106. for (j = 0; j < m; ++j) {
  107. for (i = 0; i < m * COMPSIZE; ++i) {
  108. b[i] += a[(long)i + (long)j * (long)m * COMPSIZE];
  109. }
  110. }
  111. begin();
  112. GETRF (&m, &m, a, &m, ipiv, &info);
  113. end();
  114. if (info) {
  115. fprintf(stderr, "Matrix is not singular .. %d\n", info);
  116. exit(1);
  117. }
  118. timeg1 += getsec();
  119. begin();
  120. GETRS("N", &m, &unit, a, &m, ipiv, b, &m, &info);
  121. end();
  122. if (info) {
  123. fprintf(stderr, "Matrix is not singular .. %d\n", info);
  124. exit(1);
  125. }
  126. timeg2 += getsec();
  127. } //loops
  128. time1=timeg1/(double)loops;
  129. time2=timeg2/(double)loops;
  130. maxerr = 0.;
  131. for(i = 0; i < m; i++){
  132. #ifndef XDOUBLE
  133. if (maxerr < fabs(b[i * COMPSIZE] - 1.0)) maxerr = fabs(b[i * COMPSIZE] - 1.0);
  134. #ifdef COMPLEX
  135. if (maxerr < fabs(b[i * COMPSIZE] + 1)) maxerr = fabs(b[i * COMPSIZE + 1]);
  136. #endif
  137. #else
  138. if (maxerr < fabsl(b[i * COMPSIZE] - 1.0L)) maxerr = fabsl(b[i * COMPSIZE] - 1.0L);
  139. #ifdef COMPLEX
  140. if (maxerr < fabsl(b[i * COMPSIZE] + 1)) maxerr = fabsl(b[i * COMPSIZE + 1]);
  141. #endif
  142. #endif
  143. }
  144. #ifdef XDOUBLE
  145. fprintf(stderr," %Le ", maxerr);
  146. #else
  147. fprintf(stderr," %e ", maxerr);
  148. #endif
  149. fprintf(stderr,
  150. " %10.2f MFlops %10.2f MFlops %10.2f MFlops\n",
  151. COMPSIZE * COMPSIZE * 2. / 3. * (double)m * (double)m * (double)m / time1 * 1.e-6,
  152. COMPSIZE * COMPSIZE * 2. * (double)m * (double)m / time2 * 1.e-6,
  153. COMPSIZE * COMPSIZE * (2. / 3. * (double)m * (double)m * (double)m + 2. * (double)m * (double)m) / (time1 + time2) * 1.e-6);
  154. #if 0
  155. if (
  156. #ifdef DOUBLE
  157. maxerr > 1.e-8
  158. #else
  159. maxerr > 1.e-1
  160. #endif
  161. ) {
  162. fprintf(stderr, "Error is too large.\n");
  163. exit(1);
  164. }
  165. #endif
  166. }
  167. return 0;
  168. }
  169. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));