I’m using CUDA to build a particle system for ray-tracing based on SPH method. Here for my particle class, any object has a stl vector which contains the index of the neighbor paricles. I want to use the arrays in CUDA kernel, but thrust can only be called on host, and the lengh of the array of the neighbor differs for each particle, makes the size of the class object undecided.
Is there any data container that implements such arrays of variable length? or any method to return the array of such dynamic data?
thrust can only be called on host
This is not true. See here
Thanks for replying. Indeed thrust fuction can be called to return the result of some calculations for vectors. However, the result I want to get is a vector. And each expected vector calculated by one thread has different length, which directly depends on how many neighbors are around the center particle. IMO, this problem mainly involves the usage of dynamic memory allocation, while I know it might destroy the performance. Therefore, I’m wondering any better solution if possible:)
Is there a max number of neighbors around a particle?
Thanks very much！ allocating the dynamic array is useful. I can loop over all of the particles for one time to get the number of the neighbors for each particle and then allocate respective size array to in the second identical iteration.