It seems to be a strange but very basic problem. I tried doing a simple operation in pyopencl. Given below is the code where if I multiply my positions with exp(-f_sum/sigma2)/sigma2 I get 0 (even though I have non zero values for both positions as well as sigma) but when I add the value I get the correct result.
kernelsource = """ __kernel void forceFinder(
const int N,
const int dim,
const float sigma,
const float resistant,
__global float* datacl,
__constant float* poscl,
__global float* res
)
{
int i = get_global_id(0);
float f_sum ;
int k;
float sigma2 = sigma * sigma;
float tempo;
if (i < N ) {
f_sum = 0;
for (k = 0; k < dim; k++)
{
f_sum += pown((poscl[k] - datacl[i * dim + k]), 2);
}
for (k = 0; k < dim; k++)
{
res[i * dim + k] = (datacl[i * dim + k] - poscl[k]) * exp(-f_sum/sigma2)/sigma2;
}
}
}
"""
Instead of "*" in last loop if I replace it with "+" I get the output