1 #include <stdio.h>
2 #include <stdlib.h>
3 
mysub(int n,double * x,double * y)4 void mysub(int n, double *x, double *y)
5 {
6     return;
7 }
8 
9 volatile double _dummy;
10 
main()11 int main()
12 {
13     /* Parameters */
14 #define NMAX    1000
15 #define ITS     100000
16 
17     int      i, j, iters;
18     double   alpha, avg, t1, t2, tnotim;
19     double   x[NMAX], y[NMAX];
20     double   SuperLU_timer_();
21 
22     /* Initialize X and Y */
23     for (i = 0; i < NMAX; ++i) {
24 	x[i] = 1.0 / (double)(i+1);
25 	y[i] = (double)(NMAX - i) / (double)NMAX;
26     }
27     alpha = 0.315;
28 
29     /* Time DAXPY operations */
30     iters = ITS;
31     tnotim = 0.0;
32     while ( tnotim <= 0.0 ) {
33       t1 = SuperLU_timer_();
34       for (j = 0; j < iters; ++j) {
35 	for (i = 0; i < NMAX; ++i) y[i] += alpha * x[i];
36 	alpha = -alpha;
37 	_dummy = y[j%NMAX];
38       }
39       t2 = SuperLU_timer_();
40       tnotim = t2 - t1;
41       if ( tnotim > 0. ){
42 	float ops = 2.0 * iters * NMAX * 1e-9;
43         printf("Time for %d DAXPYs = %10.6g seconds\n",
44 	       iters, tnotim);
45 	printf("DAXPY performance rate = %10.6g Gflops\n", ops/tnotim);
46       } else {
47         /* this makes sure we dont keep trying forever */
48         if ( iters > 100000000 ) {
49           printf("*** Error: Time for operations was zero.\n"
50                  "\tThe timer may not be working correctly.\n");
51           /*exit(9);*/
52         }
53         iters *= 10;
54       }
55     }
56 
57     /* Force gcc not to optimize away the previous loop (DCS) */
58     printf("y[0]=%g\n", y[0]) ;
59 
60     t1 = SuperLU_timer_();
61     for (j = 0; j < ITS; ++j) {
62 	for (i = 0; i < NMAX; ++i)
63 	    y[i] += alpha * x[i];
64 	alpha = -alpha;
65     }
66     t2 = SuperLU_timer_();
67     tnotim = t2 - t1;
68 
69     /* Time 1,000,000 DAXPY operations with SuperLU_timer_()
70        in the outer loop */
71     t1 = SuperLU_timer_();
72     for (j = 0; j < ITS; ++j) {
73 	for (i = 0; i < NMAX; ++i)
74 	    y[i] += alpha * x[i];
75 	alpha = -alpha;
76 	t2 = SuperLU_timer_();
77     }
78 
79     /* Compute the time in milliseconds used by an average call to
80        SuperLU_timer_(). */
81     printf("Including DSECND, time        = %10.3g seconds\n", t2-t1);
82     avg = ( (t2 - t1) - tnotim )*1000. / (double)ITS;
83     printf("Average time for DSECND       = %10.3g milliseconds\n", avg);
84 
85     /* Compute the equivalent number of floating point operations used
86        by an average call to DSECND.    */
87     if ( tnotim > 0. )
88 	printf("Equivalent floating point ops = %10.3g ops\n",
89 	       1000.*avg / tnotim);
90 
91     mysub(NMAX, x, y);
92     return 0;
93 }
94 
95