I am trying to compute in-place prefix sum on device_vector from Thrust library. The following snippet doesn't work:
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include <iostream>
#include <stdio.h>
#include <thrust/scan.h>
#include <thrust/device_vector.h>
int main()
{
thrust::device_vector<float> vector(4);
vector[0] = 1.0;
vector[1] = -3.0;
vector[2] = 4.0;
vector[3] = 5.0;
thrust::inclusive_scan(vector.begin(), vector.end(), vector.begin());
thrust::host_vector<float> h_vector(vector.begin(), vector.end());
for (size_t i = 0; i < 4; ++i) {
std::cout << h_vector[i] << std::endl;
}
return 0;
}
It throws some exception on a line with inclusive_scan call. What am I doing wrong?