I am trying to sort an array of class objects based on its type by passing a comparison function as the parameter to the thrust sort.
The class defination:
class TetraCutInfo
{
public:
int tetraid;
unsigned int ncutEdges;
unsigned int ncutNodes;
unsigned int type_cut;
__host__ __device__ TetraCutInfo();
};
Sort:
thrust::sort(cutInfoptr,cutInfoptr+n,cmp());
cutInfoptr is a pointer of type TetraCutInfo having the address of the device memory allocated using cudaMalloc.
Comparison function
struct cmp
{
__host__ __device__
bool operator()(const TetraCutInfo x, TetraCutInfo y)
{
return (x.type_cut < y.type_cut);
}
};
On running this I am getting Segmentation fault, however I am able to iterate through cutInfoptr in another kernel.
PS: I referred to the example in the link https://code.google.com/p/thrust/source/browse/examples/sort.cu