Skip to content

Instantly share code, notes, and snippets.

@bryancatanzaro
Created July 19, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bryancatanzaro/3146033 to your computer and use it in GitHub Desktop.
Save bryancatanzaro/3146033 to your computer and use it in GitHub Desktop.
Simple sequential thrust program
//Define the system to be OpenMP to remove all CUDA references
#define THRUST_DEVICE_SYSTEM THRUST_DEVICE_SYSTEM_OMP
#include <thrust/host_vector.h>
#include <thrust/fill.h>
#include <thrust/reduce.h>
#include <iostream>
template<typename T>
struct my_reduction {
typedef T result_type;
T operator()(const T& a, const T& b) const {
return a + b + 1;
}
};
int main() {
int length = 10;
thrust::host_vector<int> x(length);
thrust::fill(x.begin(), x.end(), 1);
int reduction_value = thrust::reduce(x.begin(), x.end(), 0, my_reduction<int>());
std::cout << "Thrust result: " << reduction_value << std::endl;
std::cout << "Result should be: " << 2 * length << std::endl;
}
@srossross
Copy link

Thank's I'll see what I can do with this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment