| 25 |
25 |
#include "fortran_common.h"
|
| 26 |
26 |
#include "fortran_thunking.h"
|
| 27 |
27 |
#elif FBLAS
|
|
28 |
#include <cblas.h>
|
| 28 |
29 |
#include <cblas_f77.h>
|
| 29 |
30 |
#elif GSL
|
| 30 |
31 |
#include <gsl_cblas.h>
|
| 31 |
32 |
#elif ACML
|
| 32 |
33 |
#include <acml.h>
|
| 33 |
|
#include <acml_mv.h>
|
| 34 |
34 |
#else
|
| 35 |
35 |
#include <cblas.h>
|
|
36 |
#include <blaswrap.h>
|
| 36 |
37 |
#endif
|
| 37 |
38 |
|
| 38 |
39 |
#ifdef DOUBLE
|
| ... | ... | |
| 41 |
42 |
#define LENGTH float
|
| 42 |
43 |
#endif
|
| 43 |
44 |
|
| 44 |
|
#ifdef FBLAS
|
| 45 |
|
|
| 46 |
|
#ifdef DOUBLE
|
| 47 |
|
|
| 48 |
|
void dtrsv_( FCHAR, FCHAR, FCHAR, FINT, const double *, FINT, double *, FINT);
|
| 49 |
|
|
| 50 |
|
void dgemv_(FCHAR, FINT, FINT, const double *, const double *, FINT,
|
| 51 |
|
const double *, FINT, const double *, double *, FINT);
|
| 52 |
|
|
| 53 |
|
void dswap_( FINT, double *, FINT, double *, FINT);
|
| 54 |
|
|
| 55 |
|
void daxpy_( FINT, const double *, const double *, FINT, double *, FINT);
|
| 56 |
|
|
| 57 |
|
void dnrm2_( FINT, const double *, FINT, double *);
|
| 58 |
|
|
| 59 |
|
#else
|
| 60 |
|
|
| 61 |
|
void strsv_( FCHAR, FCHAR, FCHAR, FINT, const float *, FINT, float *, FINT);
|
| 62 |
|
|
| 63 |
|
void sgemv_(FCHAR, FINT, FINT, const float *, const float *, FINT,
|
| 64 |
|
const float *, FINT, const float *, float *, FINT);
|
| 65 |
|
|
| 66 |
|
void sswap_( FINT, float *, FINT, float *, FINT);
|
| 67 |
|
|
| 68 |
|
void saxpy_( FINT, const float *, const float *, FINT, float *, FINT);
|
| 69 |
|
|
| 70 |
|
void snrm2_( FINT, const float *, FINT, float *);
|
| 71 |
|
|
| 72 |
|
#endif
|
| 73 |
|
|
| 74 |
|
#endif
|
| 75 |
|
|
| 76 |
45 |
/* Matrix with only defined triangular terms */
|
| 77 |
46 |
/* Even if there are 0 in matrix, must be defined at all ! */
|
| 78 |
47 |
|
| ... | ... | |
| 217 |
186 |
if (j>i)
|
| 218 |
187 |
{
|
| 219 |
188 |
/* Normalization is necessary to avoid problems */
|
|
189 |
/* A[i*dim+j]=(LENGTH)rand()/(RAND_MAX+1.) */
|
|
190 |
/* *(LENGTH)(i+1.)/(LENGTH)(j+1.); */
|
| 220 |
191 |
A[i*dim+j]=(LENGTH)rand()/(RAND_MAX+1.)
|
| 221 |
|
*(LENGTH)(i+1.)/(LENGTH)(j+1.);
|
|
192 |
/(LENGTH)(dim-j);
|
| 222 |
193 |
}
|
| 223 |
194 |
else if (j==i)
|
| 224 |
195 |
{
|
| ... | ... | |
| 314 |
285 |
printVectorGPU(dim,devPtrX,"X","Errors");
|
| 315 |
286 |
|
| 316 |
287 |
/* Estimate the second checker */
|
| 317 |
|
/* checksA[i]=(double)cublasDnrm2(dim,devPtrX,incx); */
|
|
288 |
checksA[i]=(double)cublasDnrm2(dim,devPtrX,incx);
|
| 318 |
289 |
|
| 319 |
290 |
/* Swap vector X and Y */
|
| 320 |
291 |
cublasDswap(dim,devPtrX,incx,devPtrY,incx);
|
| ... | ... | |
| 340 |
311 |
printVectorGPU(dim,devPtrX,"X","Errors");
|
| 341 |
312 |
|
| 342 |
313 |
/* Estimate the second checker */
|
| 343 |
|
/* checksA[i]=(double)cublasSnrm2(dim,devPtrX,incx); */
|
|
314 |
checksA[i]=(double)cublasSnrm2(dim,devPtrX,incx);
|
| 344 |
315 |
|
| 345 |
316 |
/* Swap vector X and Y */
|
| 346 |
317 |
cublasSswap(dim,devPtrX,incx,devPtrY,incx);
|
| ... | ... | |
| 395 |
366 |
printVector(dim,X,"X","Errors");
|
| 396 |
367 |
|
| 397 |
368 |
/* Store the checker of errors */
|
| 398 |
|
/* checksA[i]=(double)CUBLAS_DNRM2(&dim,X,&incx); */
|
|
369 |
checksA[i]=(double)CUBLAS_DNRM2(&dim,X,&incx);
|
| 399 |
370 |
|
| 400 |
371 |
/* Swap vector X and Y */
|
| 401 |
372 |
CUBLAS_DSWAP(&dim,X,&incx,Y,&incx);
|
| ... | ... | |
| 419 |
390 |
printVector(dim,X,"X","Errors");
|
| 420 |
391 |
|
| 421 |
392 |
/* Store the checker of errors */
|
| 422 |
|
/* checksA[i]=(double)CUBLAS_SNRM2(&dim,X,&incx); */
|
|
393 |
checksA[i]=(double)CUBLAS_SNRM2(&dim,X,&incx);
|
| 423 |
394 |
|
| 424 |
395 |
/* Swap vector X and Y */
|
| 425 |
396 |
CUBLAS_SSWAP(&dim,X,&incx,Y,&incx);
|
| ... | ... | |
| 443 |
414 |
{
|
| 444 |
415 |
#ifdef DOUBLE
|
| 445 |
416 |
|
| 446 |
|
printVector(dim,X,"X","Roots");
|
|
417 |
printVector(dim,X,"X","Initial roots");
|
| 447 |
418 |
|
| 448 |
419 |
/* Multiply A by X as Y <- A.X */
|
| 449 |
420 |
dgemv_(&trans,&dim,&dim,&alpha,A,&dim,X,&incx,&beta,Y,&incx);
|
| 450 |
421 |
|
| 451 |
|
printVector(dim,Y,"Y","Results");
|
|
422 |
printVector(dim,Y,"Y<-A.X","Estimated results");
|
| 452 |
423 |
|
| 453 |
424 |
/* Solve linear system */
|
| 454 |
425 |
dtrsv_(&uplo,&trans,&diag,&dim,A,&dim,Y,&incx);
|
| 455 |
426 |
|
| 456 |
|
printVector(dim,Y,"Y","Solutions");
|
|
427 |
printVector(dim,Y,"X","Solutions from A.X=Y");
|
| 457 |
428 |
|
| 458 |
429 |
/* Compare the roots X and Y */
|
| 459 |
430 |
daxpy_(&dim,&beta2,Y,&incx,X,&incx);
|
| 460 |
431 |
|
| 461 |
|
printVector(dim,X,"X","Errors");
|
|
432 |
printVector(dim,X,"X","Differences initial and estimated");
|
| 462 |
433 |
|
| 463 |
434 |
/* Store the checker of errors */
|
| 464 |
|
/* dnrm2_(&dim,X,&incx,&checksA[i]); */
|
|
435 |
dnrm2_(&dim,X,&incx,&checksA[i]);
|
| 465 |
436 |
|
| 466 |
437 |
/* Swap vector X and Y */
|
| 467 |
438 |
dswap_(&dim,X,&incx,Y,&incx);
|
| ... | ... | |
| 486 |
457 |
printVector(dim,X,"X","Errors");
|
| 487 |
458 |
|
| 488 |
459 |
/* Store the checker of errors */
|
| 489 |
|
/* snrm2_(&dim,X,&incx,&checksA[i]); */
|
|
460 |
snrm2_(&dim,X,&incx,&checksA[i]);
|
| 490 |
461 |
|
| 491 |
462 |
/* Swap vector X and Y */
|
| 492 |
463 |
sswap_(&dim,X,&incx,Y,&incx);
|
| ... | ... | |
| 524 |
495 |
printVector(dim,X,"X","Errors");
|
| 525 |
496 |
|
| 526 |
497 |
/* Store the checker of errors */
|
| 527 |
|
/* dnrm2_(&dim,X,&incx,&checksA[i]); */
|
|
498 |
dnrm2_(&dim,X,&incx,&checksA[i]);
|
| 528 |
499 |
|
| 529 |
500 |
/* Swap vector X and Y */
|
| 530 |
501 |
dswap(dim,X,incx,Y,incx);
|
| ... | ... | |
| 549 |
520 |
printVector(dim,X,"X","Errors");
|
| 550 |
521 |
|
| 551 |
522 |
/* Store the checker of errors */
|
| 552 |
|
/* snrm2_(&dim,X,&incx,&checksA[i]); */
|
|
523 |
snrm2_(&dim,X,&incx,&checksA[i]);
|
| 553 |
524 |
|
| 554 |
525 |
/* Swap vector X and Y */
|
| 555 |
526 |
sswap(dim,X,incx,Y,incx);
|
| ... | ... | |
| 592 |
563 |
printVector(dim,X,"X","Errors");
|
| 593 |
564 |
|
| 594 |
565 |
/* Store the checker of errors */
|
| 595 |
|
/* checksA[i]=(double)cblas_dnrm2(dim,X,incx); */
|
|
566 |
checksA[i]=(double)cblas_dnrm2(dim,X,incx);
|
| 596 |
567 |
|
| 597 |
568 |
cblas_dswap(dim,X,incx,Y,incx);
|
| 598 |
569 |
|
| ... | ... | |
| 617 |
588 |
printVector(dim,X,"X","Errors");
|
| 618 |
589 |
|
| 619 |
590 |
/* Store the checker of errors */
|
| 620 |
|
/* checksA[i]=(double)cblas_snrm2(dim,X,incx); */
|
|
591 |
checksA[i]=(double)cblas_snrm2(dim,X,incx);
|
| 621 |
592 |
|
| 622 |
593 |
cblas_sswap(dim,X,incx,Y,incx);
|
| 623 |
594 |
|
| ... | ... | |
| 659 |
630 |
printVector(dim,X,"X","Errors");
|
| 660 |
631 |
|
| 661 |
632 |
/* Store the checker of errors */
|
| 662 |
|
/* checksA[i]=(double)cblas_dnrm2(dim,X,incx); */
|
|
633 |
checksA[i]=(double)cblas_dnrm2(dim,X,incx);
|
| 663 |
634 |
|
| 664 |
635 |
cblas_dswap(dim,X,incx,Y,incx);
|
| 665 |
636 |
|
| ... | ... | |
| 684 |
655 |
printVector(dim,X,"X","Errors");
|
| 685 |
656 |
|
| 686 |
657 |
/* Store the checker of errors */
|
| 687 |
|
/* checksA[i]=(double)cblas_snrm2(dim,X,incx); */
|
| 688 |
|
|
|
658 |
checksA[i]=(double)cblas_snrm2(dim,X,incx);
|
|
659 |
|
| 689 |
660 |
cblas_sswap(dim,X,incx,Y,incx);
|
| 690 |
661 |
|
| 691 |
662 |
#endif
|