root / BLAS / xGEMM / xGEMM.c @ 49
Historique | Voir | Annoter | Télécharger (12,43 ko)
| 1 |
/*
|
|---|---|
| 2 |
Performs matrix multiply
|
| 3 |
|
| 4 |
Thanks for help from aurel32@debian.org
|
| 5 |
*/
|
| 6 |
|
| 7 |
#include <stdio.h> |
| 8 |
#include <math.h> |
| 9 |
#include <stdlib.h> |
| 10 |
#include <sys/time.h> |
| 11 |
#include <string.h> |
| 12 |
|
| 13 |
#ifdef CUBLAS
|
| 14 |
#include <cublas.h> |
| 15 |
#define CUBLAS_WRAPPER_ERROR_NOERR 0 |
| 16 |
#define CUBLAS_WRAPPER_ERROR_ALLOC 1 |
| 17 |
#define CUBLAS_WRAPPER_ERROR_SET 2 |
| 18 |
#define CUBLAS_WRAPPER_ERROR_GET 3 |
| 19 |
#define CUBLAS_WRAPPER_ERROR_STUB 4 |
| 20 |
#elif THUNKING
|
| 21 |
#include <cublas.h> |
| 22 |
#include "fortran_common.h" |
| 23 |
#include "fortran_thunking.h" |
| 24 |
#elif FBLAS
|
| 25 |
#include <cblas_f77.h> |
| 26 |
#elif GSL
|
| 27 |
#include <gsl_cblas.h> |
| 28 |
#elif ACML
|
| 29 |
#include <acml.h> |
| 30 |
#include <acml_mv.h> |
| 31 |
#else
|
| 32 |
#include <cblas.h> |
| 33 |
#endif
|
| 34 |
|
| 35 |
#ifdef DOUBLE
|
| 36 |
#define LENGTH double |
| 37 |
#else
|
| 38 |
#define LENGTH float |
| 39 |
#endif
|
| 40 |
|
| 41 |
#ifdef FBLAS
|
| 42 |
|
| 43 |
#ifdef DOUBLE
|
| 44 |
|
| 45 |
void dgemm_(FCHAR, FCHAR, FINT, FINT, FINT, const double *, const double *, FINT, |
| 46 |
const double *, FINT, const double *, double *, FINT); |
| 47 |
|
| 48 |
#else
|
| 49 |
|
| 50 |
void sgemm_(FCHAR, FCHAR, FINT, FINT, FINT, const float *, const float *, FINT, |
| 51 |
const float *, FINT, const float *, float *, FINT); |
| 52 |
|
| 53 |
#endif
|
| 54 |
#endif
|
| 55 |
|
| 56 |
/* Matrix with only defined triangular terms */
|
| 57 |
/* Even if there are 0 in matrix, must be defined at all ! */
|
| 58 |
|
| 59 |
/* Get from fortran.c */
|
| 60 |
|
| 61 |
#ifdef CUBLAS
|
| 62 |
static char *errMsg[5] = |
| 63 |
{
|
| 64 |
"no error",
|
| 65 |
"allocation error",
|
| 66 |
"setVector/setMatrix error",
|
| 67 |
"getVector/getMatrix error",
|
| 68 |
"not implemented"
|
| 69 |
}; |
| 70 |
|
| 71 |
static void wrapperError (const char *funcName, int error) |
| 72 |
{
|
| 73 |
printf ("cublas%s wrapper: %s\n", funcName, errMsg[error]);
|
| 74 |
fflush (stdout); |
| 75 |
} |
| 76 |
#endif
|
| 77 |
|
| 78 |
int printVector(const int dimVector,const LENGTH *dataVector, |
| 79 |
char *nameVector,char *mesgVector) |
| 80 |
{
|
| 81 |
#ifndef QUIET
|
| 82 |
|
| 83 |
int i;
|
| 84 |
printf("\n%s of %s, size %i:\n",mesgVector,nameVector,dimVector);
|
| 85 |
for (i=0;i<dimVector;i++) |
| 86 |
{
|
| 87 |
printf("%s[%i]=%2.10e\n",nameVector,i,dataVector[i]);
|
| 88 |
} |
| 89 |
#endif
|
| 90 |
|
| 91 |
return 0; |
| 92 |
} |
| 93 |
|
| 94 |
int printResults(const int dimVector,const LENGTH *dataVector, |
| 95 |
char *nameVector,char *mesgVector) |
| 96 |
{
|
| 97 |
#ifdef RESULTS
|
| 98 |
int i;
|
| 99 |
|
| 100 |
printf("\n%s of %s, size %i:\n",mesgVector,nameVector,dimVector);
|
| 101 |
for (i=0;i<dimVector;i++) |
| 102 |
{
|
| 103 |
printf("%s[%i]=%2.10e\n",nameVector,i,dataVector[i]);
|
| 104 |
} |
| 105 |
#endif
|
| 106 |
return 0; |
| 107 |
} |
| 108 |
|
| 109 |
#ifdef CUBLAS
|
| 110 |
int printVectorGPU(const int dimVector,const LENGTH *dataVector, |
| 111 |
char *nameVector,char *mesgVector) |
| 112 |
{
|
| 113 |
#ifndef QUIET
|
| 114 |
int i;
|
| 115 |
cublasStatus stat; |
| 116 |
LENGTH *P=0;
|
| 117 |
int incx=1; |
| 118 |
|
| 119 |
P=malloc(dimVector*sizeof(LENGTH));
|
| 120 |
|
| 121 |
stat=cublasGetVector(dimVector,sizeof(P[0]),dataVector,incx,P,incx); |
| 122 |
|
| 123 |
if (stat != CUBLAS_STATUS_SUCCESS) {
|
| 124 |
wrapperError ("ToGet", CUBLAS_WRAPPER_ERROR_GET);
|
| 125 |
} |
| 126 |
|
| 127 |
printf("\n%s of %s, size %i:\n",mesgVector,nameVector,dimVector);
|
| 128 |
for (i=0;i<dimVector;i++) |
| 129 |
{
|
| 130 |
printf("%s[%i]=%2.10e\n",nameVector,i,P[i]);
|
| 131 |
} |
| 132 |
|
| 133 |
free(P); |
| 134 |
#endif
|
| 135 |
|
| 136 |
return 0; |
| 137 |
} |
| 138 |
#endif
|
| 139 |
|
| 140 |
int bench(int dim,int RUNS) |
| 141 |
{
|
| 142 |
/*
|
| 143 |
int dim=1000;
|
| 144 |
int RUNS=100;
|
| 145 |
int incx=1;
|
| 146 |
*/
|
| 147 |
#ifdef PRINT
|
| 148 |
LENGTH factor=1.;
|
| 149 |
#endif
|
| 150 |
|
| 151 |
LENGTH alpha=1.,beta=0.; |
| 152 |
LENGTH *A,*B,*C,*D; |
| 153 |
|
| 154 |
/* checkBefore checkAfter checks */
|
| 155 |
LENGTH *checksA,*checksB; |
| 156 |
|
| 157 |
int i=0, j=0; |
| 158 |
|
| 159 |
double duration;
|
| 160 |
|
| 161 |
struct timeval tv1,tv2;
|
| 162 |
struct timezone tz;
|
| 163 |
|
| 164 |
/* Create 4 Matrix of dimension dim by dim */
|
| 165 |
|
| 166 |
A=malloc(dim*dim*sizeof(LENGTH));
|
| 167 |
B=malloc(dim*dim*sizeof(LENGTH));
|
| 168 |
C=malloc(dim*dim*sizeof(LENGTH));
|
| 169 |
D=malloc(dim*dim*sizeof(LENGTH));
|
| 170 |
|
| 171 |
/* Create 2 vectors for checker Before and After */
|
| 172 |
|
| 173 |
checksA=malloc(RUNS*sizeof(LENGTH));
|
| 174 |
checksB=malloc(RUNS*sizeof(LENGTH));
|
| 175 |
|
| 176 |
/* Initialize elements with random numbers */
|
| 177 |
/* Initialize the seed for rand() */
|
| 178 |
/* srand(time()); */
|
| 179 |
|
| 180 |
for (i=0; i<dim; i++) { |
| 181 |
for (j=0; j<dim; j++) { |
| 182 |
A[i*dim+j]=(LENGTH)rand()/(RAND_MAX+1.)
|
| 183 |
*(LENGTH)(i+1.)/(LENGTH)(j+1.); |
| 184 |
B[i*dim+j]=(LENGTH)rand()/(RAND_MAX+1.)
|
| 185 |
*(LENGTH)(i+1.)/(LENGTH)(j+1.); |
| 186 |
C[i*dim+j]=0.;
|
| 187 |
D[i*dim+j]=0.;
|
| 188 |
} |
| 189 |
} |
| 190 |
/*
|
| 191 |
A[0]=1;
|
| 192 |
A[1]=2;
|
| 193 |
A[2]=3;
|
| 194 |
A[3]=4;
|
| 195 |
|
| 196 |
B[0]=5;
|
| 197 |
B[1]=6;
|
| 198 |
B[2]=7;
|
| 199 |
B[3]=8;
|
| 200 |
*/
|
| 201 |
|
| 202 |
/* Print the matrix */
|
| 203 |
|
| 204 |
#ifdef QUIET
|
| 205 |
#else
|
| 206 |
for (i=0; i<dim; i++) { |
| 207 |
for (j=0; j<dim; j++) printf("A[%i,%i]=%1.5f ", i,j,A[i*dim+j]); |
| 208 |
putchar('\n');
|
| 209 |
} |
| 210 |
putchar('\n');
|
| 211 |
for (i=0; i<dim; i++) { |
| 212 |
for (j=0; j<dim; j++) printf("B[%i,%i]=%1.5f ", i,j,B[i*dim+j]); |
| 213 |
putchar('\n');
|
| 214 |
} |
| 215 |
putchar('\n');
|
| 216 |
#endif
|
| 217 |
|
| 218 |
/* Get first timer before launching */
|
| 219 |
gettimeofday(&tv1, &tz); |
| 220 |
|
| 221 |
/* Compute with CuBLAS library */
|
| 222 |
#ifdef CUBLAS
|
| 223 |
LENGTH *devPtrA=0, *devPtrB=0, *devPtrC=0, *devPtrD=0; |
| 224 |
cublasStatus stat1, stat2, stat3, stat4; |
| 225 |
struct timeval tv3,tv4;
|
| 226 |
|
| 227 |
/* Order is Row */
|
| 228 |
/* Have to swap uplo and trans */
|
| 229 |
char transa='N',transb='T'; |
| 230 |
|
| 231 |
printf("Using CuBLAS: %i iterations for %ix%i matrix\n",
|
| 232 |
RUNS,dim,dim); |
| 233 |
|
| 234 |
stat1=cublasAlloc(dim*dim,sizeof(devPtrA[0]),(void**)&devPtrA); |
| 235 |
stat2=cublasAlloc(dim*dim,sizeof(devPtrB[0]),(void**)&devPtrB); |
| 236 |
stat3=cublasAlloc(dim*dim,sizeof(devPtrC[0]),(void**)&devPtrC); |
| 237 |
stat4=cublasAlloc(dim*dim,sizeof(devPtrD[0]),(void**)&devPtrD); |
| 238 |
|
| 239 |
if ((stat1 != CUBLAS_STATUS_SUCCESS) ||
|
| 240 |
(stat2 != CUBLAS_STATUS_SUCCESS) || |
| 241 |
(stat3 != CUBLAS_STATUS_SUCCESS) || |
| 242 |
(stat4 != CUBLAS_STATUS_SUCCESS) ) {
|
| 243 |
wrapperError ("xGEMM", CUBLAS_WRAPPER_ERROR_ALLOC);
|
| 244 |
cublasFree (devPtrA); |
| 245 |
cublasFree (devPtrB); |
| 246 |
cublasFree (devPtrC); |
| 247 |
cublasFree (devPtrD); |
| 248 |
return 1; |
| 249 |
} |
| 250 |
|
| 251 |
stat1=cublasSetMatrix(dim,dim,sizeof(A[0]),A,dim,devPtrA,dim); |
| 252 |
stat2=cublasSetMatrix(dim,dim,sizeof(B[0]),B,dim,devPtrB,dim); |
| 253 |
stat3=cublasSetMatrix(dim,dim,sizeof(C[0]),C,dim,devPtrC,dim); |
| 254 |
stat4=cublasSetMatrix(dim,dim,sizeof(D[0]),D,dim,devPtrD,dim); |
| 255 |
|
| 256 |
if ((stat1 != CUBLAS_STATUS_SUCCESS) ||
|
| 257 |
(stat2 != CUBLAS_STATUS_SUCCESS) || |
| 258 |
(stat3 != CUBLAS_STATUS_SUCCESS) || |
| 259 |
(stat4 != CUBLAS_STATUS_SUCCESS) ) {
|
| 260 |
wrapperError ("xGEMM", CUBLAS_WRAPPER_ERROR_SET);
|
| 261 |
cublasFree (devPtrA); |
| 262 |
cublasFree (devPtrB); |
| 263 |
cublasFree (devPtrC); |
| 264 |
cublasFree (devPtrD); |
| 265 |
return 1; |
| 266 |
} |
| 267 |
|
| 268 |
/* Get third timer after memory operation */
|
| 269 |
gettimeofday(&tv3, &tz); |
| 270 |
|
| 271 |
#ifdef DOUBLE
|
| 272 |
|
| 273 |
for (i=0;i<RUNS;i++) |
| 274 |
{
|
| 275 |
cublasDgemm(transa,transa,dim,dim,dim,alpha,devPtrB,dim, |
| 276 |
devPtrA,dim,beta,devPtrC,dim); |
| 277 |
cublasDgemm(transb,transb,dim,dim,dim,alpha,devPtrA,dim, |
| 278 |
devPtrB,dim,beta,devPtrD,dim); |
| 279 |
} |
| 280 |
|
| 281 |
#else
|
| 282 |
|
| 283 |
for (i=0;i<RUNS;i++) |
| 284 |
{
|
| 285 |
cublasSgemm(transa,transa,dim,dim,dim,alpha,devPtrB,dim, |
| 286 |
devPtrA,dim,beta,devPtrC,dim); |
| 287 |
cublasSgemm(transb,transb,dim,dim,dim,alpha,devPtrA,dim, |
| 288 |
devPtrB,dim,beta,devPtrD,dim); |
| 289 |
} |
| 290 |
|
| 291 |
#endif
|
| 292 |
|
| 293 |
stat3=cublasGetMatrix(dim,dim,sizeof(C[0]),devPtrC,dim,C,dim); |
| 294 |
stat4=cublasGetMatrix(dim,dim,sizeof(D[0]),devPtrD,dim,D,dim); |
| 295 |
|
| 296 |
cublasFree (devPtrA); |
| 297 |
cublasFree (devPtrB); |
| 298 |
cublasFree (devPtrC); |
| 299 |
cublasFree (devPtrD); |
| 300 |
|
| 301 |
if ((stat1 != CUBLAS_STATUS_SUCCESS) ) {
|
| 302 |
wrapperError ("xGEMM", CUBLAS_WRAPPER_ERROR_GET);
|
| 303 |
} |
| 304 |
|
| 305 |
/* Get fourth timer after memory free */
|
| 306 |
gettimeofday(&tv4, &tz); |
| 307 |
|
| 308 |
#elif THUNKING
|
| 309 |
|
| 310 |
/* Order is Row : Have to swap uplo='U' and trans='N' */
|
| 311 |
char transa='N',transb='T'; |
| 312 |
printf("Using CuBLAS/Thunking: %i iterations for %ix%i matrix\n",
|
| 313 |
RUNS,dim,dim); |
| 314 |
|
| 315 |
#ifdef DOUBLE
|
| 316 |
|
| 317 |
for (i=0;i<RUNS;i++) |
| 318 |
{
|
| 319 |
/* Multiply A by X as Y <- A.X */
|
| 320 |
CUBLAS_DGEMM(&transa,&transa, |
| 321 |
&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim); |
| 322 |
CUBLAS_DGEMM(&transb,&transb, |
| 323 |
&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim); |
| 324 |
} |
| 325 |
|
| 326 |
#else
|
| 327 |
|
| 328 |
for (i=0;i<RUNS;i++) |
| 329 |
{
|
| 330 |
/* Multiply A by X as Y <- A.X */
|
| 331 |
CUBLAS_SGEMM(&transa,&transa, |
| 332 |
&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim); |
| 333 |
CUBLAS_SGEMM(&transb,&transb, |
| 334 |
&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim); |
| 335 |
} |
| 336 |
|
| 337 |
#endif
|
| 338 |
|
| 339 |
#elif FBLAS
|
| 340 |
|
| 341 |
/* Order is Row : Have to swap uplo='U' and trans='N' */
|
| 342 |
char transa='N',transb='T'; |
| 343 |
|
| 344 |
printf("Using FBLAS: %i iterations for %ix%i matrix\n",
|
| 345 |
RUNS,dim,dim); |
| 346 |
|
| 347 |
#ifdef DOUBLE
|
| 348 |
|
| 349 |
for (i=0;i<RUNS;i++) |
| 350 |
{
|
| 351 |
/* Multiply A by X as Y <- A.X */
|
| 352 |
dgemm_(&transa,&transa,&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim); |
| 353 |
dgemm_(&transb,&transb,&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim); |
| 354 |
} |
| 355 |
|
| 356 |
#else
|
| 357 |
|
| 358 |
for (i=0;i<RUNS;i++) |
| 359 |
{
|
| 360 |
/* Multiply A by X as Y <- A.X */
|
| 361 |
sgemm_(&transa,&transa,&dim,&dim,&dim,&alpha,B,&dim,A,&dim,&beta,C,&dim); |
| 362 |
sgemm_(&transb,&transb,&dim,&dim,&dim,&alpha,A,&dim,B,&dim,&beta,D,&dim); |
| 363 |
} |
| 364 |
|
| 365 |
#endif
|
| 366 |
|
| 367 |
#elif ACML
|
| 368 |
|
| 369 |
/* Order is Row : Have to swap uplo='U' and trans='N' */
|
| 370 |
char transa='N',transb='T'; |
| 371 |
|
| 372 |
printf("Using ACML: %i iterations for %ix%i matrix\n",
|
| 373 |
RUNS,dim,dim); |
| 374 |
|
| 375 |
#ifdef DOUBLE
|
| 376 |
|
| 377 |
for (i=0;i<RUNS;i++) |
| 378 |
{
|
| 379 |
/* Multiply A by X as Y <- A.X */
|
| 380 |
dgemm(transa,transa,dim,dim,dim,alpha,B,dim,A,dim,beta,C,dim); |
| 381 |
dgemm(transb,transb,dim,dim,dim,alpha,A,dim,B,dim,beta,D,dim); |
| 382 |
} |
| 383 |
|
| 384 |
#else
|
| 385 |
|
| 386 |
for (i=0;i<RUNS;i++) |
| 387 |
{
|
| 388 |
/* Multiply A by X as Y <- A.X */
|
| 389 |
sgemm(transa,transa,dim,dim,dim,alpha,B,dim,A,dim,beta,C,dim); |
| 390 |
sgemm(transb,transb,dim,dim,dim,alpha,A,dim,B,dim,beta,D,dim); |
| 391 |
} |
| 392 |
|
| 393 |
#endif
|
| 394 |
|
| 395 |
#elif GSL
|
| 396 |
|
| 397 |
printf("Using GSL: %i iterations for %ix%i matrix\n",RUNS,dim,dim);
|
| 398 |
|
| 399 |
/*
|
| 400 |
RowMajor : Matrix is read row by row
|
| 401 |
Upper : the no null elements are on top
|
| 402 |
NoTrans : no transposition before estimation
|
| 403 |
NonUnit : Matrix is not unit
|
| 404 |
*/
|
| 405 |
|
| 406 |
#ifdef DOUBLE
|
| 407 |
|
| 408 |
for (i=0;i<RUNS;i++) |
| 409 |
{
|
| 410 |
/* Multiply A by X as Y <- A.X */
|
| 411 |
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans, |
| 412 |
dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim); |
| 413 |
cblas_dgemm(CblasRowMajor,CblasTrans,CblasTrans, |
| 414 |
dim,dim,dim,alpha,B,dim,A,dim,beta,D,dim); |
| 415 |
} |
| 416 |
|
| 417 |
#else
|
| 418 |
|
| 419 |
for (i=0;i<RUNS;i++) |
| 420 |
{
|
| 421 |
/* Multiply A by X as Y <- A.X */
|
| 422 |
cblas_sgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans, |
| 423 |
dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim); |
| 424 |
cblas_sgemm(CblasRowMajor,CblasTrans,CblasTrans, |
| 425 |
dim,dim,dim,alpha,B,dim,A,dim,beta,D,dim); |
| 426 |
} |
| 427 |
|
| 428 |
#endif
|
| 429 |
|
| 430 |
#else
|
| 431 |
|
| 432 |
printf("Using CBLAS: %i iterations for %ix%i matrix\n",RUNS,dim,dim);
|
| 433 |
|
| 434 |
/*
|
| 435 |
RowMajor : Matrix is read row bu row
|
| 436 |
Upper : the no null elements are on top
|
| 437 |
NoTrans : no transposition before estimation
|
| 438 |
NonUnit : Matrix is not unit
|
| 439 |
*/
|
| 440 |
|
| 441 |
#ifdef DOUBLE
|
| 442 |
|
| 443 |
for (i=0;i<RUNS;i++) |
| 444 |
{
|
| 445 |
cblas_dgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans, |
| 446 |
dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim); |
| 447 |
cblas_dgemm(CblasRowMajor,CblasTrans,CblasTrans, |
| 448 |
dim,dim,dim,alpha,B,dim,A,dim,beta,D,dim); |
| 449 |
} |
| 450 |
|
| 451 |
#else
|
| 452 |
|
| 453 |
for (i=0;i<RUNS;i++) |
| 454 |
{
|
| 455 |
cblas_sgemm(CblasRowMajor,CblasNoTrans,CblasNoTrans, |
| 456 |
dim,dim,dim,alpha,A,dim,B,dim,beta,C,dim); |
| 457 |
cblas_sgemm(CblasRowMajor,CblasTrans,CblasTrans, |
| 458 |
dim,dim,dim,alpha,B,dim,A,dim,beta,D,dim); |
| 459 |
} |
| 460 |
|
| 461 |
#endif
|
| 462 |
|
| 463 |
#endif
|
| 464 |
|
| 465 |
/* Get second timer after launching */
|
| 466 |
gettimeofday(&tv2, &tz); |
| 467 |
|
| 468 |
/* Store the checker of errors */
|
| 469 |
checksA[0]=0.; |
| 470 |
|
| 471 |
for (i=0; i<dim; i++) { |
| 472 |
for (j=0; j<dim; j++) { |
| 473 |
checksA[0]=checksA[0]+fabs(D[i*dim+j]-C[j*dim+i]); |
| 474 |
} |
| 475 |
} |
| 476 |
|
| 477 |
/* Print the matrix */
|
| 478 |
|
| 479 |
#ifdef QUIET
|
| 480 |
#else
|
| 481 |
for (i=0; i<dim; i++) { |
| 482 |
for (j=0; j<dim; j++) printf("C[%i,%i]=%1.5f ", i,j,C[i*dim+j]); |
| 483 |
putchar('\n');
|
| 484 |
} |
| 485 |
putchar('\n');
|
| 486 |
for (i=0; i<dim; i++) { |
| 487 |
for (j=0; j<dim; j++) printf("D[%i,%i]=%1.5f ", i,j,D[i*dim+j]); |
| 488 |
putchar('\n');
|
| 489 |
} |
| 490 |
putchar('\n');
|
| 491 |
#endif
|
| 492 |
|
| 493 |
/* Free 1 Matrix and 2 Vectors of dimension dim */
|
| 494 |
|
| 495 |
free(A); |
| 496 |
free(B); |
| 497 |
free(C); |
| 498 |
free(D); |
| 499 |
|
| 500 |
putchar('\n');
|
| 501 |
|
| 502 |
#ifdef CUBLAS
|
| 503 |
double memoryIn,memoryOut;
|
| 504 |
|
| 505 |
memoryIn=(double)((tv3.tv_sec-tv1.tv_sec) * 1000000L + \ |
| 506 |
(tv3.tv_usec-tv1.tv_usec))/1000000.; |
| 507 |
|
| 508 |
memoryOut=(double)((tv2.tv_sec-tv4.tv_sec) * 1000000L + \ |
| 509 |
(tv2.tv_usec-tv4.tv_usec))/1000000.; |
| 510 |
|
| 511 |
duration=(double)((tv4.tv_sec-tv3.tv_sec) * 1000000L + \ |
| 512 |
(tv4.tv_usec-tv3.tv_usec))/1000000./RUNS; |
| 513 |
|
| 514 |
printf("Duration of memory allocation : %2.10f s\n",memoryIn);
|
| 515 |
printf("Duration of memory free : %2.10f s\n",memoryOut);
|
| 516 |
#else
|
| 517 |
duration=(double)((tv2.tv_sec-tv1.tv_sec) * 1000000L + \ |
| 518 |
(tv2.tv_usec-tv1.tv_usec))/1000000./RUNS; |
| 519 |
|
| 520 |
#endif
|
| 521 |
|
| 522 |
printf("Duration of each cycle : %2.10f s\n",duration);
|
| 523 |
|
| 524 |
printf("Number of GFlops : %2.3f \n",
|
| 525 |
dim*dim*2.*(2.*dim-1)/duration/1000000000.); |
| 526 |
|
| 527 |
printf("Error %1.10f\n",checksA[0]); |
| 528 |
printResults(RUNS,checksA,"C","Errors cumulated"); |
| 529 |
|
| 530 |
putchar('\n');
|
| 531 |
|
| 532 |
/* Free 2 vectors for checker Before and After */
|
| 533 |
|
| 534 |
free(checksA); |
| 535 |
free(checksB); |
| 536 |
|
| 537 |
return 0; |
| 538 |
} |
| 539 |
|
| 540 |
int main(int argc,char **argv) |
| 541 |
{
|
| 542 |
if ((argc==1)|| |
| 543 |
(strcmp(argv[1],"-h")==0)|| |
| 544 |
(strcmp(argv[1],"--help")==0)) |
| 545 |
{
|
| 546 |
printf("\nPerforms a bench using BLAS library implementation:\n\n"
|
| 547 |
"\t#1 Size of square matrices \n"
|
| 548 |
"\t#2 Number of iterations\n\n");
|
| 549 |
} |
| 550 |
else if ((atoi(argv[1])>=2)&& |
| 551 |
(atoi(argv[2])>=1)) |
| 552 |
{
|
| 553 |
bench(atoi(argv[1]),atoi(argv[2])); |
| 554 |
} |
| 555 |
|
| 556 |
return 0; |
| 557 |
} |