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.

getri.c 5.9 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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. #undef GETRF
  40. #undef GETRI
  41. #ifndef COMPLEX
  42. #ifdef XDOUBLE
  43. #define GETRF BLASFUNC(qgetrf)
  44. #define GETRI BLASFUNC(qgetri)
  45. #elif defined(DOUBLE)
  46. #define GETRF BLASFUNC(dgetrf)
  47. #define GETRI BLASFUNC(dgetri)
  48. #else
  49. #define GETRF BLASFUNC(sgetrf)
  50. #define GETRI BLASFUNC(sgetri)
  51. #endif
  52. #else
  53. #ifdef XDOUBLE
  54. #define GETRF BLASFUNC(xgetrf)
  55. #define GETRI BLASFUNC(xgetri)
  56. #elif defined(DOUBLE)
  57. #define GETRF BLASFUNC(zgetrf)
  58. #define GETRI BLASFUNC(zgetri)
  59. #else
  60. #define GETRF BLASFUNC(cgetrf)
  61. #define GETRI BLASFUNC(cgetri)
  62. #endif
  63. #endif
  64. extern void GETRI(blasint *m, FLOAT *a, blasint *lda, blasint *ipiv, FLOAT *work, blasint *lwork, blasint *info);
  65. int main(int argc, char *argv[]){
  66. FLOAT *a,*work;
  67. FLOAT wkopt[4];
  68. blasint *ipiv;
  69. blasint m, i, j, l, info,lwork;
  70. int from = 1;
  71. int to = 200;
  72. int step = 1;
  73. int loops = 1;
  74. double time1,timeg;
  75. char *p;
  76. char btest = 'I';
  77. argc--;argv++;
  78. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  79. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  80. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  81. if ((p = getenv("OPENBLAS_TEST"))) btest=*p;
  82. if ((p = getenv("OPENBLAS_LOOPS"))) loops=atoi(p);
  83. fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
  84. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  85. fprintf(stderr,"Out of Memory!!\n");exit(1);
  86. }
  87. if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){
  88. fprintf(stderr,"Out of Memory!!\n");exit(1);
  89. }
  90. for(j = 0; j < to; j++){
  91. for(i = 0; i < to * COMPSIZE; i++){
  92. a[(long)i + (long)j * (long)to * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  93. }
  94. }
  95. lwork = -1;
  96. m=to;
  97. GETRI(&m, a, &m, ipiv, wkopt, &lwork, &info);
  98. lwork = (blasint)wkopt[0];
  99. if (( work = (FLOAT *)malloc(sizeof(FLOAT) * lwork * COMPSIZE)) == NULL){
  100. fprintf(stderr,"Out of Memory!!\n");exit(1);
  101. }
  102. #ifdef __linux
  103. srandom(getpid());
  104. #endif
  105. fprintf(stderr, " SIZE FLops Time Lwork\n");
  106. for(m = from; m <= to; m += step){
  107. timeg = 0.;
  108. fprintf(stderr, " %6d : ", (int)m);
  109. for (l = 0; l < loops; l++) {
  110. if (btest == 'F') begin();
  111. GETRF (&m, &m, a, &m, ipiv, &info);
  112. if (btest == 'F') {
  113. end();
  114. timeg += getsec();
  115. }
  116. if (info) {
  117. fprintf(stderr, "Matrix is not singular .. %d\n", info);
  118. exit(1);
  119. }
  120. if (btest == 'I') begin();
  121. lwork = -1;
  122. GETRI(&m, a, &m, ipiv, wkopt, &lwork, &info);
  123. lwork = (blasint)wkopt[0];
  124. GETRI(&m, a, &m, ipiv, work, &lwork, &info);
  125. if (btest == 'I') end();
  126. if (info) {
  127. fprintf(stderr, "failed compute inverse matrix .. %d\n", info);
  128. exit(1);
  129. }
  130. if (btest == 'I')
  131. timeg += getsec();
  132. } // loops
  133. time1 = timeg/(double)loops;
  134. fprintf(stderr,
  135. " %10.2f MFlops : %10.2f Sec : %d\n",
  136. COMPSIZE * COMPSIZE * (4.0/3.0 * (double)m * (double)m *(double)m - (double)m *(double)m + 5.0/3.0* (double)m) / time1 * 1.e-6,time1,lwork);
  137. }
  138. return 0;
  139. }
  140. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));