home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / lib / mathlib / libfft / TRY / r_speed3d.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.1 KB  |  232 lines

  1. #include <stdio.h>
  2. #include <sys/time.h>
  3.  
  4. #include "fft.h"
  5. #include "constant.h"
  6.  
  7. /*
  8. *   Precision Dependant declarations
  9. */
  10.  
  11. #ifdef DOUBLE
  12.  
  13. typedef double this_type;
  14. typedef double this_half;
  15.  
  16. #define        TOLERANCE        DTOLERANCE
  17. #define        THIS_GEN        dgen_
  18. #define        THIS_FFTI        dfft3di
  19. #define        THIS_FFTUI        dfft3dui
  20. #define        THIS_SCAL        dscal3d
  21. #define        THIS_FFT        dfft3d
  22. #define        THIS_FFTU        dfft3du
  23.  
  24. #endif
  25.  
  26. #ifdef SINGLE
  27.  
  28. typedef float this_type;
  29. typedef float this_half;
  30.  
  31. #define        TOLERANCE        STOLERANCE
  32. #define        THIS_GEN        sgen_
  33. #define        THIS_FFTI        sfft3di
  34. #define        THIS_FFTUI        sfft3dui
  35. #define        THIS_SCAL        sscal3d
  36. #define        THIS_FFT        sfft3d
  37. #define        THIS_FFTU        sfft3du
  38.  
  39. #endif
  40.  
  41. /*    */
  42.  
  43. void inimat_();
  44. void GetArguments();
  45. void get_values();
  46.  
  47. int min_size, max_size, inc_size, size, size_x, size_y, size_z;
  48. this_type *pa, *pSave, *pt;
  49.  
  50. int is_timing;
  51.  
  52. static     long z_sec, z_usec;
  53. static int first_time = 1;
  54.  
  55. float second()
  56. {
  57.         struct timeval s_val;
  58.     struct timezone s_z;
  59.     float time;
  60.     long n_sec, n_usec;
  61.         gettimeofday(&s_val, &s_z);
  62.     n_sec = s_val.tv_sec;
  63.     n_usec = s_val.tv_usec;
  64.     if( first_time ) {
  65.         z_sec = n_sec;
  66.         z_usec = n_usec;
  67.         first_time =0;
  68.     }
  69.     time = (float)(n_sec-z_sec) + (float)(n_usec -z_usec) * 1.0E-6;
  70.     return( time );
  71. }
  72.  
  73. main(argc,argv)
  74. int argc;
  75. char *argv[];
  76. {
  77.     int i, j, k, n_total, is_wrong, nx, ny, nz, inc, n_times, n_flops, ld1, ld2;
  78.     double x, y, t, emax;
  79.     this_half ratio;
  80.  
  81. /* ******************************************************* */
  82.     GetArguments( argc, argv);
  83. /* ******************************************************* */
  84.  
  85.     srandom( (123*getpid()) | 0x01);
  86.  
  87.     for( size=min_size ; size <= max_size ; size *= inc_size) { 
  88.  
  89.     nx = (size_x) ? size_x : size;
  90.     ny = (size_y) ? size_y : size;
  91.     nz = (size_z) ? size_z : size;
  92.     ld1 = nx+2;
  93.     ld2 = ny+1;
  94.     n_total = ld1*ld2*nz;
  95.     pa = (this_type *)malloc( (n_total + nx + 3*ny + 3*nz + 10*FACTOR_SPACE) * sizeof(this_type));
  96.     if( !(pa) ) {
  97.         fprintf( stderr, "Could not allocate ... Exiting\n");
  98.         exit (-1);
  99.     }
  100.  
  101.     fflush(stdout);
  102.  
  103.     printf( "%4d  ", size);
  104.  
  105.     n_flops = (int) (5. * (double)(nx*ny*nz)/2. * (log((double)(nx*ny*nz))/log(2.) -1.));
  106.     n_times = (int) (MAX_FLOPS / (double)n_flops);
  107.     if(n_times < 1) n_times =1;
  108.     ratio = 1./(double)(nx*ny*nz);
  109. /* *******************************************************
  110. ******************************************************* */
  111.     pSave = pa + n_total;
  112.  
  113.     THIS_GEN(pa, &n_total);
  114.  
  115.     inc =1 ;
  116. /* *******************************************************
  117.     pSave = THIS_FFTI( nx,ny,nz, pSave);
  118.  
  119.     t = second();
  120.     for ( i = 0 ; i < n_times ; i++)  {
  121.         is_wrong = THIS_FFT( -1, nx, ny, nz, pa, ld1, ld2, pSave);
  122.         is_wrong = THIS_FFT(  1, nx, ny, nz, pa, ld1, ld2, pSave);
  123.         THIS_SCAL( nx, ny, nz, ratio, pa, ld1, ld2);
  124.     }
  125.     t = second() - t;
  126.  
  127.     if( is_timing)
  128.         x = t / (double)(2*n_times);
  129.     else
  130.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  131.  
  132.     printf("%6.3e  ", x);
  133. ******************************************************* */
  134. /* *******************************************************
  135. ******************************************************* */
  136.     pSave = THIS_FFTUI( nx,ny,nz, pSave);
  137.  
  138.     t = second();
  139.     for ( i = 0 ; i < n_times ; i++)  {
  140.         is_wrong = THIS_FFTU( -1, nx, ny, nz, pa, ld1, ld2, pSave);
  141.         is_wrong = THIS_FFTU(  1, nx, ny, nz, pa, ld1, ld2, pSave);
  142.         THIS_SCAL( nx, ny, nz, ratio, pa, ld1, ld2);
  143.     }
  144.     t = second() - t;
  145.  
  146.     if( is_timing)
  147.         x = t / (double)(2*n_times);
  148.     else
  149.         x = (t > 0) ? (((double)(2*n_times) * (double)(n_flops)*1.e-6) / t) : 0.0;
  150.  
  151.     printf("%6.3e  ", x);
  152. /* *******************************************************
  153. ******************************************************* */
  154.     printf("\n");
  155.     free(pa);
  156.     }
  157.     return(0);
  158. }
  159.  
  160. int is_random;
  161.  
  162. void GetArguments( argc, argv)
  163. int argc;
  164. char *argv[];
  165. {
  166.     int i, j, k;
  167.     int nerror = 0;
  168.  
  169. #define ON    1
  170.  
  171.     max_size = MAX_SIZE;
  172.     min_size = MIN_SIZE;
  173.     inc_size = INC_SIZE;
  174.  
  175.     is_timing = 0;
  176.     size_x = 0;
  177.     size_y = 0;
  178.     size_z = 0;
  179.  
  180. /* ******************************************************* */
  181.     for ( i = 1 ; (i < argc) && (nerror != ON) ; i ++ ) {
  182.     if( argv[i][0] == '-') {
  183.         switch ( argv[i][1]) {
  184.         case 'x' :
  185.         case 'X' :  
  186.                 if( i+1 > argc)
  187.                 nerror = ON;
  188.                 else
  189.                 size_x = atoi( argv[++i]);
  190.                 break;
  191.         case 'y' :
  192.         case 'Y' :  
  193.                 if( i+1 > argc)
  194.                 nerror = ON;
  195.                 else
  196.                 size_y = atoi( argv[++i]);
  197.                 break;
  198.         case 'z' :
  199.         case 'Z' :  
  200.                 if( i+1 > argc)
  201.                 nerror = ON;
  202.                 else
  203.                 size_z = atoi( argv[++i]);
  204.                 break;
  205.         case 't' :
  206.         case 'T' :  
  207.                 is_timing = 1;
  208.                 break;
  209.         default  :  nerror = ON;
  210.         }
  211.     }
  212.     else {
  213.         if( i+1 > argc)
  214.         nerror = ON;
  215.         else { 
  216.         min_size = atoi( argv[i++]);
  217.         max_size = atoi( argv[i++]);
  218.         inc_size = atoi( argv[i]);
  219.         }
  220.     }
  221.     }
  222.     if( nerror == ON) {
  223.     fprintf( stderr, 
  224.         "Usage : %s [-p(arallel)] [n_trials]\n", argv[0]);
  225.     exit(-1);
  226.     }
  227.     if ( is_timing) 
  228.         fprintf( stderr, "Checking Performance   in Secs\n");
  229.     else
  230.         fprintf( stderr, "Checking Performance   in Mflops\n");
  231. }
  232.