## convert dense to csr and save it

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

### convert dense to csr and save it

Hi, I create m*n dense matrix, convert it to csr and save it.
However, it always returns segmentation fault.
Code: Select all
`magma_init();magma_int_t dev=0;magma_queue_t queue=NULL;magma_queue_create(dev, &queue);magma_z_matrix *A=new magma_z_matrix;int m=48, n=10;magmaDoubleComplex *val;val=new magmaDoubleComplex[m*n];for (int i=0; i<m*n; i++){   val[i]=MAGMA_Z_MAKE(rand() / ((double) RAND_MAX),0);}std::cout<<"Set return:"<<magma_zvset(m, n, val, &A[0], queue)<<"\n";std::cout<<"Convert return:"<<magma_zmconvert(A[0], &A[0], Magma_DENSE, Magma_CSR, queue)<<"\n";write_z_csrtomtx(A[0],"test.mtx",queue);magma_z_mfree(A,queue);delete A;magma_queue_destroy( queue );magma_finalize();`

It returns
Set return:0
Convert return:0
write_csr_to_file :Segmentation fault

I also try "magma_zwrite_csr_mtx" function by setting RowMajor.
It will save mtx successfully, but it only contains 10*10 values.
How do I fix this problem?
thanks
mikemike10212003

Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

### Re: convert dense to csr and save it

Hi, I think I found the problem.
It have some error in magma-2.1.0/sparse-iter/control/magam_zmio.cpp
I change some variable, and the result it return is correct.
Code: Select all
`//print in ColMajor of complex part        fprintf( fp, "%d %d %d\n", int(B.num_cols), int(B.num_rows), int(B.nnz));                // TODO what's the difference between i (or i+1) and rowindex?        magma_index_t i=0, j=0, rowindex=1;                for(i=0; i < B.num_rows; i++) {            magma_index_t rowtemp1 = B.row[i];            magma_index_t rowtemp2 = B.row[i+1];            for(j=0; j < rowtemp2 - rowtemp1; j++) {                fprintf( fp, "%d %d %.16g %.16g\n",                    ((B.col)[rowtemp1+j]+1), rowindex,                    MAGMA_Z_REAL((B.val)[rowtemp1+j]),                    MAGMA_Z_IMAG((B.val)[rowtemp1+j]) );            }            rowindex++;        }`

Code: Select all
`//print in RowMajor of complex part        fprintf( fp, "%%%%MatrixMarket matrix coordinate complex general\n" );        fprintf( fp, "%d %d %d\n", int(A.num_rows), int(A.num_cols), int(A.nnz));                // TODO what's the difference between i (or i+1) and rowindex?        magma_index_t i=0, j=0, rowindex=1;                for(i=0; i < A.num_rows; i++) {            magma_index_t rowtemp1 = A.row[i];            magma_index_t rowtemp2 = A.row[i+1];            for(j=0; j < rowtemp2 - rowtemp1; j++) {                fprintf( fp, "%d %d %.16g %.16g\n",                    rowindex, ((A.col)[rowtemp1+j]+1),                     MAGMA_Z_REAL((A.val)[rowtemp1+j]),                    MAGMA_Z_IMAG((A.val)[rowtemp1+j]) );            }            rowindex++;        }`

It reads ash219.mtx and gemat1.mtx of Matrix Market and write it in colmajor and rowmajor by magma_zwrite_csr_mtx.
They are all correct.
ash219.mtx has more rows than cols. gemat1.mtx has more cols than rows.

The following attachment is magma_zmio.cpp I have changed the variable.
magma_zmio.cpp
change some variable in magma_zwrite_csr_mtx

magma_{f,d,c}mio.cpp need to be changed like it.
mikemike10212003

Posts: 10
Joined: Mon Oct 10, 2016 4:47 am

### Who is online

Users browsing this forum: No registered users and 5 guests