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 9.1 kB

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