Sorting complex CSR matrix for sparse multiplication


I have a sparse matrix in CSR format with complex values that I am reading into a CUDA function. I have to use the Xcsrsort function to get all of the components in a form that is compatible with the csrmv multiplication, and am getting a weird problem.

I have implemented the sorting exactly as it is presented in the cuSparse documentation (section 12.28), and it all appears to work correctly apart from the fact that the real part of the complex values gets scrambled. All of the imaginary parts of my complex values are in the correct positions based on the sorting index, and I can’t work out where I might be going wrong.

Any ideas or suggestions would be gratefully received!