pmm  1.0.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
dsyrk.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 "config.h"
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include "pmm_util.h"
24 //#include <gsl/gsl_matrix.h>
25 #include <gsl/gsl_blas.h>
26 
27 #ifdef HAVE_SETAFFINITY
28  #include <sched.h>
29 #endif
30 
31 #define NARGS 1
32 
33 int main(int argc, char **argv) {
34 
35 
36  /* declare variables */
37  gsl_matrix *A, *C;
38  double arg;
39  size_t n;
40  unsigned int i,j;
41  long long complexity;
42 
43 #ifdef HAVE_SETAFFINITY
44  cpu_set_t aff_mask;
45 #endif
46 
47 
48  /* parse arguments */
49  if(argc != NARGS+1) {
50  return PMM_EXIT_ARGFAIL;
51  }
52  if(sscanf(argv[1], "%lf", &arg) == 0) {
53  return PMM_EXIT_ARGPARSEFAIL;
54  }
55 
56  n = (size_t)arg;
57 
58  /* calculate complexity */
59  complexity = n*n*(long long)n;
60 
61 #ifdef HAVE_SETAFFINITY
62  /* set processor affinity */
63  CPU_ZERO(&aff_mask);
64  CPU_SET(0, &aff_mask);
65 
66  if(sched_setaffinity(0, sizeof(aff_mask), &aff_mask) < 0) {
67  printf("could not set affinity!\n");
68  return PMM_EXIT_ARGFAIL;
69  }
70 #endif
71 
72 
73 
74  /* initialise data */
75  A = gsl_matrix_alloc(n, n);
76  C = gsl_matrix_alloc(n, n);
77 
78 
79  for(i=0; i<n; i++) {
80  for(j=0; j<n; j++) {
81  gsl_matrix_set(A, i, j, 10.0*(rand()/((double)RAND_MAX+1)));
82 
83  if(j<n-i) {
84  gsl_matrix_set(C, i, j, 10.0*(rand()/((double)RAND_MAX+1)));
85  }
86  }
87  }
88  //gsl_matrix_set_all(A, 2.5);
89  //gsl_matrix_set_all(C, 7.3);
90 
91  /* initialise timer */
92  pmm_timer_init(complexity);
93 
94  /* start timer */
96 
97  /* execute routine */
98  gsl_blas_dsyrk(CblasUpper, CblasNoTrans, 1.0, A, 1.0, C);
99 
100  /* stop timer */
101  pmm_timer_stop();
102 
103  /* get timing result */
105 
106  /* destroy timer */
108 
109  gsl_matrix_free(A);
110  gsl_matrix_free(C);
111 
112  return PMM_EXIT_SUCCESS;
113 }