PLASMA  2.4.5
PLASMA - Parallel Linear Algebra for Scalable Multi-core Architectures
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
testing_cpemv.c
Go to the documentation of this file.
1 
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <string.h>
18 #include <math.h>
19 
20 #include <plasma.h>
21 #include <cblas.h>
22 #include <lapacke.h>
23 #include <core_blas.h>
24 #include "testing_cmain.h"
25 
26 #define COMPLEX
27 #undef REAL
28 
29 /*--------------------------------------------------------------
30  * Check the pemv
31  */
32 static int check_solution(
34  int M, int N, int L,
35  PLASMA_Complex32_t alpha, PLASMA_Complex32_t *A, int LDA,
36  PLASMA_Complex32_t *X, int INCX,
37  PLASMA_Complex32_t beta, PLASMA_Complex32_t *Y0, int INCY0,
38  PLASMA_Complex32_t *Y, int INCY,
39  PLASMA_Complex32_t *W, float *Rnorm)
40 {
41  int k;
42  float eps = LAPACKE_slamch_work('e');
43  float *work;
44  PLASMA_Complex32_t mzone = -1.0;
45 
46  /* Copy x to w */
47  if ( trans == PlasmaNoTrans ) {
48  k = N;
49  } else {
50  k = M;
51  }
52 
53  work = (float *)malloc(k * sizeof(float));
54  cblas_ccopy(k, Y0, INCY0, W, 1);
55 
56  /* w = a A x + b w */
58  M, N,
59  CBLAS_SADDR(alpha), A, LDA,
60  X, INCX,
61  CBLAS_SADDR(beta), W, 1);
62 
63  /* y - w */
64  cblas_caxpy(k, CBLAS_SADDR(mzone), Y, INCY, W, 1);
65 
66  /* Max Norm */
67  *Rnorm = LAPACKE_clange_work(LAPACK_COL_MAJOR, 'm', 1, k, W, 1, work);
68 
69  if ( (*Rnorm / (M*N)) > eps) {
70  return 1;
71  } else {
72  return 0;
73  }
74 }
75 
76 /*--------------------------------------------------------------
77  * Testing CPEMV
78  */
79 int testing_cpemv(int argc, char **argv)
80 {
81  /* Check for number of arguments*/
82  if ( argc != 1) {
83  USAGE("PEMV", "N",
84  " - N : number of columns\n");
85  return -1;
86  }
87 
88  /* Args */
89  int arg_n = atoi(argv[0]);
90 
91  /* Local variables */
92  PLASMA_Complex32_t *A, *X, *Y, *A0, *Y0, *work;
93  PLASMA_Complex32_t alpha, beta, alpha0, beta0;
94  int n = arg_n;
95  int lda = arg_n;
96 
97  int info_solution = 0;
98  int i, j, k, t;
99  int nbtests = 0;
100  int nfails = 0;
101  int m, l, storev, incx, incy;
102  char *cstorev;
103  float rnorm;
104  float eps = LAPACKE_slamch_work('e');
105 
106  /* Allocate Data */
107  A = (PLASMA_Complex32_t *)malloc(lda*n*sizeof(PLASMA_Complex32_t));
108  A0 = (PLASMA_Complex32_t *)malloc(lda*n*sizeof(PLASMA_Complex32_t));
109  X = (PLASMA_Complex32_t *)malloc(lda*n*sizeof(PLASMA_Complex32_t));
110  Y = (PLASMA_Complex32_t *)malloc(lda*n*sizeof(PLASMA_Complex32_t));
111  Y0 = (PLASMA_Complex32_t *)malloc( n*sizeof(PLASMA_Complex32_t));
112  work = (PLASMA_Complex32_t *)malloc( 2*n*sizeof(PLASMA_Complex32_t));
113 
114  LAPACKE_clarnv_work(1, ISEED, 1, &alpha0);
115  LAPACKE_clarnv_work(1, ISEED, 1, &beta0 );
116 
117  /* Check if unable to allocate memory */
118  if ( (!A) || (!X) || (!Y0) || (!work) ) {
119  printf("Out of Memory \n ");
120  exit(0);
121  }
122 
123  /* Initialize Data */
124  PLASMA_cplrnt(n, n, A, lda, 479 );
125  PLASMA_cplrnt(n, n, X, lda, 320 );
126  PLASMA_cplrnt(n, 1, Y0, n, 573 );
127 
128  printf("\n");
129  printf("------ TESTS FOR PLASMA CPEMV ROUTINE ------- \n");
130  printf("\n");
131  printf(" The matrix A is randomly generated for each test.\n");
132  printf(" The relative machine precision (eps) is %e \n",eps);
133  printf(" Computational tests pass if scaled residual is less than eps.\n");
134  printf("\n");
135 
136  nfails = 0;
137  for (i=0; i<6; i++) {
138 
139  /* m and n cannot be greater than lda (arg_n) */
140  switch (i) {
141  case 0: l = 0; m = arg_n; n = m; break;
142  case 1: l = 0; m = arg_n; n = arg_n/2; break;
143  case 2: l = arg_n; m = l; n = l; break;
144  case 3: l = arg_n/2; m = l; n = arg_n; break;
145  case 4: l = arg_n/2; m = arg_n-l; n = l; break;
146  case 5: l = arg_n/3; m = arg_n-l; n = arg_n/2; break;
147  }
148 
149  /* Colwise ConjTrans & Rowwise NoTrans */
150 #ifdef COMPLEX
151  for (t=0; t<3; t++) {
152 #else
153  for (t=0; t<2; t++) {
154 #endif
155 
156  /* Swap m and n for transpose cases */
157  if ( t == 1 ) {
158  k = m; m = n; n = k;
159  }
160 
161  LAPACKE_clacpy_work( LAPACK_COL_MAJOR, 'A', m, n,
162  A, lda, A0, lda);
163 
164  if ( trans[t] == PlasmaNoTrans ) {
165  storev = PlasmaRowwise;
166  cstorev = storevstr[0];
167 
168  /* zeroed the upper right triangle */
169  int64_t i, j;
170  for (j=(n-l); j<n; j++) {
171  for (i=0; i<(j-(n-l)); i++) {
172  A0[i+j*lda] = 0.0;
173  }
174  }
175  }
176  else {
177  storev = PlasmaColumnwise;
178  cstorev = storevstr[1];
179 
180  /* zeroed the lower left triangle */
181  int64_t i, j;
182  for (j=0; j<(l-1); j++) {
183  for (i=(m-l+1+j); i<m; i++) {
184  A0[i+j*lda] = 0.0;
185  }
186  }
187  }
188 
189  for (j=0; j<3; j++) {
190 
191  /* Choose alpha and beta */
192  alpha = ( j==1 ) ? 0.0 : alpha0;
193  beta = ( j==2 ) ? 0.0 : beta0;
194 
195  /* incx and incy: 1 or lda */
196  for (k=0; k<4; k++) {
197  switch (k) {
198  case 0: incx = 1; incy = 1; break;
199  case 1: incx = 1; incy = lda; break;
200  case 2: incx = lda; incy = 1; break;
201  case 3: incx = lda; incy = lda; break;
202  }
203 
204  /* initialize Y with incy */
205  cblas_ccopy(n, Y0, 1, Y, incy);
206 
207  /* CPEMV */
208  CORE_cpemv( trans[t], storev, m, n, l,
209  alpha, A, lda,
210  X, incx,
211  beta, Y, incy,
212  work);
213 
214  /* Check the solution */
215  info_solution = check_solution(trans[t], storev,
216  m, n, l,
217  alpha, A0, lda,
218  X, incx,
219  beta, Y0, 1,
220  Y, incy,
221  work, &rnorm);
222 
223  if ( info_solution != 0 ) {
224  nfails++;
225  printf("Failed: t=%s, s=%s, M=%3d, N=%3d, L=%3d, alpha=%e, incx=%3d, beta=%e, incy=%3d, rnorm=%e\n",
226  transstr[t], cstorev, m, n, l, crealf(alpha), incx, crealf(beta), incy, rnorm );
227  }
228  nbtests++;
229  }
230  }
231  }
232  }
233 
234  if ( nfails )
235  printf("%d / %d tests failed\n", nfails, nbtests);
236 
237  printf("***************************************************\n");
238  if (nfails == 0) {
239  printf(" ---- TESTING CPEMV ...... PASSED !\n");
240  }
241  else {
242  printf(" ---- TESTING CPEMV ... FAILED !\n");
243  }
244  printf("***************************************************\n");
245 
246  free( A0 );
247  free( A );
248  free( X );
249  free( Y0 );
250  free( Y );
251 
252  return 0;
253 }
254