Fork me on GitHub

What is Thrust?

Thrust is a parallel algorithms library which resembles the C++ Standard Template Library (STL). Thrust’s high-level interface greatly enhances programmer productivity while enabling performance portability between GPUs and multicore CPUs. Interoperability with established technologies (such as CUDA, TBB, and OpenMP) facilitates integration with existing software. Develop high-performance applications rapidly with Thrust!

Recent News

<ul id=recent_news>

  • Thrust v1.8.1 release (18 Mar 2015)
  • Thrust v1.8.0 release (12 Jan 2015)
  • Thrust v1.7.0 release (02 Jul 2013)
  • Thrust Content from GTC 2012 (12 May 2012)
  • Thrust v1.6.0 release (07 Mar 2012)
  • Thrust v1.5.1 release (30 Jan 2012)
  • Thrust v1.5.0 release (28 Nov 2011)
  • Thrust v1.3.0 release (05 Oct 2010)
  • </ul>

    View all news »

    Examples

    Thrust is best explained through examples. The following source code generates random numbers serially and then transfers them to a parallel device where they are sorted.

    #include <thrust/host_vector.h>
    #include <thrust/device_vector.h>
    #include <thrust/generate.h>
    #include <thrust/sort.h>
    #include <thrust/copy.h>
    #include <algorithm>
    #include <cstdlib>
    
    int main(void)
    {
      // generate 32M random numbers serially
      thrust::host_vector<int> h_vec(32 << 20);
      std::generate(h_vec.begin(), h_vec.end(), rand);
    
      // transfer data to the device
      thrust::device_vector<int> d_vec = h_vec;
    
      // sort data on the device (846M keys per second on GeForce GTX 480)
      thrust::sort(d_vec.begin(), d_vec.end());
    
      // transfer data back to host
      thrust::copy(d_vec.begin(), d_vec.end(), h_vec.begin());
    
      return 0;
    }

    This code sample computes the sum of 100 random numbers in parallel:

    #include <thrust/host_vector.h>
    #include <thrust/device_vector.h>
    #include <thrust/generate.h>
    #include <thrust/reduce.h>
    #include <thrust/functional.h>
    #include <algorithm>
    #include <cstdlib>
    
    int main(void)
    {
      // generate random data serially
      thrust::host_vector<int> h_vec(100);
      std::generate(h_vec.begin(), h_vec.end(), rand);
    
      // transfer to device and compute sum
      thrust::device_vector<int> d_vec = h_vec;
      int x = thrust::reduce(d_vec.begin(), d_vec.end(), 0, thrust::plus<int>());
      return 0;
    }

    Refer to the Quick Start Guide page for further information and examples.

    Contributors

    The original creators of Thrust are Jared Hoberock and Nathan Bell.