MAGMA  magma-1.4.0
Matrix Algebra on GPU and Multicore Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
testing_dsytrd.cpp File Reference
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <cuda_runtime_api.h>
#include <cublas.h>
#include "flops.h"
#include "magma.h"
#include "magma_lapack.h"
#include "testings.h"
Include dependency graph for testing_dsytrd.cpp:

Go to the source code of this file.

Macros

#define PRECISION_d
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define PRECISION_d

Definition at line 28 of file testing_dsytrd.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file testing_dsytrd.cpp.

References magma_opts::check, FLOPS_DSYTRD, h_A, magma_opts::lapack, lapackf77_dlacpy(), lapackf77_dlamch, lapackf77_dlarnv(), lapackf77_dorgtr(), lapackf77_dsyt21(), lapackf77_dsytrd(), magma_dmake_symmetric(), magma_dsytrd(), magma_get_dsytrd_nb(), magma_strerror(), magma_wtime(), MagmaUpperLowerStr, magma_opts::niter, magma_opts::nsize, magma_opts::ntest, parse_opts(), TESTING_FINALIZE, TESTING_FREE, TESTING_HOSTALLOC, TESTING_HOSTFREE, TESTING_INIT, TESTING_MALLOC, magma_opts::tolerance, and magma_opts::uplo.

34 {
35  TESTING_INIT();
36 
37  real_Double_t gflops, gpu_perf, cpu_perf, gpu_time, cpu_time;
38  double eps;
39  double *h_A, *h_R, *h_Q, *h_work, *work;
40  double *tau;
41  double *diag, *offdiag;
42  double result[2] = {0., 0.};
43  magma_int_t N, n2, lda, lwork, info, nb;
44  magma_int_t ione = 1;
45  magma_int_t itwo = 2;
46  magma_int_t ithree = 3;
47  magma_int_t ISEED[4] = {0,0,0,1};
48  magma_int_t status = 0;
49 
50  #if defined(PRECISION_z) || defined(PRECISION_c)
51  double *rwork;
52  #endif
53 
54  eps = lapackf77_dlamch( "E" );
55 
56  magma_opts opts;
57  parse_opts( argc, argv, &opts );
58 
59  double tol = opts.tolerance * lapackf77_dlamch("E");
60 
61  printf(" N CPU GFlop/s (sec) GPU GFlop/s (sec) |A-QHQ'|/N|A| |I-QQ'|/N\n");
62  printf("===========================================================================\n");
63  for( int i = 0; i < opts.ntest; ++i ) {
64  for( int iter = 0; iter < opts.niter; ++iter ) {
65  N = opts.nsize[i];
66  lda = N;
67  n2 = N*lda;
68  nb = magma_get_dsytrd_nb(N);
69  lwork = N*nb; /* We suppose the magma nb is bigger than lapack nb */
70  gflops = FLOPS_DSYTRD( N ) / 1e9;
71 
72  TESTING_MALLOC( h_A, double, lda*N );
73  TESTING_HOSTALLOC( h_R, double, lda*N );
74  TESTING_HOSTALLOC( h_work, double, lwork );
75  TESTING_MALLOC( tau, double, N );
76  TESTING_MALLOC( diag, double, N );
77  TESTING_MALLOC( offdiag, double, N-1 );
78 
79  if ( opts.check ) {
80  TESTING_MALLOC( h_Q, double, lda*N );
81  TESTING_MALLOC( work, double, 2*N*N );
82  #if defined(PRECISION_z) || defined(PRECISION_c)
83  TESTING_MALLOC( rwork, double, N );
84  #endif
85  }
86 
87  /* ====================================================================
88  Initialize the matrix
89  =================================================================== */
90  lapackf77_dlarnv( &ione, ISEED, &n2, h_A );
91  magma_dmake_symmetric( N, h_A, lda );
92  lapackf77_dlacpy( MagmaUpperLowerStr, &N, &N, h_A, &lda, h_R, &lda );
93 
94  /* ====================================================================
95  Performs operation using MAGMA
96  =================================================================== */
97  gpu_time = magma_wtime();
98  magma_dsytrd( opts.uplo, N, h_R, lda, diag, offdiag,
99  tau, h_work, lwork, &info );
100  gpu_time = magma_wtime() - gpu_time;
101  gpu_perf = gflops / gpu_time;
102  if (info != 0)
103  printf("magma_dsytrd returned error %d: %s.\n",
104  (int) info, magma_strerror( info ));
105 
106  /* =====================================================================
107  Check the factorization
108  =================================================================== */
109  if ( opts.check ) {
110  lapackf77_dlacpy( &opts.uplo, &N, &N, h_R, &lda, h_Q, &lda );
111  lapackf77_dorgtr( &opts.uplo, &N, h_Q, &lda, tau, h_work, &lwork, &info );
112 
113  #if defined(PRECISION_z) || defined(PRECISION_c)
114  lapackf77_dsyt21( &itwo, &opts.uplo, &N, &ione,
115  h_A, &lda, diag, offdiag,
116  h_Q, &lda, h_R, &lda,
117  tau, work, rwork, &result[0] );
118 
119  lapackf77_dsyt21( &ithree, &opts.uplo, &N, &ione,
120  h_A, &lda, diag, offdiag,
121  h_Q, &lda, h_R, &lda,
122  tau, work, rwork, &result[1] );
123  #else
124  lapackf77_dsyt21( &itwo, &opts.uplo, &N, &ione,
125  h_A, &lda, diag, offdiag,
126  h_Q, &lda, h_R, &lda,
127  tau, work, &result[0] );
128 
129  lapackf77_dsyt21( &ithree, &opts.uplo, &N, &ione,
130  h_A, &lda, diag, offdiag,
131  h_Q, &lda, h_R, &lda,
132  tau, work, &result[1] );
133  #endif
134  }
135 
136  /* =====================================================================
137  Performs operation using LAPACK
138  =================================================================== */
139  if ( opts.lapack ) {
140  cpu_time = magma_wtime();
141  lapackf77_dsytrd( &opts.uplo, &N, h_A, &lda, diag, offdiag, tau,
142  h_work, &lwork, &info );
143  cpu_time = magma_wtime() - cpu_time;
144  cpu_perf = gflops / cpu_time;
145  if (info != 0)
146  printf("lapackf77_dsytrd returned error %d: %s.\n",
147  (int) info, magma_strerror( info ));
148  }
149 
150  /* =====================================================================
151  Print performance and error.
152  =================================================================== */
153  if ( opts.lapack ) {
154  printf("%5d %7.2f (%7.2f) %7.2f (%7.2f)",
155  (int) N, cpu_perf, cpu_time, gpu_perf, gpu_time );
156  } else {
157  printf("%5d --- ( --- ) %7.2f (%7.2f)",
158  (int) N, gpu_perf, gpu_time );
159  }
160  if ( opts.check ) {
161  printf(" %8.2e %8.2e%s\n", result[0]*eps, result[1]*eps,
162  ( ( (result[0]*eps < tol) && (result[1]*eps < tol) ) ? "" : " failed") );
163  status |= ! (result[0]*eps < tol);
164  status |= ! (result[1]*eps < tol);
165 
166  } else {
167  printf(" --- ---\n");
168  }
169 
170  TESTING_FREE( h_A );
171  TESTING_FREE( tau );
172  TESTING_FREE( diag );
173  TESTING_FREE( offdiag );
174  TESTING_HOSTFREE( h_R );
175  TESTING_HOSTFREE( h_work );
176 
177  if ( opts.check ) {
178  TESTING_FREE( h_Q );
179  TESTING_FREE( work );
180  #if defined(PRECISION_z) || defined(PRECISION_c)
181  TESTING_FREE( rwork );
182  #endif
183  }
184  }
185  }
186 
188  return status;
189 }
void parse_opts(int argc, char **argv, magma_opts *opts)
magma_int_t magma_dsytrd(char uplo, magma_int_t n, double *A, magma_int_t lda, double *d, double *e, double *tau, double *work, magma_int_t lwork, magma_int_t *info)
Definition: dsytrd.cpp:20
void lapackf77_dlacpy(const char *uplo, const magma_int_t *m, const magma_int_t *n, const double *A, const magma_int_t *lda, double *B, const magma_int_t *ldb)
magma_int_t magma_get_dsytrd_nb(magma_int_t m)
Definition: get_nb.cpp:391
#define TESTING_HOSTFREE(__ptr)
Definition: testings.h:57
magma_int_t ntest
Definition: testings.h:124
void lapackf77_dorgtr(const char *uplo, const magma_int_t *n, double *A, const magma_int_t *lda, const double *tau, double *work, const magma_int_t *lwork, magma_int_t *info)
magma_int_t niter
Definition: testings.h:138
#define TESTING_INIT()
Definition: testings.h:19
int magma_int_t
Definition: magmablas.h:12
#define TESTING_MALLOC(__ptr, __type, __size)
Definition: testings.h:34
void lapackf77_dsyt21(magma_int_t *itype, const char *uplo, const magma_int_t *n, const magma_int_t *kband, double *A, const magma_int_t *lda, double *d, double *e, double *U, const magma_int_t *ldu, double *V, const magma_int_t *ldv, double *tau, double *work, double *result)
#define TESTING_FREE(__ptr)
Definition: testings.h:54
#define FLOPS_DSYTRD(__n)
Definition: flops.h:333
#define h_A(i, j)
void lapackf77_dlarnv(const magma_int_t *idist, magma_int_t *iseed, const magma_int_t *n, double *x)
#define lapackf77_dlamch
Definition: magma_lapack.h:27
int check
Definition: testings.h:147
#define MagmaUpperLowerStr
Definition: magma.h:86
double magma_wtime(void)
Definition: timer.cpp:110
void magma_dmake_symmetric(magma_int_t N, double *A, magma_int_t lda)
magma_int_t nsize[MAX_NTEST]
Definition: testings.h:126
void lapackf77_dsytrd(const char *uplo, const magma_int_t *n, double *A, const magma_int_t *lda, double *d, double *e, double *tau, double *work, const magma_int_t *lwork, magma_int_t *info)
const char * magma_strerror(magma_err_t error)
Definition: error.cpp:227
#define TESTING_HOSTALLOC(__ptr, __type, __size)
Definition: testings.h:41
#define TESTING_FINALIZE()
Definition: testings.h:29
double real_Double_t
Definition: magma_types.h:27
magma_uplo_t uplo
Definition: testings.h:153
double tolerance
Definition: testings.h:144
int lapack
Definition: testings.h:148

Here is the call graph for this function: