Unknown error message Newbie question

Hi,

 I am trying to compile and run a small program which will reverse an array. The kernel is supposed to transfer the array onto the shared memory and again onto the global memory in reversed order.

My code gets compiled. But when I run it… program executes and I get the reversed array printed out, but I also get the following error message.

“This application has requested the Runtime to terminate it in an unusual way. Please contact the application’s support team for more information” and also a pop-up message box saying “An exception unknown software exception has occured in the application at location 0x004…”

Can any one help me… Why does this happen and how do I fix it? My kernel code is given below…[codebox]

global void reverse_array_shared(int* dev_arr1, int* dev_arr2, int array_size)

{

extern shared int sh_array;

int in_index = blockDim.x*blockIdx.x + threadIdx.x;

int out_index = array_size - 1 - in_index;

if(in_index < array_size)

{

/** Transferring data from Global memory into shared memory**/

sh_array[threadIdx.x] = dev_arr1[in_index];

/** Transfer it back into global memory but in a different order **/

dev_arr2[out_index] = sh_array[threadIdx.x];

}

[/codebox]

Appreciate any help… Thanks.

best,

Avinash

Hi,

 Its me again. About the error that I posted above.. By just trying changing every aspect of the program I managed to figure out what was causing the problem. But I am still stumped as for why it is causing the problem.[codebox]__global__ void reverse_array_shared (int* dev_arr2, int* dev_arr1)

{

 extern __shared__ int sh_array[];

 int in_index = blockDim.x*blockIdx.x +threadIdx.x;

 int out_index = gridDim.x*blockDim.x -1 - in_index;

sh_array[threadIdx.x] = dev_arr1[in_index];

dev_arr2[out_index] = sh_array[threadIdx.x];

}[/codebox]

When I change the code to this, it works without any problems. I have taken out the conditional statement that was there in the earlier code. I put in this statement “if(in_index < array_size)” to deal with a case in which the array size may not be a multiple of my block size. So the if statement was to make sure that extra threads in a block do not do anything.

I am not able to understand why this would cause a problem. I did read that using conditionals inside a kernel might slow down the execution if the threads diverged. But is there some other problem with using conditionals inside kernels that I am missing.??

I would greatly appreciate it if some one could explain this to me…

best,

Avinash