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.

geev.c 8.1 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261
  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. #undef GEEV
  45. #ifndef COMPLEX
  46. #ifdef XDOUBLE
  47. #define GEEV BLASFUNC(qgeev)
  48. #elif defined(DOUBLE)
  49. #define GEEV BLASFUNC(dgeev)
  50. #else
  51. #define GEEV BLASFUNC(sgeev)
  52. #endif
  53. #else
  54. #ifdef XDOUBLE
  55. #define GEEV BLASFUNC(xgeev)
  56. #elif defined(DOUBLE)
  57. #define GEEV BLASFUNC(zgeev)
  58. #else
  59. #define GEEV BLASFUNC(cgeev)
  60. #endif
  61. #endif
  62. #ifndef COMPLEX
  63. extern void GEEV( char* jobvl, char* jobvr, blasint* n, FLOAT* a,
  64. blasint* lda, FLOAT* wr, FLOAT* wi, FLOAT* vl, blasint* ldvl,
  65. FLOAT* vr, blasint* ldvr, FLOAT* work, blasint* lwork, blasint* info );
  66. #else
  67. extern void GEEV( char* jobvl, char* jobvr, blasint* n, FLOAT* a,
  68. blasint* lda, FLOAT* wr, FLOAT* vl, blasint* ldvl,
  69. FLOAT* vr, blasint* ldvr, FLOAT* work, blasint* lwork, FLOAT *rwork, blasint* info );
  70. #endif
  71. #if defined(__WIN32__) || defined(__WIN64__)
  72. #ifndef DELTA_EPOCH_IN_MICROSECS
  73. #define DELTA_EPOCH_IN_MICROSECS 11644473600000000ULL
  74. #endif
  75. int gettimeofday(struct timeval *tv, void *tz){
  76. FILETIME ft;
  77. unsigned __int64 tmpres = 0;
  78. static int tzflag;
  79. if (NULL != tv)
  80. {
  81. GetSystemTimeAsFileTime(&ft);
  82. tmpres |= ft.dwHighDateTime;
  83. tmpres <<= 32;
  84. tmpres |= ft.dwLowDateTime;
  85. /*converting file time to unix epoch*/
  86. tmpres /= 10; /*convert into microseconds*/
  87. tmpres -= DELTA_EPOCH_IN_MICROSECS;
  88. tv->tv_sec = (long)(tmpres / 1000000UL);
  89. tv->tv_usec = (long)(tmpres % 1000000UL);
  90. }
  91. return 0;
  92. }
  93. #endif
  94. #if !defined(__WIN32__) && !defined(__WIN64__) && !defined(__CYGWIN32__) && 0
  95. static void *huge_malloc(BLASLONG size){
  96. int shmid;
  97. void *address;
  98. #ifndef SHM_HUGETLB
  99. #define SHM_HUGETLB 04000
  100. #endif
  101. if ((shmid =shmget(IPC_PRIVATE,
  102. (size + HUGE_PAGESIZE) & ~(HUGE_PAGESIZE - 1),
  103. SHM_HUGETLB | IPC_CREAT |0600)) < 0) {
  104. printf( "Memory allocation failed(shmget).\n");
  105. exit(1);
  106. }
  107. address = shmat(shmid, NULL, SHM_RND);
  108. if ((BLASLONG)address == -1){
  109. printf( "Memory allocation failed(shmat).\n");
  110. exit(1);
  111. }
  112. shmctl(shmid, IPC_RMID, 0);
  113. return address;
  114. }
  115. #define malloc huge_malloc
  116. #endif
  117. int main(int argc, char *argv[]){
  118. FLOAT *a,*vl,*vr,*wi,*wr,*work,*rwork;
  119. FLOAT wkopt[4];
  120. char job='V';
  121. char jobr='N';
  122. char *p;
  123. blasint m, i, j, info,lwork;
  124. double factor = 26.33;
  125. int from = 1;
  126. int to = 200;
  127. int step = 1;
  128. struct timeval start, stop;
  129. double time1;
  130. argc--;argv++;
  131. if (argc > 0) { from = atol(*argv); argc--; argv++;}
  132. if (argc > 0) { to = MAX(atol(*argv), from); argc--; argv++;}
  133. if (argc > 0) { step = atol(*argv); argc--; argv++;}
  134. if ((p = getenv("OPENBLAS_JOB"))) job=*p;
  135. if ( job == 'N' ) factor = 10.0;
  136. fprintf(stderr, "From : %3d To : %3d Step = %3d Job=%c\n", from, to, step,job);
  137. if (( a = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  138. fprintf(stderr,"Out of Memory!!\n");exit(1);
  139. }
  140. if (( vl = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  141. fprintf(stderr,"Out of Memory!!\n");exit(1);
  142. }
  143. if (( vr = (FLOAT *)malloc(sizeof(FLOAT) * to * to * COMPSIZE)) == NULL){
  144. fprintf(stderr,"Out of Memory!!\n");exit(1);
  145. }
  146. if (( wr = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){
  147. fprintf(stderr,"Out of Memory!!\n");exit(1);
  148. }
  149. if (( wi = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){
  150. fprintf(stderr,"Out of Memory!!\n");exit(1);
  151. }
  152. if (( rwork = (FLOAT *)malloc(sizeof(FLOAT) * to * COMPSIZE)) == NULL){
  153. fprintf(stderr,"Out of Memory!!\n");exit(1);
  154. }
  155. for(j = 0; j < to; j++){
  156. for(i = 0; i < to * COMPSIZE; i++){
  157. a[(long)i + (long)j * (long)to * COMPSIZE] = ((FLOAT) rand() / (FLOAT) RAND_MAX) - 0.5;
  158. }
  159. }
  160. lwork = -1;
  161. m=to;
  162. #ifndef COMPLEX
  163. GEEV (&job, &jobr, &m, a, &m, wr, wi, vl, &m, vr, &m, wkopt, &lwork, &info);
  164. #else
  165. GEEV (&job, &jobr, &m, a, &m, wr, vl, &m, vr, &m, wkopt, &lwork,rwork, &info);
  166. #endif
  167. lwork = (blasint)wkopt[0];
  168. if (( work = (FLOAT *)malloc(sizeof(FLOAT) * lwork * COMPSIZE)) == NULL){
  169. fprintf(stderr,"Out of Memory!!\n");exit(1);
  170. }
  171. #ifdef linux
  172. srandom(getpid());
  173. #endif
  174. fprintf(stderr, " SIZE FLops Time Lwork\n");
  175. for(m = from; m <= to; m += step){
  176. fprintf(stderr, " %6d : ", (int)m);
  177. gettimeofday( &start, (struct timezone *)0);
  178. lwork = -1;
  179. #ifndef COMPLEX
  180. GEEV (&job, &jobr, &m, a, &m, wr, wi, vl, &m, vr, &m, wkopt, &lwork, &info);
  181. #else
  182. GEEV (&job, &jobr, &m, a, &m, wr, vl, &m, vr, &m, wkopt, &lwork,rwork, &info);
  183. #endif
  184. lwork = (blasint)wkopt[0];
  185. #ifndef COMPLEX
  186. GEEV (&job, &jobr, &m, a, &m, wr, wi, vl, &m, vr, &m, work, &lwork, &info);
  187. #else
  188. GEEV (&job, &jobr, &m, a, &m, wr, vl, &m, vr, &m, work, &lwork,rwork, &info);
  189. #endif
  190. gettimeofday( &stop, (struct timezone *)0);
  191. if (info) {
  192. fprintf(stderr, "failed to compute eigenvalues .. %d\n", info);
  193. exit(1);
  194. }
  195. time1 = (double)(stop.tv_sec - start.tv_sec) + (double)((stop.tv_usec - start.tv_usec)) * 1.e-6;
  196. fprintf(stderr,
  197. " %10.2f MFlops : %10.2f Sec : %d\n",
  198. COMPSIZE * COMPSIZE * factor * (double)m * (double)m * (double)m / time1 * 1.e-6,time1,lwork);
  199. }
  200. return 0;
  201. }
  202. // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));