我一直在尝试将 COO 矩阵的行索引、列索引和值复制到单独的推力向量中,但我发现我无法这样做。
下面是代码
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 是一个推力向量指针,已在之前的一些代码中分配了内存,此处不相关。
代码编译,但在运行时失败并出现错误:
在抛出“thrust::system::system_error”实例后调用终止 what(): invalid argument Aborted (core dumped)
有人可以告诉我我做错了什么吗?
谢谢阿克谢