Sparse Matrix Segfault

2013-03-03
2013-06-12
  • Hi,

    I seem to be having trouble multiplying sparse matricies, I think I may be missing something completely, but here's a test case that illustrates what I'm having trouble with

        std::vector< std::map< unsigned int, float> > cpuMatrix(4);
        viennacl::matrix<float> denseMatrix(4, 5);
        viennacl::vector<float> test(4), result(5);
        cpuMatrix[0][0] = 2;
        cpuMatrix[1][1] = 2;
        cpuMatrix[2][2] = 2;
        cpuMatrix[3][3] = 2;
        denseMatrix(0,0) = 2;
        denseMatrix(1,1) = 2;
        denseMatrix(2,2) = 2;
        denseMatrix(3,3) = 2;
        test[0] = 1.;
        test[1] = 2.;
        test[2] = 3.;
        test[3] = 4.;
        viennacl::compressed_matrix<float> sparseMatrix(4, 5);
        viennacl::copy(cpuMatrix, sparseMatrix);
        // No problem with dense matricies
        result = viennacl::linalg::prod(viennacl::trans(denseMatrix), test);
        // Segfaults
        result = viennacl::linalg::prod(viennacl::trans(sparseMatrix), test);
    

    Did I miss something obvious? I'm on OSX 10.8.2, using ViennaCL 1.4.1 if it helps.

     
  • Karl Rupp
    Karl Rupp
    2013-03-03

    Hi,

    transposed sparse matrix-vector products are not yet supported. (I'm actually surprised the code even compiles - we definitely need to make the compilation fail with a good error message).

    The reason is that the various sparse matrix format are not suited for parallel transposed products. Thus, in order to get any reasonable performance, we would have to transpose the sparse matrix on the CPU first. Meanwhile, here is what I recommend to you: Set up a transposed matrix by hand on the CPU (similar to how you do now for cpuMatrix) and then use prod() without trans() on the transposed matrix.

    Best regards,
    Karli