Pro*_*mer 3 printf cuda nvidia thrust
我正在使用推力分区功能将数组划分为偶数和奇数.但是,当我尝试显示设备矢量时,它会显示随机值.请告诉我错误在哪里.我想我做的一切都是正确的.
#include<stdio.h>
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include<thrust/partition.h>
struct is_even
{
//const int toCom;
//is_even(int val):toCom(val){}
__device__
bool operator()(const int &x)
{
return x%2;
}
};
void main(){
thrust::host_vector<int> H(6);
for(int i =0 ; i<H.size();i++){
H[i] = i+1;
}
thrust::device_vector<int> D = H;
thrust::partition(D.begin(),D.end(),is_even());
for(int i =0 ;i< D.size();i++){
printf("%d,",D[i]);
}
getchar();
}
Run Code Online (Sandbox Code Playgroud)
您不能通过省略号发送thrust::device_reference(即结果D[i]),printf因为它不是POD类型.请参阅文档.您的代码将生成编译器警告此效果.
铸成int第一:
for(int i = 0; i < D.size(); ++i)
{
printf("%d,", (int) D[i]);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
443 次 |
| 最近记录: |