我从推力webpage将推力1.70和1.60下载到我的主目录/home/me/project/thrust
。当我尝试使用gcc -c -I/home/me/project thrust_1_example.cpp
运行下面的example时,收到错误消息,提示未找到头文件:In file included from /home/me/project/thrust/detail/config.h:22, from /home/me/project/thrust/host_vector.h:24, from thrust_1_example.cpp:1:/home/me/project/thrust/detail/config/config.h:25:49: error: thrust/detail/config/simple_defines.h: No such file or directory
我发现detail/config
确实是空的。我想念什么吗?
#include <thrust/host_vector.h>
#include <thrust/device_vector.h>
#include <iostream>
int main(void)
{
// H has storage for 4 integers
thrust::host_vector<int> H(4);
// initialize individual elements
H[0] = 14;
H[1] = 20;
H[2] = 38;
H[3] = 46;
// H.size() returns the size of vector H
std::cout << "H has size " << H.size() << std::endl;
// print contents of H
for(int i = 0; i < H.size(); i++)
std::cout << "H[" << i << "] = " << H[i] << std::endl;
// resize H
H.resize(2);
std::cout << "H now has size " << H.size() << std::endl;
// Copy host_vector H to device_vector D
thrust::device_vector<int> D = H;
// elements of D can be modified
D[0] = 99;
D[1] = 88;
// print contents of D
for(int i = 0; i < D.size(); i++)
std::cout << "D[" << i << "] = " << D[i] << std::endl;
// H and D are automatically deleted when the function returns
return 0;
}
最佳答案
如果仅安装CUDA 5.5,您将获得推力1.7。
如果您以GPU后端为目标(意味着您想在GPU上运行推力代码),则需要nvcc
,CUDA 5.5随附的GPU设备代码编译器/编译器驱动程序。
您不能使用gcc
构建推力GPU代码(必须使用nvcc
),并且文件名应以.cu
而不是.cpp
结尾
关于c++ - 编译推力示例代码时未找到头文件,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/20308625/