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