pmm
1.0.0
Main Page
Data Structures
Files
File List
Globals
All
Data Structures
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Macros
routines
lapack
double
dpotrf.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 <time.h>
23
#include <cblas.h>
24
#include "
pmm_util.h
"
25
26
#ifndef ATLAS_ORDER
27
#define ATLAS_ORDER CBLAS_ORDER
28
#endif
29
#ifndef ATLAS_UPLO
30
#define ATLAS_UPLO CBLAS_UPLO
31
#endif
32
#ifndef ATLAS_DIAG
33
#define ATLAS_DIAG CBLAS_DIAG
34
#endif
35
36
#include <atlas/clapack.h>
37
38
#define NARGS 1
39
40
/*
41
* this benchmark is for the dpotrf cholesky factorization function of lapack
42
*/
43
44
int
main
(
int
argc,
char
**argv) {
45
46
47
/* declare variables */
48
double
*A;
/* random matrix A */
49
double
*B;
/* postive definite matrix B (derived from A) */
50
long
long
int
c;
/* complexity */
51
int
n;
/* matrix size of side */
52
int
i, j;
/* indexes */
53
int
ret;
/* dpotrf return status */
54
char
uplo;
55
char
trans;
56
double
alpha, beta;
57
58
59
/* parse arguments */
60
if
(argc !=
NARGS
+1) {
61
return
PMM_EXIT_ARGFAIL
;
62
}
63
if
(sscanf(argv[1],
"%d"
, &n) == 0) {
64
return
PMM_EXIT_ARGPARSEFAIL
;
65
}
66
67
/* calculate complexity */
68
c = (n*n*(
long
long
int)n)/3;
69
70
71
/* allocate array */
72
A = malloc((n * n) *
sizeof
*A);
73
B = malloc((n * n) *
sizeof
*B);
74
if
(A == NULL || B == NULL) {
75
printf(
"Could not allocate memory.\n"
);
76
return
PMM_EXIT_ALLOCFAIL
;
77
}
78
79
/* initialise data */
80
//srand(time(NULL));
81
for
(i=0; i<n; i++) {
82
83
for
(j=0;j<n; j++) {
84
/* column major order */
85
A[n*j+i] = 10.0*(rand()/((double)RAND_MAX+1));
86
}
87
}
88
uplo =
'l'
;
89
trans =
't'
;
90
alpha=1.0;
91
beta=0.0;
92
93
/* making positive definite matrix ... */
94
/* dsyrk_(&uplo, &trans, &n, &n, &alpha, A, &n, &beta, B, &n); */
95
cblas_dsyrk(CblasColMajor, CblasUpper, CblasTrans, n, n, alpha, A, n, beta, B, n);
96
97
/*
98
for(i=0; i<n; i++) {
99
for(j=0; j<n; j++) {
100
printf("%d:%f ", n*j+1, B[n*j+i]);
101
}
102
printf("\n");
103
}
104
*/
105
106
107
free(A);
108
109
// ensure any part of B that is paged out is now paged back in again
110
for
(i=0; i<n*n; i++) {
111
alpha = B[i];
112
}
113
114
115
/* initialise timer */
116
pmm_timer_init
(c);
117
118
/* start timer */
119
pmm_timer_start
();
120
121
/* execute routine */
122
/* dpotrf_(&uplo, &n, B, &n, &ret); */
123
ret = clapack_dpotrf(CblasColMajor, CblasUpper, n, B, n);
124
125
/* stop timer */
126
pmm_timer_stop
();
127
128
/* check dpotrf return */
129
/*
130
for(i=0; i<n; i++) {
131
for(j=0; j<n; j++) {
132
printf("%lf ", B[n*j+i]);
133
}
134
printf("\n");
135
}
136
*/
137
138
if
(ret != 0) {
139
printf(
"Error calling dpotrf: %d\n"
, ret);
140
free(B);
141
142
return
PMM_EXIT_EXEFAIL
;
143
}
144
145
/* get timing result */
146
pmm_timer_result
();
147
148
/* destroy timer */
149
pmm_timer_destroy
();
150
151
free(B);
152
153
return
PMM_EXIT_SUCCESS
;
154
}
Generated on Fri Apr 5 2013 18:25:32 for pmm by
1.8.1.2