1 /***************************************************************************
2 Copyright (c) 2014, The OpenBLAS Project
3 All rights reserved.
4 Redistribution and use in source and binary forms, with or without
5 modification, are permitted provided that the following conditions are
6 met:
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9 2. Redistributions in binary form must reproduce the above copyright
10 notice, this list of conditions and the following disclaimer in
11 the documentation and/or other materials provided with the
12 distribution.
13 3. Neither the name of the OpenBLAS project nor the names of
14 its contributors may be used to endorse or promote products
15 derived from this software without specific prior written permission.
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 ARE DISCLAIMED. IN NO EVENT SHALL THE OPENBLAS PROJECT OR CONTRIBUTORS BE
20 LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
25 USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *****************************************************************************/
27
28 #include "bench.h"
29
30 #undef ASUM
31
32 #ifdef COMPLEX
33 #ifdef DOUBLE
34 #define ASUM BLASFUNC(dzasum)
35 #else
36 #define ASUM BLASFUNC(scasum)
37 #endif
38 #else
39 #ifdef DOUBLE
40 #define ASUM BLASFUNC(dasum)
41 #else
42 #define ASUM BLASFUNC(sasum)
43 #endif
44 #endif
45
main(int argc,char * argv[])46 int main(int argc, char *argv[])
47 {
48
49 FLOAT *x;
50 FLOAT result;
51 blasint m, i;
52 blasint inc_x = 1;
53 int loops = 1;
54 int l;
55 char *p;
56
57 int from = 1;
58 int to = 200;
59 int step = 1;
60 double time1, timeg;
61
62 argc--;
63 argv++;
64
65 if (argc > 0)
66 {
67 from = atol(*argv);
68 argc--;
69 argv++;
70 }
71 if (argc > 0)
72 {
73 to = MAX(atol(*argv), from);
74 argc--;
75 argv++;
76 }
77 if (argc > 0)
78 {
79 step = atol(*argv);
80 argc--;
81 argv++;
82 }
83
84 if ((p = getenv("OPENBLAS_LOOPS")))
85 loops = atoi(p);
86 if ((p = getenv("OPENBLAS_INCX")))
87 inc_x = atoi(p);
88
89 fprintf(stderr, "From : %3d To : %3d Step = %3d Inc_x = %d Loops = %d\n", from, to, step, inc_x, loops);
90
91 if ((x = (FLOAT *)malloc(sizeof(FLOAT) * to * abs(inc_x) * COMPSIZE)) == NULL)
92 {
93 fprintf(stderr, "Out of Memory!!\n");
94 exit(1);
95 }
96
97 #ifdef __linux
98 srandom(getpid());
99 #endif
100
101 fprintf(stderr, " SIZE Flops\n");
102
103 for (m = from; m <= to; m += step)
104 {
105
106 timeg = 0;
107
108 fprintf(stderr, " %6d : ", (int)m);
109
110 for (l = 0; l < loops; l++)
111 {
112
113 for (i = 0; i < m * COMPSIZE * abs(inc_x); i++)
114 {
115 x[i] = ((FLOAT)rand() / (FLOAT)RAND_MAX) - 0.5;
116 }
117 begin();
118 result = ASUM(&m, x, &inc_x);
119 end();
120 timeg += getsec();
121 }
122 if (loops > 1)
123 timeg /= loops;
124
125 #ifdef COMPLEX
126 fprintf(stderr, " %10.2f MFlops %10.6f sec\n", 4. * (double)m / timeg * 1.e-6, timeg);
127 #else
128 fprintf(stderr, " %10.2f MFlops %10.6f sec\n", 2. * (double)m / timeg * 1.e-6, timeg);
129 #endif
130 }
131
132 return 0;
133 }
134
135 // void main(int argc, char *argv[]) __attribute__((weak, alias("MAIN__")));
136