pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
cblas_dgemm_stripe.c
Go to the documentation of this file.
1 /*
2  Copyright (C) 2008-2010 Robert Higgins
3  Author: Robert Higgins <robert.higgins@ucd.ie>
4 
5  This file is part of PMM.
6 
7  PMM is free software: you can redistribute it and/or modify
8  it under the terms of the GNU General Public License as published by
9  the Free Software Foundation, either version 3 of the License, or
10  (at your option) any later version.
11 
12  PMM is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  GNU General Public License for more details.
16 
17  You should have received a copy of the GNU General Public License
18  along with PMM. If not, see <http://www.gnu.org/licenses/>.
19 */
20 #include <stdlib.h>
21 #include <stdio.h>
22 #include <cblas.h>
23 
24 #include "pmm_util.h"
25 
26 #define NARGS 2
27 
28 /*
29  * this version of the dgemm benchmark is for the multiplciation of two
30  * matrices simulating a striped decomposition. A is an mxn (rowsxcols) stripe
31  * of some hypothetical nxn matrix, B is a full nxn matric, and the result C is
32  * an mxn stripe of the hypothetical result.
33  *
34  * The first input parameter is the size of the full B matrix, n (of nxn). The
35  * second parameter is the size of the stripe of A/C m (of mxn)
36  */
37 int main(int argc, char **argv) {
38 
39 
40  /* declare variables */
41  double *a, *b, *c;
42  double arg[NARGS];
43  size_t m, n;
44  unsigned int i;
45  long long int complexity;
46 
47  /* parse arguments */
48  if(argc != NARGS+1) {
49  return PMM_EXIT_ARGFAIL;
50  }
51  if(sscanf(argv[1], "%lf", &(arg[0])) == 0 ||
52  sscanf(argv[2], "%lf", &(arg[1])) == 0) {
53  return PMM_EXIT_ARGPARSEFAIL;
54  }
55 
56  n = (size_t)arg[0];
57  m = (size_t)arg[1];
58 
59  if(n<m) {
60  printf("Size of matrix N must be greater/equal to size of stripe.\n");
61  return PMM_EXIT_ARGFAIL;
62  }
63 
64  /* calculate complexity */
65  complexity = 2*n*m*(long long int)n;
66 
67  /* initialise data */
68  a = malloc(m*n * sizeof *a);
69  b = malloc(n*n * sizeof *b);
70  c = malloc(m*n * sizeof *c);
71 
72  // fill the stripes
73  for(i=0; i<m*n; i++) {
74  a[i] = 2.0;
75  b[i] = 1.0;
76  c[i] = 0.0;
77  }
78  // fill the rest of b
79  for(;i<n*n; i++) {
80  b[i] = 1.0;
81  }
82 
83  /* initialise timer */
84  pmm_timer_init(complexity);
85 
86  /* start timer */
88 
89  /* execute routine */
90  cblas_dgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, m, n, n, 1.0, a, n, b, n, 0.0, c, n);
91 
92  /* stop timer */
94 
95  /* get timing result */
97 
98  /* destroy timer */
100 
101  free(a);
102  a = NULL;
103  free(b);
104  b = NULL;
105  free(c);
106  c = NULL;
107 
108  return PMM_EXIT_SUCCESS;
109 }