スラスト zip イテレータを使用して複数の CUDA 配列を圧縮しようとすると、紛らわしいエラーが発生します。私の場合は単純です。オブジェクトのステータスを示す整数の Thrust::vector と、オブジェクトの位置と速度を 3D で示す float の 6 つのベクトルがあります。ステータス(整数)ベクトル要素の値が 1 の場合、すべてのベクトルからその要素を削除し、ベクトルを縮小したいと考えています。
この例に従って、7 通りのタプルと述語を使用します。
// Predicate
struct isTupleFlagged
{
__host__ __device__ bool operator() ( const PartTuple& tup )
{
const int x = thrust::get<0>( tup );
return ( x == 1 );
}
};
void ParticleSystem::RemoveFlaggedParticles()
{
typedef thrust::device_vector< int >::iterator IntDIter;
typedef thrust::device_vector< float >::iterator FloatDIter;
typedef thrust::tuple< IntDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter, FloatDIter > PartDIterTuple;
typedef thrust::zip_iterator< PartDIterTuple > ZipDIter;
ZipDIter newEnd = thrust::remove_if( thrust::make_zip_iterator( thrust::make_tuple( exit.begin(), x.begin(), y.begin(), z.begin(), vx.begin(), vy.begin(), vz.begin() ) ),
thrust::make_zip_iterator( thrust::make_tuple( exit.end(), x.end(), y.end(), z.end(), vx.end(), vy.end(), vz.end() ) ),
isTupleFlagged() );
PartDIterTuple endTuple = newEnd.get_iterator_tuple();
exit.erase(thrust::get<0>( endTuple ), exit.end());
x.erase( thrust::get<1>( endTuple ), x.end() );
y.erase( thrust::get<2>( endTuple ), y.end() );
z.erase( thrust::get<3>( endTuple ), z.end() );
vx.erase( thrust::get<4>( endTuple ), vx.end() );
vy.erase( thrust::get<5>( endTuple ), vy.end() );
vz.erase( thrust::get<6>( endTuple ), vz.end() );
}
ただし、これは余分な要素を誤って削除するようです。たとえば、フラグが設定されたオブジェクトが 100 のベクトルに 1 つある場合、圧縮後のベクトルのサイズは 52 であり、予想される 99 ではありません。私は何を逃したのですか?