Search code examples
cudagpunvidiathrust

push_back using Thrust library


Is it possible to use push_back with Thrust library? and what about a vector of vectors? I would like to use in the GPU what in the CPu is:

 vector< vector<int> > MyVector( 100 );
 ...
 MyVector[i].push_back(j);

Is there a way to use it like for example:

thrust::device_vector<thrust::device_vector<int>> d_vec(4);

and what about creating an array of device_vectors? Is it possible?


Solution

    1. Yes, thrust::device_vector has a push_back method just like a std::vector.
    2. No, it is not possible to have a device_vector containing device_vectors. If you need that sort of functionality in thrust I would recommend looking at thrust::zip_iterator which can provide "array of structures" like access to a series of distinct vectors or iterators.