[Molds-dev] BLAS-wrapper was made (ticket #27830)

Back to archive index

Mikiya Fujii mikiy****@gmail*****
2012年 10月 9日 (火) 14:47:50 JST


Dear MolDS developers,

I made a BLAS-wrapper, MolDS_wrappers::Blas (ticket #27830).
Wrappers for matrix*matirx (MolDS_wrappers::Blas::Dgemm) and
matrix*vector(MolDS_wrappers::Blas::Dgemv) were only implemented.
Sorry to late, anyway, please use them.
Two examples of simplest use are shown below.

My bext,
Mikiya

    /***  example 1, for matrix*matrix (MolDS_wrappers::Blas::Dgemm): ***/
    #include"../wrappers/Blas.h"  // <- change the relative path to the Blas.h

    // matrixC = matrixA * matrixB
    double** matrixA=NULL; //m*k-matrix
    double** matrixB=NULL; //k*n-matirx
    double** matrixC=NULL; //m*n-matirx
    int m=2;
    int n=3;
    int k=4;
    MallocerFreer::GetInstance()->Malloc<double>(&matrixA,m,k);
    MallocerFreer::GetInstance()->Malloc<double>(&matrixB,k,n);
    MallocerFreer::GetInstance()->Malloc<double>(&matrixC,m,n);

    for(int i=0; i<m; i++){
       for(int j=0; j<k; j++){
          matrixA[i][j] = 0.23*(i*j+1);
       }
    }
    for(int i=0; i<k; i++){
       for(int j=0; j<n; j++){
          matrixB[i][j] = (i*j+2)/2 * 0.09 - 1.0;
       }
    }

    MolDS_wrappers::Blas::GetInstance()->Dgemm(m, n, k, matrixA,
matrixB, matrixC); // <- call BLAS-wrapper

    MallocerFreer::GetInstance()->Free<double>(&matrixA,m,k);
    MallocerFreer::GetInstance()->Free<double>(&matrixB,k,n);
    MallocerFreer::GetInstance()->Free<double>(&matrixC,m,n);


    /***  example 2, for matrix*vector (MolDS_wrappers::Blas::Dgemv): ***/
    #include"../wrappers/Blas.h"  // <- change the relative path to the Blas.h

    // vectorY = matrixA * vectorX
    double** matrixA=NULL; // m*n-matrix
    double*  vectorX=NULL; // n-vector
    double*  vectorY=NULL; // m-vector
    int m=2;
    int n=3;

    MallocerFreer::GetInstance()->Malloc<double>(&matrixA,m,n);
    MallocerFreer::GetInstance()->Malloc<double>(&vectorX,n);
    MallocerFreer::GetInstance()->Malloc<double>(&vectorY,m);

    matrixA[0][0]=1.0;  matrixA[0][1]=-2.0; matrixA[0][2]=2.4;
    matrixA[1][0]=10.0; matrixA[1][1]=-0.3; matrixA[1][2]=1.4;
    vectorX[0]=3.0; vectorX[1]=2.2; vectorX[2]=-2.3;
    vectorY[0]=3.0; vectorY[1]=2.2;

    MolDS_wrappers::Blas::GetInstance()->Dgemv(m, n, matrixA, vectorX,
vectorY); // <- call BLAS-wrapper

    MallocerFreer::GetInstance()->Free<double>(&matrixA,m,n);
    MallocerFreer::GetInstance()->Free<double>(&vectorX,n);
    MallocerFreer::GetInstance()->Free<double>(&vectorY,m);




MolDS-dev メーリングリストの案内
Back to archive index