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_chetrd.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_chetrd.cpp:

Go to the source code of this file.

Macros

#define PRECISION_c
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define PRECISION_c

Definition at line 28 of file testing_chetrd.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 33 of file testing_chetrd.cpp.

References magma_opts::check, FLOPS_CHETRD, h_A, magma_opts::lapack, lapackf77_chet21(), lapackf77_chetrd(), lapackf77_clacpy(), lapackf77_clarnv(), lapackf77_cungtr(), lapackf77_slamch, magma_chetrd(), magma_cmake_hermitian(), magma_get_chetrd_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  float eps;
39  magmaFloatComplex *h_A, *h_R, *h_Q, *h_work, *work;
40  magmaFloatComplex *tau;
41  float *diag, *offdiag;
42  float 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  float *rwork;
52  #endif
53 
54  eps = lapackf77_slamch( "E" );
55 
56  magma_opts opts;
57  parse_opts( argc, argv, &opts );
58 
59  float tol = opts.tolerance * lapackf77_slamch("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_chetrd_nb(N);
69  lwork = N*nb; /* We suppose the magma nb is bigger than lapack nb */
70  gflops = FLOPS_CHETRD( N ) / 1e9;
71 
72  TESTING_MALLOC( h_A, magmaFloatComplex, lda*N );
73  TESTING_HOSTALLOC( h_R, magmaFloatComplex, lda*N );
74  TESTING_HOSTALLOC( h_work, magmaFloatComplex, lwork );
75  TESTING_MALLOC( tau, magmaFloatComplex, N );
76  TESTING_MALLOC( diag, float, N );
77  TESTING_MALLOC( offdiag, float, N-1 );
78 
79  if ( opts.check ) {
80  TESTING_MALLOC( h_Q, magmaFloatComplex, lda*N );
81  TESTING_MALLOC( work, magmaFloatComplex, 2*N*N );
82  #if defined(PRECISION_z) || defined(PRECISION_c)
83  TESTING_MALLOC( rwork, float, N );
84  #endif
85  }
86 
87  /* ====================================================================
88  Initialize the matrix
89  =================================================================== */
90  lapackf77_clarnv( &ione, ISEED, &n2, h_A );
91  magma_cmake_hermitian( N, h_A, lda );
92  lapackf77_clacpy( MagmaUpperLowerStr, &N, &N, h_A, &lda, h_R, &lda );
93 
94  /* ====================================================================
95  Performs operation using MAGMA
96  =================================================================== */
97  gpu_time = magma_wtime();
98  magma_chetrd( 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_chetrd returned error %d: %s.\n",
104  (int) info, magma_strerror( info ));
105 
106  /* =====================================================================
107  Check the factorization
108  =================================================================== */
109  if ( opts.check ) {
110  lapackf77_clacpy( &opts.uplo, &N, &N, h_R, &lda, h_Q, &lda );
111  lapackf77_cungtr( &opts.uplo, &N, h_Q, &lda, tau, h_work, &lwork, &info );
112 
113  #if defined(PRECISION_z) || defined(PRECISION_c)
114  lapackf77_chet21( &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_chet21( &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_chet21( &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_chet21( &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_chetrd( &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_chetrd 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)
#define TESTING_HOSTFREE(__ptr)
Definition: testings.h:57
magma_int_t ntest
Definition: testings.h:124
void magma_cmake_hermitian(magma_int_t N, magmaFloatComplex *A, magma_int_t lda)
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
#define TESTING_FREE(__ptr)
Definition: testings.h:54
#define h_A(i, j)
#define FLOPS_CHETRD(__n)
Definition: flops.h:329
magma_int_t magma_chetrd(char uplo, magma_int_t n, magmaFloatComplex *A, magma_int_t lda, float *d, float *e, magmaFloatComplex *tau, magmaFloatComplex *work, magma_int_t lwork, magma_int_t *info)
Definition: chetrd.cpp:20
int check
Definition: testings.h:147
magma_int_t magma_get_chetrd_nb(magma_int_t m)
Definition: get_nb.cpp:408
#define MagmaUpperLowerStr
Definition: magma.h:86
void lapackf77_chet21(const magma_int_t *itype, const char *uplo, const magma_int_t *n, const magma_int_t *kband, magmaFloatComplex *A, const magma_int_t *lda, float *d, float *e, magmaFloatComplex *U, const magma_int_t *ldu, magmaFloatComplex *V, const magma_int_t *ldv, magmaFloatComplex *tau, magmaFloatComplex *work, float *rwork, float *result)
void lapackf77_clacpy(const char *uplo, const magma_int_t *m, const magma_int_t *n, const magmaFloatComplex *A, const magma_int_t *lda, magmaFloatComplex *B, const magma_int_t *ldb)
double magma_wtime(void)
Definition: timer.cpp:110
#define lapackf77_slamch
Definition: magma_lapack.h:26
magma_int_t nsize[MAX_NTEST]
Definition: testings.h:126
void lapackf77_chetrd(const char *uplo, const magma_int_t *n, magmaFloatComplex *A, const magma_int_t *lda, float *d, float *e, magmaFloatComplex *tau, magmaFloatComplex *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
void lapackf77_cungtr(const char *uplo, const magma_int_t *n, magmaFloatComplex *A, const magma_int_t *lda, const magmaFloatComplex *tau, magmaFloatComplex *work, const magma_int_t *lwork, magma_int_t *info)
#define TESTING_FINALIZE()
Definition: testings.h:29
double real_Double_t
Definition: magma_types.h:27
void lapackf77_clarnv(const magma_int_t *idist, magma_int_t *iseed, const magma_int_t *n, magmaFloatComplex *x)
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: