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.

potrf.c 8.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250
  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 POTRF
  41. #ifndef COMPLEX
  42. #ifdef XDOUBLE
  43. #define POTRF BLASFUNC(qpotrf)
  44. #define POTRS BLASFUNC(qpotrs)
  45. #define POTRI BLASFUNC(qpotri)
  46. #define SYRK BLASFUNC(qsyrk)
  47. #elif defined(DOUBLE)
  48. #define POTRF BLASFUNC(dpotrf)
  49. #define POTRS BLASFUNC(dpotrs)
  50. #define POTRI BLASFUNC(dpotri)
  51. #define SYRK BLASFUNC(dsyrk)
  52. #else
  53. #define POTRF BLASFUNC(spotrf)
  54. #define POTRS BLASFUNC(spotrs)
  55. #define POTRI BLASFUNC(spotri)
  56. #define SYRK BLASFUNC(ssyrk)
  57. #endif
  58. #else
  59. #ifdef XDOUBLE
  60. #define POTRF BLASFUNC(xpotrf)
  61. #define POTRS BLASFUNC(xpotrs)
  62. #define POTRI BLASFUNC(xpotri)
  63. #define SYRK BLASFUNC(xherk)
  64. #elif defined(DOUBLE)
  65. #define POTRF BLASFUNC(zpotrf)
  66. #define POTRS BLASFUNC(zpotrs)
  67. #define POTRI BLASFUNC(zpotri)
  68. #define SYRK BLASFUNC(zherk)
  69. #else
  70. #define POTRF BLASFUNC(cpotrf)
  71. #define POTRS BLASFUNC(cpotrs)
  72. #define POTRI BLASFUNC(cpotri)
  73. #define SYRK BLASFUNC(cherk)
  74. #endif
  75. #endif
  76. // extern void POTRI(char *uplo, blasint *m, FLOAT *a, blasint *lda, blasint *info);
  77. // extern void POTRS(char *uplo, blasint *m, blasint *n, FLOAT *a, blasint *lda, FLOAT *b, blasint *ldb, blasint *info);
  78. int main(int argc, char *argv[]){
  79. #ifndef COMPLEX
  80. char *trans[] = {"T", "N"};
  81. #else
  82. char *trans[] = {"C", "N"};
  83. #endif
  84. char *uplo[] = {"U", "L"};
  85. FLOAT alpha[] = {1.0, 0.0};
  86. FLOAT beta [] = {0.0, 0.0};
  87. FLOAT *a, *b;
  88. char *p;
  89. char btest = 'F';
  90. blasint m, i, j, info, uplos=0;
  91. double flops;
  92. int from = 1;
  93. int to = 200;
  94. int step = 1;
  95. double time1;
  96. argc--;argv++;
  97. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  98. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  99. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  100. if ((p = getenv("OPENBLAS_UPLO")))
  101. if (*p == 'L') uplos=1;
  102. if ((p = getenv("OPENBLAS_TEST"))) btest=*p;
  103. fprintf(stderr, "From : %3d To : %3d Step = %3d Uplo = %c\n", from, to, step,*uplo[uplos]);
  104. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  105. fprintf(stderr,"Out of Memory!!\n");exit(1);
  106. }
  107. if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  108. fprintf(stderr,"Out of Memory!!\n");exit(1);
  109. }
  110. for(m = from; m <= to; m += step){
  111. #ifndef COMPLEX
  112. if (uplos & 1) {
  113. for (j = 0; j < m; j++) {
  114. for(i = 0; i < j; i++) a[(long)i + (long)j * (long)m] = 0.;
  115. a[(long)j + (long)j * (long)m] = ((double) rand() / (double) RAND_MAX) + 8.;
  116. for(i = j + 1; i < m; i++) a[(long)i + (long)j * (long)m] = ((double) rand() / (double) RAND_MAX) - 0.5;
  117. }
  118. } else {
  119. for (j = 0; j < m; j++) {
  120. for(i = 0; i < j; i++) a[(long)i + (long)j * (long)m] = ((double) rand() / (double) RAND_MAX) - 0.5;
  121. a[(long)j + (long)j * (long)m] = ((double) rand() / (double) RAND_MAX) + 8.;
  122. for(i = j + 1; i < m; i++) a[(long)i + (long)j * (long)m] = 0.;
  123. }
  124. }
  125. #else
  126. if (uplos & 1) {
  127. for (j = 0; j < m; j++) {
  128. for(i = 0; i < j; i++) {
  129. a[((long)i + (long)j * (long)m) * 2 + 0] = 0.;
  130. a[((long)i + (long)j * (long)m) * 2 + 1] = 0.;
  131. }
  132. a[((long)j + (long)j * (long)m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) + 8.;
  133. a[((long)j + (long)j * (long)m) * 2 + 1] = 0.;
  134. for(i = j + 1; i < m; i++) {
  135. a[((long)i + (long)j * (long)m) * 2 + 0] = 0;
  136. a[((long)i + (long)j * (long)m) * 2 + 1] = ((double) rand() / (double) RAND_MAX) - 0.5;
  137. }
  138. }
  139. } else {
  140. for (j = 0; j < m; j++) {
  141. for(i = 0; i < j; i++) {
  142. a[((long)i + (long)j * (long)m) * 2 + 0] = 0.;
  143. a[((long)i + (long)j * (long)m) * 2 + 1] = ((double) rand() / (double) RAND_MAX) - 0.5;
  144. }
  145. a[((long)j + (long)j * (long)m) * 2 + 0] = ((double) rand() / (double) RAND_MAX) + 8.;
  146. a[((long)j + (long)j * (long)m) * 2 + 1] = 0.;
  147. for(i = j + 1; i < m; i++) {
  148. a[((long)i + (long)j * (long)m) * 2 + 0] = 0.;
  149. a[((long)i + (long)j * (long)m) * 2 + 1] = 0.;
  150. }
  151. }
  152. }
  153. #endif
  154. SYRK(uplo[uplos], trans[uplos], &m, &m, alpha, a, &m, beta, b, &m);
  155. begin();
  156. POTRF(uplo[uplos], &m, b, &m, &info);
  157. end();
  158. if (info != 0) {
  159. fprintf(stderr, "Potrf info = %d\n", info);
  160. exit(1);
  161. }
  162. time1 = getsec();
  163. flops = COMPSIZE * COMPSIZE * (1.0/3.0 * (double)m * (double)m *(double)m +1.0/2.0* (double)m *(double)m + 1.0/6.0* (double)m) / time1 * 1.e-6;
  164. if ( btest == 'S' )
  165. {
  166. for(j = 0; j < to; j++){
  167. for(i = 0; i < to * COMPSIZE; i++){
  168. a[i + j * to * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  169. }
  170. }
  171. begin();
  172. POTRS(uplo[uplos], &m, &m, b, &m, a, &m, &info);
  173. end();
  174. if (info != 0) {
  175. fprintf(stderr, "Potrs info = %d\n", info);
  176. exit(1);
  177. }
  178. time1 = getsec();
  179. flops = COMPSIZE * COMPSIZE * (2.0 * (double)m * (double)m *(double)m ) / time1 * 1.e-6;
  180. }
  181. if ( btest == 'I' )
  182. {
  183. begin();
  184. POTRI(uplo[uplos], &m, b, &m, &info);
  185. end();
  186. if (info != 0) {
  187. fprintf(stderr, "Potri info = %d\n", info);
  188. exit(1);
  189. }
  190. time1 = getsec();
  191. flops = COMPSIZE * COMPSIZE * (2.0/3.0 * (double)m * (double)m *(double)m +1.0/2.0* (double)m *(double)m + 5.0/6.0* (double)m) / time1 * 1.e-6;
  192. }
  193. fprintf(stderr, "%8d : %10.2f MFlops : %10.3f Sec : Test=%c\n",m,flops ,time1,btest);
  194. }
  195. return 0;
  196. }
  197. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));