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.

gesv.c 6.5 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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 GESV
  46. #undef GETRS
  47. #ifndef COMPLEX
  48. #ifdef XDOUBLE
  49. #define GESV BLASFUNC(qgesv)
  50. #elif defined(DOUBLE)
  51. #define GESV BLASFUNC(dgesv)
  52. #else
  53. #define GESV BLASFUNC(sgesv)
  54. #endif
  55. #else
  56. #ifdef XDOUBLE
  57. #define GESV BLASFUNC(xgesv)
  58. #elif defined(DOUBLE)
  59. #define GESV BLASFUNC(zgesv)
  60. #else
  61. #define GESV BLASFUNC(cgesv)
  62. #endif
  63. #endif
  64. #if defined(__WIN32__) || defined(__WIN64__)
  65. #ifndef DELTA_EPOCH_IN_MICROSECS
  66. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  67. #endif
  68. int gettimeofday(struct timeval *tv, void *tz){
  69. FILETIME ft;
  70. unsigned __int64 tmpres = 0;
  71. static int tzflag;
  72. if (NULL != tv)
  73. {
  74. GetSystemTimeAsFileTime(&ft);
  75. tmpres |= ft.dwHighDateTime;
  76. tmpres <<= 32;
  77. tmpres |= ft.dwLowDateTime;
  78. /*converting file time to unix epoch*/
  79. tmpres /= 10; /*convert into microseconds*/
  80. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  81. tv->tv_sec = (long)(tmpres / 1000000UL);
  82. tv->tv_usec = (long)(tmpres % 1000000UL);
  83. }
  84. return 0;
  85. }
  86. #endif
  87. #if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
  88. static void *huge_malloc(BLASLONG size){
  89. int shmid;
  90. void *address;
  91. #ifndef SHM_HUGETLB
  92. #define SHM_HUGETLB 04000
  93. #endif
  94. if ((shmid =shmget(IPC_PRIVATE,
  95. (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
  96. SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
  97. printf( "Memory allocation failed(shmget).\n");
  98. exit(1);
  99. }
  100. address = shmat(shmid, NULL, SHM_RND);
  101. if ((BLASLONG)address == -1){
  102. printf( "Memory allocation failed(shmat).\n");
  103. exit(1);
  104. }
  105. shmctl(shmid, IPC_RMID, 0);
  106. return address;
  107. }
  108. #define malloc huge_malloc
  109. #endif
  110. int main(int argc, char *argv[]){
  111. FLOAT *a, *b;
  112. blasint *ipiv;
  113. blasint m, i, j, info;
  114. int from = 1;
  115. int to = 200;
  116. int step = 1;
  117. struct timeval start, stop;
  118. double time1;
  119. argc--;argv++;
  120. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  121. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  122. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  123. fprintf(stderr, "From : %3d To : %3d Step = %3d\n", from, to, step);
  124. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  125. fprintf(stderr,"Out of Memory!!\n");exit(1);
  126. }
  127. if (( b = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  128. fprintf(stderr,"Out of Memory!!\n");exit(1);
  129. }
  130. if (( ipiv = (blasint *)malloc(sizeof(blasint) * to * COMPSIZE)) == NULL){
  131. fprintf(stderr,"Out of Memory!!\n");exit(1);
  132. }
  133. #ifdef __linux
  134. srandom(getpid());
  135. #endif
  136. fprintf(stderr, " SIZE Flops Time\n");
  137. for(m = from; m <= to; m += step){
  138. fprintf(stderr, " %dx%d : ", (int)m, (int)m);
  139. for(j = 0; j < m; j++){
  140. for(i = 0; i < m * COMPSIZE; i++){
  141. a[(long)i + (long)j * (long)m * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  142. }
  143. }
  144. for(j = 0; j < m; j++){
  145. for(i = 0; i < m * COMPSIZE; i++){
  146. b[(long)i + (long)j * (long)m * COMPSIZE] = 0.0;
  147. }
  148. }
  149. for (j = 0; j < m; ++j) {
  150. for (i = 0; i < m * COMPSIZE; ++i) {
  151. b[i] += a[(long)i + (long)j * (long)m * COMPSIZE];
  152. }
  153. }
  154. gettimeofday( &start, (struct timezone *)0);
  155. GESV (&m, &m, a, &m, ipiv, b, &m, &info);
  156. gettimeofday( &stop, (struct timezone *)0);
  157. time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
  158. fprintf(stderr,
  159. "%10.2f MFlops %10.6f s\n",
  160. COMPSIZE * COMPSIZE * (2. / 3. * (double)m * (double)m * (double)m + 2. * (double)m * (double)m * (double)m ) / (time1) * 1.e-6 , time1);
  161. }
  162. return 0;
  163. }
  164. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));