扫描大型阵列

scan for large arrays

我想对大型阵列使用 Thrust 库中的扫描功能,但我对大于 32768 的阵列进行了核心转储。我想知道是否还有 thrust_scan 以外的其他选项。

这是我的代码片段:

  #include <thrust/scan.h>
  #include <stdio.h>

   int main()

   {

       int *x;
       int n = 65536;
      x = (int *) malloc(n);
      for (int i=0;i<n;i++)
          x[i]=i;
      thrust::inclusive_scan(x,x+n,x);
      for (int i=0;i<n;i++)
          printf(" %d ", x[i]);
          printf("\n");

  }

这个:

x = (int *) malloc(n);

分配 n 字节 的存储空间。您想要存储 n 个整数:

x = (int *) malloc(n*sizeof(int));