-1

I am trying to convert a sparse matrix into csr format using CUSP and CUDA. I modified slightly the code shown in CUSP documentation:

#include <cusp/array2d.h>
#include <cusp/coo_matrix.h>
#include <cusp/csr_matrix.h>
#include <cusp/print.h>
int main(void)
{
// create a simple example
cusp::array2d<float, cusp::host_memory> A(3,4);
A(0,0) = 10;  A(0,1) =  0;  A(0,2) = 20;  A(0,3) =  0;
A(1,0) =  0;  A(1,1) = 30;  A(1,2) =  0;  A(1,3) = 40;
A(2,0) = 50;  A(2,1) = 60;  A(2,2) = 70;  A(2,3) = 80;
print(A);
// save A to disk in MatrixMarket format
cusp::io::write_matrix_market_file(A, "A.mtx");
// load A from disk into a coo_matrix
cusp::csr_matrix<int, float, cusp::device_memory> B;
cusp::io::read_matrix_market_file(B, "A.mtx");

cusp::io::write_matrix_market_file(B,"B.mtx");
// print B
cusp::print(B);
return 0;
}

But the result I get is the matrix in coo format with the indices shifted by 1:

%%MatrixMarket matrix coordinate real general
3   4   8
1 1 10
1 3 20
2 2 30
2 4 40
3 1 50
3 2 60
3 3 70
3 4 80

Any help ?

Thanks.

The Hiary
  • 109
  • 1
  • 13
  • I'm not sure what you want help with. Read this http://math.nist.gov/MatrixMarket/formats.html – talonmies Jun 07 '15 at 05:35
  • As @talonmies has pointed out, the matrix market format is something akin to a COO format. You will not see the matrix market file containing a CSR-looking format. Your actual printout appears to be a matrix market file, not the output from the `cusp::print` command. And the offset-by-1 is already explained in the link that talonmies provided. I can run a slightly modified version of your code, and the `cusp::print` command does print out the matrix, but it is still in a COO format although not offset-by-1. – Robert Crovella Jun 09 '15 at 01:47
  • If you are wanting to print out the CSR format data, you will need to do it manually by printing out the arrays underlying the matrices. So if you want help, please clarify what it is you are wanting to see or trying to do, specifically. – Robert Crovella Jun 09 '15 at 01:47
  • Thanks for the responses ! – Angiolo Huaman Jun 10 '15 at 04:04
  • Possible duplicate of [Not able to understand output of CSR Representation in CUSP](https://stackoverflow.com/questions/16315727/not-able-to-understand-output-of-csr-representation-in-cusp) – The Hiary Jun 08 '18 at 15:57

1 Answers1

1

Thanks for the responses ! Indeed I had to write the csr format by hand although it was not so hard as I initially thought. My code resulted like this:

// Imprimimos la matriz en formato csr:
cout<<"\n=======================\n";
cout<<"Matriz de adyacencia en formato CSR:\n";
cout<<"Row-offset   :";
for (int j=0 ; j<10 ; j++) cout<<B.row_offsets[j]<<" ";
cout<<"\n"; cout<<"Column index :";
for (int j=0 ; j<17 ; j++) cout<<B.column_indices[j]<<" ";
cout<<"\n"; cout<<"Values:";
for (int j=0 ; j<17 ; j++) cout<<B.values[j]<<" ";   
cout<<"\n==================\n";