Inverse of cusparse<t>gthr() ?

Hi all,

This is my first message. I hope someone can help me here. I have a sparse float vector (about 3M non-zero elements; dense vector would be about 200M elements) and I want to copy a series of values (about 200K) from this vector to a dense vector. How do I do this most efficiently?


Naive pseudo code:

void gather_from_sparse(const float * xVal,
                        const int * xInd,
                        const int nnz,
                        const int dense_size,
                        const int nr_desired_vals,
                        const int * desired_indices,
                        float * output)
   float * dense = new float[dense_size];
   for (int i = 0; i < nnz; ++i)
      dense[xInd[i]] = xVal[i];
   for (int j = 0; j < nr_desired_vals; ++j)
      output[j] = dense[desired_indices[j]];
   delete dense;

Some things that might make it easier:

  • xInd and desired_indices will always be sorted in ascending order
  • desired_indices is always a subset of xInd

are you wanting to do this on the host or on the device?

thrust has gathering and scattering functions which may be useful

Hi txbob, this is all on the device. I have about 500 of these sparse vectors loaded (using a Titan X). After extracting the values I do some computations and repeat. Everything ideally fully stays on the device.