I have been trying to copy the row indices, column indices and values of a COO matrix into separate thrust vectors, but I find that I am unable to do so.
Below is the code
cusp::coo_matrix <unsigned int, float, cusp::device_memory> *sim_mat;
sim_mat = new cusp::coo_matrix <unsigned int, float, cusp::device_memory>;
/* Code to fill up sim_mat: runs fine
...
*/
{
thrust::device_ptr <unsigned int> d_rows = &((sim_mat->row_indices));
thrust::device_ptr <unsigned int> d_cols = &((sim_mat->column_indices)[0]);
thrust::device_ptr <float> d_vals = &((sim_mat->values)[0]);
unsigned int size_nn = (sim_mat->row_indices).size();
thrust::device_vector <unsigned int> d_Rows;
thrust::device_vector <float> d_Vals;
thrust::device_vector <unsigned int> reduced_Rows;
// Code fails below this point
thrust::copy_n (d_rows, size_nn, d_Rows.begin());
thrust::copy_n (d_vals, size_nn, d_Vals.begin());
cout << size_nn << std::endl;
if (!(sim_mat->is_sorted_by_row()))
thrust::sort_by_key(d_Rows.begin(), d_Rows.end(), d_Vals.begin());
thrust::reduce_by_key(d_Rows.begin(), d_Rows.end(), d_Vals.begin(), reduced_Rows.begin(), sim_row->begin());
}
Ithe sim_row is a thrust vector pointer that has been allocated memory in some previous code and not relevant here.
The code compiles, but fails at run time with the error:
terminate called after throwing an instance of 'thrust::system::system_error' what(): invalid argument Aborted (core dumped)
Could someone tell me what am I doing wrong?
Thanks Akshay