title: Converting a dense matrix to sparse CSR format with cuSPARSE
body: <p>I want to use <code>Scsrmv</code> cusparse function.</p>
  
  <p>Reading the documentation from <a href="http://docs.nvidia.com/cuda/cusparse/index.html#axzz33TAVudf5" rel="nofollow">here</a>, I can't figure how to define <code>csrRowPtrA</code> and <code>csrColIndA</code>:</p>
  
  <blockquote>
    <p>csrRowPtrA :  integer array of m+1 elements that contains the start of
    every row and the end of the last row plus one.</p>
    
    <p>csrColIndA :  integer array of nnz ( = csrRowPtrA(m) - csrRowPtrA(0) )
    column indices of the nonzero elements of matrix A.</p>
  </blockquote>
  
  <p>So , for example:</p>
  
  <pre><code>  float *devRow;
    cudaMalloc((void **)&amp;devRow, (m+1)*sizeof(float));
  </code></pre>
  
  <p>and if <code>A</code> is the matrix, then:</p>
  
  <pre><code>for (int i=0; i&lt;m; i+= n)   //m is rows , n is columns
      devRow[i] = A[i];
  </code></pre>
  
  <p>This is for the start of every row. For the last row and plus <code>1</code>? This confused me.</p>
  
  <p>And for columns? Something like:</p>
  
  <pre><code>for (int i=0;i&lt;nnz;i++)
     devCol = devRow[m] - devRow[0];
  </code></pre>