당신이 원하는 것을 직접 할 방법이 없습니다. 기능적으로 동일한 것을 달성하는 두 가지 옵션이 있습니다.
첫 번째는 호출하기 전에 값 배열을 복사하여 원본 데이터를 정렬 및 정렬되지 않은 버전으로 남겨 둡니다. 그래서 예
thrust::device_vector<int> values_sorted(thrust::device_ptr<int>(values),
thrust::device_ptr<int>(values + numKeys));
thrust::sort_by_key(thrust::device_ptr<int>(keys),
thrust::device_ptr<int>(keys + numKeys),
values_sorted.begin());
두 번째 대안은 모든에 정렬에 값 배열을 전달하지 입니다된다. 추력은 배열이 저장되는 순서를 수정하지 않고 배열에 완벽하게 순차적으로 액세스 할 수있게하는 매우 유용한 순열 반복기를 사용합니다 (그렇게한다면 반복기 기반 수집 작업). 이렇게하려면 인덱스 벡터를 생성하고 대신 키가를 정렬 한 후 지금까지 변경하지 않고 index
에 의해 개최 keys
정렬 된 순서로 values
를 반환합니다, 지금 perm
typedef thrust::device_vector<int>::iterator iit;
thrust::device_vector<int> index(thrust::make_counting_iterator(int(0)),
thrust::make_counting_iterator(int(numKeys));
thrust::sort_by_key(thrust::device_ptr<int>(keys),
thrust::device_ptr<int>(keys + numKeys),
index.begin());
thrust::permutation_iterator<iit,iit> perm(thrust::device_ptr<int>(values),
index.begin());
같은 것을 그 정렬 된 인덱스 순열 반복자의 인스턴스 원래의 데이터의 순서.
[표준 면책 조항 : 브라우저에 작성된 모든 코드는 컴파일되거나 테스트되지 않았습니다. 본인 부담으로 사용하십시오]
http://stackoverflow.com/questions/13515308/cuda-thrust-and-sort-by-key –