5 Replies Latest reply on Aug 11, 2011 9:40 AM by maximmoroz

    Synchronization problem??



      I have a small problem with the accuracy of calculations. The kernel (code below) returns different results for the same input data. The difference is minimal.

      For example (the program's output):

      GRMS: 70.764435 (first run), 70.583441 (second run), 70.563168, ...

      The results are stored in dx[N], dy[N], dz[N] and R[N]. GRMS is average value of dx[N], dy[N], dz[N].

      X[N], Y[N] and Z[N] are coordinates and C[N] is for charge (input data) - atoms.

      Does anyone have an idea what could be wrong? Why such a small differenc in calculations?



      __kernel void vector_add(__global float *X, __global float *Y, __global float *Z, __global float *C, __global float *R , const int limit, __global float *dx , __global float *dy , __global float *dz) { int i = get_global_id(0); int n=0; float distance=0.0; float e, tx, ty, tz,stx,sty,stz; float cutoff = 10.0; float cutx, f, cg, tf, rr; R[i]=0; dx[i]=0; dy[i]=0; dz[i]=0; dx[i+1]=0; dy[i+1]=0; dz[i+1]=0; cutx = cutoff*cutoff; for(n=i+1; n<limit; n++){ stx=0.0,sty=0.0,stz=0.0; distance=sqrt((pow(X[n]-X[i],2)+pow(Y[n]-Y[i],2)+pow(Z[n]-Z[i],2))); if (distance <= cutoff ){ rr=distance*distance; f=1.0-rr/cutx; cg=(C[i]*C[n])/distance; e=cg*f*f; R[i]+=e; tf = -(e/rr)-(4.0*cg*f)/cutx; tx = tf*(X[n]-X[i]); ty = tf*(Y[n]-Y[i]); tz = tf*(Z[n]-Z[i]); dx[n] = dx[n] + tx; dy[n] = dy[n] + ty; dz[n] = dz[n] + tz; stx = stx + tx; sty = sty + ty; stz = stz + tz; } dx[i] = dx[i] - stx; dy[i] = dy[i] - sty; dz[i] = dz[i] - stz; } }