cleanup, parameters from 1, decrease matrix size
[blas_decision:mainline.git] / benchmarks / zgemm.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include "../selection.h"
4
5 #define SIZE    1024
6 static void zgemm_prepare(void);
7 static void zgemm_cleanup(void);
8 static void zgemm_benchmark(void); 
9 static int  zgemm_next_parameter(void);
10 static void zgemm_print_header(FILE *fd);
11 static void zgemm_print_parameters(FILE *fd);
12
13 struct benchmark zgemm_bench = {
14                   "zgemm_",
15                   zgemm_prepare,
16                   zgemm_benchmark,
17                   zgemm_cleanup,
18                   zgemm_next_parameter,
19                   zgemm_print_header,
20                   zgemm_print_parameters,
21                   NULL,
22                   NULL 
23                 };
24
25 typedef struct {
26         double r, i;
27 } doublecomplex;
28
29
30 typedef void (prototype_)(char *transa, char *transb, int *m, int *n, int *k, doublecomplex *alpha, doublecomplex *a, int *lda, doublecomplex *b, int *ldb, doublecomplex *beta, doublecomplex *c, int *ldc);
31
32 struct zgemm_internal {
33         doublecomplex *A, *B, *C;
34         doublecomplex *alpha, *beta;
35         int m, n, k, lda, ldb, ldc;
36         char t1, t2;
37
38 };
39
40 static void zgemm_prepare(void)
41 {
42         struct zgemm_internal *zi;
43         zi = malloc(sizeof(struct zgemm_internal));
44
45         zi->A = (doublecomplex *) malloc_random_double(sizeof(doublecomplex) * SIZE * SIZE);
46         zi->B = (doublecomplex *) malloc_random_double(sizeof(doublecomplex) * SIZE * SIZE);
47         zi->C = (doublecomplex *) malloc_random_double(sizeof(doublecomplex) * SIZE * SIZE);
48         zi->alpha = (doublecomplex *) malloc_random_double(sizeof(doublecomplex));
49         zi->beta = (doublecomplex *) malloc_random_double(sizeof(doublecomplex));
50
51         zi->lda = SIZE;
52         zi->ldb = SIZE;
53         zi->ldc = SIZE;
54         zi->m = 1;
55         zi->n = 1;
56         zi->k = 1;
57         zi->t1 = 'n';
58         zi->t2 = 'n';
59
60         zgemm_bench.internal = zi;
61 }
62
63 static void zgemm_cleanup() 
64 {
65         struct zgemm_internal *zi;
66
67         zi = zgemm_bench.internal;
68         free(zi->A);
69         free(zi->B);
70         free(zi->C);
71         free(zi->alpha);
72         free(zi->beta);
73         free(zi);
74         zgemm_bench.internal = NULL;
75 }
76
77 static int zgemm_next_parameter(void)
78 {
79         struct zgemm_internal *zi;
80         
81         zi = zgemm_bench.internal;
82
83         zi->n *= 2;
84         zi->k *= 2;
85         if (zi->k <= SIZE) return 1;
86         zi->n = 1;
87         zi->k = 1;
88
89         zi->m *= 2;
90         if (zi->m <= SIZE) return 1;
91         zi->m = 1;
92
93 /*      zi->n *= 2;
94         if (zi->n <= SIZE) return 1;
95         zi->n = 2;*/
96
97         switch (zi->t1) {
98         case 'n':
99                 zi->t1 = 't';
100                 return 1;
101         case 't':
102                 zi->t1 = 'c';
103                 return 1;
104         case 'c':
105                 zi->t1 = 'n';
106         }
107
108         switch (zi->t2) {
109         case 'n':
110                 zi->t2 = 't';
111                 return 1;
112         case 't':
113                 zi->t2 = 'c';
114                 return 1;
115         case 'c':
116                 zi->t2 = 'n';
117         }
118         return 0;
119 }
120
121 static void zgemm_print_header(FILE *fd) {
122         fprintf(fd, "#t1\tt2\tm\tn\tk\tlda\tldb\tldc\ttime\n");
123 }
124
125 static void zgemm_print_parameters(FILE *fd) 
126 {
127         struct zgemm_internal *zi;
128         zi = zgemm_bench.internal;
129         fprintf(fd, "%c\t%c\t% 3d\t% 3d\t% 3d\t% 4d\t% 4d\t% 4d\t", 
130                         zi->t1, zi->t2, zi->m, zi->n, zi->k, zi->lda, zi->ldb, zi->ldc);
131 }
132
133 static void zgemm_benchmark(void) 
134 {
135         struct zgemm_internal *zi;
136         prototype_ *f;
137         zi = zgemm_bench.internal;
138
139         f = (prototype_ *)zgemm_bench.function;
140
141         (*f)(&zi->t1,
142                  &zi->t2,
143                  &zi->m, 
144                  &zi->n,
145                  &zi->k, 
146                   zi->alpha,
147                   zi->A,
148                  &zi->lda,
149                   zi->B,
150                  &zi->ldb,
151                   zi->beta, 
152                   zi->C,
153                  &zi->ldc);
154 }