Question: Is it possible to sort objects using the Thrust library?
I have the following struct:

```
struct OB{
  int N;
  Cls *C; //CLS is another struct.
}

```

Is it possible to use thrust in order to sort an array of OB according to N? Can you provide a simple example on using thrust to sort objects? If thrust is not able to do so, is there any other CUDA libraries that allows me to do so?

Answer: 
The docs for [thrust::sort](http://wiki.thrust.googlecode.com/hg/html/group__sorting.html) show it accepts a comparison operator. See in their [example](http://code.google.com/p/thrust/source/browse/examples/sort.cu) how those are defined and used. I haven't tested this, but based on the example, all you would need is a struct that looks something like this:

```
struct OBCmp {
  __host__ __device__
  bool operator()(const OB& o1, const OB& o2) {
      return o1.N < o2.N;
  }
};

```

and then just invoke `thrust::sort(obs.begin(), obs.end(), OBCmp())`.
Up until now you cannot sort custom objects. You can do key based sorting but not of custom objects like the struct you mentioned. There are a couple of other open CUDA based algorithms available for doing this but that too requires some modification etc to make them work for you.