0

I'm having trouble running an openblas cblas test program. My Cblas runs perfectly when multiplying square matrixes, but when I try it with non square matrixes, I get the error "segmentation fault - core dumped" I checked and rechecked dimension problems but they seem to be right, so I am wondering what may be wrong. When I type m=200 instead of m=300 it works perfectly.

For instance, the following program does not work

    #include <iostream>
    #include <stdlib.h>

    extern "C"
    {
    #include <cblas.h>
    }



    using namespace std;

    int main()
    {
        double *a,*x, *y, *z;
        int m,k;
        m=300; k=200;

        a = (double *) malloc( m*k*sizeof( double ));
        x = (double *) malloc (k*sizeof(double));
        y = (double *) malloc (m*sizeof(double));
        z = (double *) malloc (m*sizeof(double));

        int i;

        for (i = 0; i < (m*k); ++i)
        {
            a[i] = 1;
        }

        for (i = 0; i < (k); ++i)
        {
            x[i] = 1;
        }

        for (i = 0; i < (m); ++i)
        {
            y[i] = 100 ;
        }

        cblas_dcopy(m,y,1,z,1);
        cblas_dgemv(CblasRowMajor,CblasNoTrans,m,k,1.0, a ,m ,x, 1, 1.0, z, 1);


        for (int i = 0; i<m; ++i)
        {
             cout<<z[i]<<endl;
        }

        free (a);
        free (x) ;
        free (y) ;
        free (z) ;

        return 0;
        }

Thanks a lot in advance

1 Answers1

0

I have figured out the problem : the parameter LDA given in the documentation of blas (the parameter that comes right after the matrix) corresponds to what they call the "leading dimension of the matrix". You must pass the number of rows of the matrix as LDA only in COLMAJOR system (used by Fortran), if you are using cblas in C or C++ you must pass the number of columns as LDA since the ROWMAJOR system is used.

Hope this may help someone in the future