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_ssymm.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_smain.h"
25 
26 static int check_solution(PLASMA_enum transA, PLASMA_enum transB, int M, int N,
27  float alpha, float *A, int LDA,
28  float *B, int LDB,
29  float beta, float *Cref, float *Cplasma, int LDC);
30 
31 int testing_ssymm(int argc, char **argv)
32 {
33  /* Check for number of arguments*/
34  if ( argc != 7 ){
35  USAGE("SYMM", "alpha beta M N K LDA LDB LDC",
36  " - alpha : alpha coefficient \n"
37  " - beta : beta coefficient \n"
38  " - M : number of rows of matrices A and C \n"
39  " - N : number of columns of matrices B and C \n"
40  " - LDA : leading dimension of matrix A \n"
41  " - LDB : leading dimension of matrix B \n"
42  " - LDC : leading dimension of matrix C\n");
43  return -1;
44  }
45 
46  float alpha = (float) atol(argv[0]);
47  float beta = (float) atol(argv[1]);
48  int M = atoi(argv[2]);
49  int N = atoi(argv[3]);
50  int LDA = atoi(argv[4]);
51  int LDB = atoi(argv[5]);
52  int LDC = atoi(argv[6]);
53  int MNmax = max(M, N);
54 
55  float eps;
56  int info_solution;
57  int i, j, s, u;
58  int LDAxM = LDA*MNmax;
59  int LDBxN = LDB*N;
60  int LDCxN = LDC*N;
61 
62  float *A = (float *)malloc(LDAxM*sizeof(float));
63  float *B = (float *)malloc(LDBxN*sizeof(float));
64  float *C = (float *)malloc(LDCxN*sizeof(float));
65  float *Cinit = (float *)malloc(LDCxN*sizeof(float));
66  float *Cfinal = (float *)malloc(LDCxN*sizeof(float));
67 
68  /* Check if unable to allocate memory */
69  if ((!A)||(!B)||(!Cinit)||(!Cfinal)){
70  printf("Out of Memory \n ");
71  return -2;
72  }
73 
74  eps = LAPACKE_slamch_work('e');
75 
76  printf("\n");
77  printf("------ TESTS FOR PLASMA SSYMM ROUTINE ------- \n");
78  printf(" Size of the Matrix %d by %d\n", M, N);
79  printf("\n");
80  printf(" The matrix A is randomly generated for each test.\n");
81  printf("============\n");
82  printf(" The relative machine precision (eps) is to be %e \n",eps);
83  printf(" Computational tests pass if scaled residuals are less than 10.\n");
84 
85  /*----------------------------------------------------------
86  * TESTING SSYMM
87  */
88 
89  /* Initialize A */
90  PLASMA_splgsy( (float)0., MNmax, A, LDA, 51 );
91 
92  /* Initialize B */
93  LAPACKE_slarnv_work(IONE, ISEED, LDBxN, B);
94 
95  /* Initialize C */
96  LAPACKE_slarnv_work(IONE, ISEED, LDCxN, C);
97 
98  for (s=0; s<2; s++) {
99  for (u=0; u<2; u++) {
100 
101  /* Initialize Cinit / Cfinal */
102  for ( i = 0; i < M; i++)
103  for ( j = 0; j < N; j++)
104  Cinit[LDC*j+i] = C[LDC*j+i];
105  for ( i = 0; i < M; i++)
106  for ( j = 0; j < N; j++)
107  Cfinal[LDC*j+i] = C[LDC*j+i];
108 
109  /* PLASMA SSYMM */
110  PLASMA_ssymm(side[s], uplo[u], M, N, alpha, A, LDA, B, LDB, beta, Cfinal, LDC);
111 
112  /* Check the solution */
113  info_solution = check_solution(side[s], uplo[u], M, N, alpha, A, LDA, B, LDB, beta, Cinit, Cfinal, LDC);
114 
115  if (info_solution == 0) {
116  printf("***************************************************\n");
117  printf(" ---- TESTING SSYMM (%5s, %5s) ....... PASSED !\n", sidestr[s], uplostr[u]);
118  printf("***************************************************\n");
119  }
120  else {
121  printf("************************************************\n");
122  printf(" - TESTING SSYMM (%s, %s) ... FAILED !\n", sidestr[s], uplostr[u]);
123  printf("************************************************\n");
124  }
125  }
126  }
127 
128  free(A); free(B); free(C);
129  free(Cinit); free(Cfinal);
130 
131  return 0;
132 }
133 
134 /*--------------------------------------------------------------
135  * Check the solution
136  */
137 
138 static int check_solution(PLASMA_enum side, PLASMA_enum uplo, int M, int N,
139  float alpha, float *A, int LDA,
140  float *B, int LDB,
141  float beta, float *Cref, float *Cplasma, int LDC)
142 {
143  int info_solution, NrowA;
144  float Anorm, Bnorm, Cinitnorm, Cplasmanorm, Clapacknorm, Rnorm;
145  float eps;
146  float beta_const;
147  float result;
148  float *work = (float *)malloc(max(M, N)* sizeof(float));
149 
150  beta_const = (float)-1.0;
151 
152  NrowA = (side == PlasmaLeft) ? M : N;
153  Anorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), NrowA, NrowA, A, LDA, work);
154  Bnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, B, LDB, work);
155  Cinitnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, Cref, LDC, work);
156  Cplasmanorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, Cplasma, LDC, work);
157 
158  cblas_ssymm(CblasColMajor, (CBLAS_SIDE)side, (CBLAS_UPLO)uplo, M, N, (alpha), A, LDA, B, LDB, (beta), Cref, LDC);
159 
160  Clapacknorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, Cref, LDC, work);
161 
162  cblas_saxpy(LDC * N, (beta_const), Cplasma, 1, Cref, 1);
163 
164  Rnorm = LAPACKE_slange_work(LAPACK_COL_MAJOR, lapack_const(PlasmaInfNorm), M, N, Cref, LDC, work);
165 
166  eps = LAPACKE_slamch_work('e');
167 
168  printf("Rnorm %e, Anorm %e, Bnorm %e, Cinitnorm %e, Cplasmanorm %e, Clapacknorm %e\n",Rnorm,Anorm,Bnorm,Cinitnorm,Cplasmanorm,Clapacknorm);
169 
170  result = Rnorm / ((Anorm + Bnorm + Cinitnorm) * N * eps);
171 
172  printf("============\n");
173  printf("Checking the norm of the difference against reference SSYMM \n");
174  printf("-- ||Cplasma - Clapack||_oo/((||A||_oo+||B||_oo+||C||_oo).N.eps) = %e \n", result );
175 
176  if ( isinf(Clapacknorm) || isinf(Cplasmanorm) || isnan(result) || isinf(result) || (result > 10.0) ) {
177  printf("-- The solution is suspicious ! \n");
178  info_solution = 1;
179  }
180  else {
181  printf("-- The solution is CORRECT ! \n");
182  info_solution= 0 ;
183  }
184  free(work);
185  return info_solution;
186 }