a = a + b + c라고 쓰는 것이 더 효율적인 방법인지 궁금합니다.STL 추력 다중 벡터 변환?
thrust::transform(b.begin(), b.end(), c.begin(), b.begin(), thrust::plus<int>());
thrust::transform(a.begin(), a.end(), b.begin(), a.begin(), thrust::plus<int>());
이 작동하지만 한 줄의 코드를 사용하여 동일한 효과를 얻을 수있는 방법이 있나요? 예제에서 saxpy 구현을 살펴 보았으나 2 개의 벡터와 상수 값을 사용합니다.
이 방법이 더 효율적입니까?
struct arbitrary_functor
{
template <typename Tuple>
__host__ __device__
void operator()(Tuple t)
{
// D[i] = A[i] + B[i] + C[i];
thrust::get<3>(t) = thrust::get<0>(t) + thrust::get<1>(t) + thrust::get<2>(t);
}
};
int main(){
// allocate storage
thrust::host_vector<int> A;
thrust::host_vector<int> B;
thrust::host_vector<int> C;
// initialize input vectors
A.push_back(10);
B.push_back(10);
C.push_back(10);
// apply the transformation
thrust::for_each(thrust::make_zip_iterator(thrust::make_tuple(A.begin(), B.begin(), C.begin(), A.begin())),
thrust::make_zip_iterator(thrust::make_tuple(A.end(), B.end(), C.end(), A.end())),
arbitrary_functor());
// print the output
std::cout << A[0] << std::endl;
return 0;
}
이것은 나에게 꽤 좋아 보인다. –