Menu

A CSR matrix consists of 3 arrays, how can I use it with the linear solvers e.g. CG?

tario
2017-08-15
2017-08-15
  • tario

    tario - 2017-08-15

    Hello,

    ViennaCL works with matrices in CSR format which consists of:

    1: A column index array int* p_c_idx = &(c_idx[0]) ;

    2: A row index array int* p_r_idx = &(r_idx[0]) ;

    3: A value array scalar* p_vals = &(vals[0]) ;

    This (1,2,3) is what I have after importing and converting the matrix of my engineering application.

    Then I have the vectors

    const scalar B = source.cdata() ;
    scalar X = psi.data() ;
    

    How can I use the above to solve the system with the linear solvers cg and bicgstab?

    T.

     
  • tario

    tario - 2017-08-20

    I think, I made some progress here but there's one compile error left:

    vclPCG.C:205:27: error: invalid use of non-static member function
    ldu2vcl(matrix, vclMat);

    The function is:

    // Import the CSR matrix for use with ViennaCL
    void ldu2vcl
    (
        const Foam::lduMatrix & matrix, viennacl::compressed_matrix<scalar>& vclMat
    )
    {
        uint N_DIAG = matrix.diag().size();
        uint lduMatrixSIZE = matrix.lower().size() + matrix.upper().size() + matrix.diag().size(); // nnz
    
        // allocat mem for CSR sparse matrix 
        scalar * v = (scalar *)calloc(lduMatrixSIZE, sizeof(scalar));
        uint * c = (uint *)calloc(lduMatrixSIZE, sizeof(uint));
        uint * r = (uint *)calloc(N_DIAG + 2, sizeof(uint));
    
        ldu2csr(matrix,v,c,r);
        vclMat.set(r,c,v,N_DIAG,N_DIAG,lduMatrixSIZE);   // ViennaCL compressed_matrix structure
    
        // free and release the matrix mem
        free(v); free(r); free(c);  //colloc()  
    }
    

    And I use it here:

    ...
        viennacl::compressed_matrix<scalar> vclMat; // matrix
        ldu2vcl(matrix, vclMat); // this gives me the error
    ...
    

    Do you have any hint what causes the problem?

    T.

     
  • Karl Rupp

    Karl Rupp - 2017-08-24

    Hi tario,

    I think the compilation problem requires more context to diagnose. It doesn't seem to be ViennaCL-related, but something related to the structure of your code.

    Best regards,
    Karli

     

Log in to post a comment.