1

Thrust 将long long int视为long int。这是一个演示程序:

#include <thrust/reduce.h>
#include <thrust/iterator/constant_iterator.h>
void tryit(long long int n) {
  // with long long
  long long int s = 
thrust::reduce(thrust::constant_iterator<long long int>(1LL),
           thrust::constant_iterator<long long int>(1LL)+n);
  std::cout << "long long: " << n << ' ' << s << std::endl;
  // now with long
  long int n1 = n;
  long int s1 = 
thrust::reduce(thrust::constant_iterator<int>(1),
           thrust::constant_iterator<int>(1)+n1);
  std::cout << "long: " << n1 << ' ' << s1 << std::endl;
}
int main() {
  tryit(1000000);
  tryit(1000000000);
  tryit(10000000000);
}

输出是:

long long: 1000000 1000000
long: 1000000 1000000
long long: 1000000000 1000000000
long: 1000000000 1000000000
long long: 10000000000 1410065408
long: 10000000000 1410065408

第一个 141006540​​8 应该是 10000000000。

我这样编译它:

nvcc -arch=compute_30 -std=c++11 longlongb.cu -o longlongb

4

0 回答 0