Question

I downloaded thrust 1.70 and 1.60 from thrust webpage to my home directory, /home/me/project/thrust. When I try to run the example below, using gcc -c -I/home/me/project thrust_1_example.cpp , I received error messages that header files are not found: 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

I found that detail/config is indeed empty. Am I missing something?

#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;
}
Was it helpful?

Solution

If you simply install CUDA 5.5 you will get thrust 1.7.

If you are targeting a GPU backend (meaning you want to run your thrust code on the GPU) it requires nvcc, the GPU device code compiler/compiler driver, which comes with CUDA 5.5.

You cannot build thrust GPU code with gcc (you must use nvcc) and the file name should end in .cu not .cpp

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top