cuSPARSE (cusparseXcoo2csr) problem

Hello guys,

the problem is that I receive different csr’s ids each time when I call cusparseXcoo2csr. Below I show first ten ids, and you can see that they not identical.

ebondarenko@tesla-cmc:~/cg_solver/tests$ ./sparse_test ./mtx/bcsstk17.mtx.new
10974 : 10974
120428676, non zeros : 219812
0
1
2
3
150
150
150
150
223
223
ebondarenko@tesla-cmc:~/cg_solver/tests$ ./sparse_test ./mtx/bcsstk17.mtx.new
10974 : 10974
120428676, non zeros : 219812
0
1
2
3
77
77
77
4
223
223

The code I use:

#include <sparse_matrix.h>
#include

#include <cuda_runtime.h>
#include <cusparse.h>

#include <common.h>

#include

#include <unistd.h>

int main (int argc, char* argv)
{
cg_solver::sparse_matrix A(argv[1]);
std::vector x(A.columns(), 1);
std::vector b(A.rows());

std::cout << A.columns() << " : " << A.rows() << std::endl;
std::cout << A.size() << ", non zeros : " << A.nnz() << std::endl;

double alpha = 1;
double beta = 0;

int* d_r_i = 0;
cudaMallocManaged ((void**)&d_r_i, sizeof(int) * A.nnz());
cudaMemcpy (d_r_i, A.rows_indexes(), sizeof(int) * A.nnz(), cudaMemcpyHostToDevice);

cusparseHandle_t handle;
cusparseCreate (&handle);

cusparseMatDescr_t descrA;
cusparseCreateMatDescr (&descrA);

cusparseSetMatType(descrA, CUSPARSE_MATRIX_TYPE_SYMMETRIC);
cusparseSetMatIndexBase(descrA,CUSPARSE_INDEX_BASE_ZERO);

int* csrRowPtr = 0;
cudaMallocManaged ((void**)&csrRowPtr, sizeof(int) * (A.rows() + 1));

CUSPARSE_CHECK (cusparseXcoo2csr (handle, d_r_i, A.nnz(), A.rows(), csrRowPtr, CUSPARSE_INDEX_BASE_ZERO));

//Wait for the async call to finish
cudaError_t cudaStat = cudaDeviceSynchronize();
if(cudaStat != cudaSuccess)
{
std::cerr << “Unable to allocate device memory for operator\n”;
throw cudaStat;
}

for (int i = 0; i < A.rows()+1 && i < 10; i++) {
printf ("%d\n", csrRowPtr[i]);
}
return 0;
}

Many thanks!

  • Eduard