Using Thrust to operate with vectors


I’m using Thrust library to do some operations with vectors.Here is a simple example of the code and the error:

int maxthrust(float*a,int dim){

	thrust::device_vector<float> mat(dim);	


	int max = thrust::reduce(mat.begin(), mat.end(), -1,thrust::maximum<int>());

	return max;


int main(){

	float* a_h=(float*)malloc(10*sizeof(float));

  	thrust::sequence(a_h, a_h + 10, 0);



When I execute there is the following error:

terminate called after throwing an instance of ‘std::bad_alloc’

what(): St9bad_alloc


I think it is strange this error because I thought it only happens when there is a very large vector.

Thanks in advance