Initialising array on GPU

Hi all,

I’m trying to initialise an array with 2527 * 2463 double precision array elements on the GPU with a prescribed value.
The GPU is a GTX285.

The function for this is:

int nelements = 2463 * 2527;
int nthreads = 256;
int nblocks = (nelements - nthreads - 1)/nthreads;

double* d_array;
cudaMalloc((void**)&d_array, nelements*sizeof(double));

initialise_array_gpu<<<nblocks, nthreads>>>(d_array, nelements, 1.0)

global void initialise_array_gpu(double* d_array, int nelements, double value)
{
int id = threadIdx.x + blockDim.x * blockIdx.x;
if(id < nelements)
{
d_array[id] = value;
}
}

This code always fails starting from element number 6223872 out of 6224001.

How can this be made to work?

It seems, I’m hitting some limits but don’t know why.

Any suggestions welcome!

Thanks a lot!

Try [font=“Courier New”]int nblocks = (nelements + nthreads - 1)/nthreads;[/font]

Try this:

int nblocks = (nelements + nthreads - 1)/nthreads;

//-----------------------^