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.

trsv.c 4.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. /***************************************************************************
  2. Copyright (c) 2014, The OpenBLAS Project
  3. All rights reserved.
  4. Redistribution and use in source and binary forms, with or without
  5. modification, are permitted provided that the following conditions are
  6. met:
  7. 1. Redistributions of source code must retain the above copyright
  8. notice, this list of conditions and the following disclaimer.
  9. 2. Redistributions in binary form must reproduce the above copyright
  10. notice, this list of conditions and the following disclaimer in
  11. the documentation and/or other materials provided with the
  12. distribution.
  13. 3. Neither the name of the OpenBLAS project nor the names of
  14. its contributors may be used to endorse or promote products
  15. derived from this software without specific prior written permission.
  16. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
  17. AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  18. IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  19. ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
  20. LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  21. DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
  22. SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
  23. CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  24. OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  25. USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  26. *****************************************************************************/
  27. #include "bench.h"
  28. #undef GEMV
  29. #undef TRSV
  30. #ifndef COMPLEX
  31. #ifdef DOUBLE
  32. #define TRSV BLASFUNC(dtrsv)
  33. #else
  34. #define TRSV BLASFUNC(strsv)
  35. #endif
  36. #else
  37. #ifdef DOUBLE
  38. #define TRSV BLASFUNC(ztrsv)
  39. #else
  40. #define TRSV BLASFUNC(ctrsv)
  41. #endif
  42. #endif
  43. int main(int argc, char *argv[]){
  44. FLOAT *a, *x;
  45. blasint n = 0, i, j;
  46. blasint inc_x=1;
  47. int loops = 1;
  48. int l;
  49. char *p;
  50. int from = 1;
  51. int to = 200;
  52. int step = 1;
  53. time_t seconds = 0;
  54. double time1,timeg;
  55. long long nanos = 0;
  56. argc--;argv++;
  57. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  58. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  59. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  60. char uplo ='L';
  61. char transa = 'N';
  62. char diag ='U';
  63. if ((p = getenv("OPENBLAS_LOOPS"))) loops = atoi(p);
  64. if ((p = getenv("OPENBLAS_INCX"))) inc_x = atoi(p);
  65. if ((p = getenv("OPENBLAS_TRANSA"))) transa=*p;
  66. if ((p = getenv("OPENBLAS_DIAG"))) diag=*p;
  67. if ((p = getenv("OPENBLAS_UPLO"))) uplo=*p;
  68. fprintf(stderr, "From : %3d To : %3d Step = %3d Transa = '%c' Inc_x = %d uplo=%c diag=%c loop = %d\n", from, to, step,transa,inc_x,
  69. uplo,diag,loops);
  70. #ifdef __linux
  71. srandom(getpid());
  72. #endif
  73. fprintf(stderr, " SIZE Flops\n");
  74. fprintf(stderr, "============================================\n");
  75. for(n = from; n <= to; n += step)
  76. {
  77. timeg=0;
  78. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * n * n * COMPSIZE)) == NULL){
  79. fprintf(stderr,"Out of Memory!!\n");exit(1);
  80. }
  81. if (( x = (FLOAT *)malloc(sizeof(FLOAT) * n * abs(inc_x) * COMPSIZE)) == NULL){
  82. fprintf(stderr,"Out of Memory!!\n");exit(1);
  83. }
  84. for(j = 0; j < n; j++){
  85. for(i = 0; i < n * COMPSIZE; i++){
  86. a[i + j * n * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  87. }
  88. }
  89. for(i = 0; i < n * COMPSIZE * abs(inc_x); i++){
  90. x[i] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  91. }
  92. for(l =0;l< loops;l++){
  93. begin();
  94. TRSV(&uplo,&transa,&diag,&n,a,&n,x,&inc_x);
  95. end();
  96. time1 = getsec();
  97. timeg += time1;
  98. }
  99. timeg /= loops;
  100. long long muls = n*(n+1)/2.0;
  101. long long adds = (n - 1.0)*n/2.0;
  102. fprintf(stderr, "%10d %10.2f MFlops %10.6f sec\n", n,(muls+adds) / timeg * 1.e-6, timeg);
  103. if(a != NULL){
  104. free(a);
  105. }
  106. if( x != NULL){
  107. free(x);
  108. }
  109. }
  110. return 0;
  111. }