Index: NBody/NBodyGL.py
===================================================================
--- NBody/NBodyGL.py	(revision 161)
+++ NBody/NBodyGL.py	(revision 162)
@@ -158,7 +158,7 @@
     xf=x0+dt*(v1+(MYFLOAT)2.e0f*(v2+v3)+v4)/(MYFLOAT)6.e0f;
     vf=v0+dt*(a1+(MYFLOAT)2.e0f*(a2+a3)+a4)/(MYFLOAT)6.e0f;
      
-    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,1.e0f,vf.s0,vf.s1,vf.s2,1.e0f));
+    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,1.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
 }
 
 // Elements from : http://doswa.com/2009/01/02/fourth-order-runge-kutta-numerical-integration.html
@@ -236,26 +236,32 @@
 __kernel void SplutterPoints(__global MYFLOAT4* clDataX, MYFLOAT box, 
                              uint seed_z,uint seed_w)
 {
-    uint gid=(uint)get_global_id(0);
-    uint z=(seed_z+gid)%gid;
+    int gid=get_global_id(0);
+    uint z=seed_z+gid;
     uint w=seed_w+gid;
-    
-    // cast to float for sin,cos are NEEDED by Mesa FP64 implementation!
+     
+    for (int i=0;i<gid;i++)
+    {
+        private MYFLOAT heat=MWCfp;
+    }
+ 
+    // Distribute in sphere
     MYFLOAT radius=MWCfp*box;
     MYFLOAT theta=MWCfp*PI;
     MYFLOAT phi=MWCfp*PI*(MYFLOAT)2.e0f;
-    MYFLOAT sinTheta=sin((float)theta);
-    
+    // cast to float for sin,cos are NEEDED by Mesa FP64 implementation!
+    MYFLOAT sinTheta=sin((float)theta);    
     clDataX[gid].s0=radius*sinTheta*cos((float)phi)/2.e0f;
     clDataX[gid].s1=radius*sinTheta*sin((float)phi)/2.e0f;
     clDataX[gid].s2=radius*cos((float)theta)/2.e0f;
-    clDataX[gid].s3=(MYFLOAT)1.e0f;
+    clDataX[gid].s3=(MYFLOAT)0.e0f;
     barrier(CLK_GLOBAL_MEM_FENCE);
 
-    //MYFLOAT x0=box*(MYFLOAT)(MWCfp-0.5);
-    //MYFLOAT y0=box*(MYFLOAT)(MWCfp-0.5);
-    //MYFLOAT z0=box*(MYFLOAT)(MWCfp-0.5);
-    //clDataX[gid].s0123 = (MYFLOAT4) (x0,y0,z0,1.e0f);
+    // Distribute in box
+    // MYFLOAT x0=box*(MYFLOAT)(MWCfp-0.5);
+    // MYFLOAT y0=box*(MYFLOAT)(MWCfp-0.5);
+    // MYFLOAT z0=box*(MYFLOAT)(MWCfp-0.5);
+    // clDataX[gid].s0123 = (MYFLOAT4) (x0,y0,z0,0.e0f);
 }
 
 __kernel void SplutterStress(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,__global MYFLOAT4* clCoM, MYFLOAT velocity,uint seed_z,uint seed_w)
@@ -279,7 +285,7 @@
        clDataV[gid].s0=velocity*sinTheta*cos((float)phi);
        clDataV[gid].s1=velocity*sinTheta*sin((float)phi);
        clDataV[gid].s2=velocity*cos((float)theta);
-       clDataV[gid].s3=(MYFLOAT)1.e0f;
+       clDataV[gid].s3=(MYFLOAT)0.e0f;
     }
     barrier(CLK_GLOBAL_MEM_FENCE);
 }
@@ -373,12 +379,12 @@
 
 def display(*args):
 
-    global MyDataX,clDataX,clDataV,Step,Method,Number
+    global MyDataX,MyDataV,clDataX,clDataV,Step,Method,Number,Iterations
     
     glClearColor(0.0, 0.0, 0.0, 0.0)
     glClear(GL_COLOR_BUFFER_BIT)
-    glColor3f(1.0,1.0,0.0)
-
+    glColor3f(1.0,1.0,1.0)
+    
     time_start=time.time()
     if Method=="RungeKutta":            
         CLLaunch=MyRoutines.RungeKutta(queue,(Number,1),None,clDataX,clDataV,Step)
@@ -389,23 +395,62 @@
     else:
         CLLaunch=MyRoutines.ImplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
     CLLaunch.wait()
-    print("Duration of 1 iteration %s" % (time.time()-time_start))
+    print("Duration of #%s iteration: %s" % (Iterations,(time.time()-time_start)))
 
     cl.enqueue_copy(queue, MyDataX, clDataX)
-    print(MyDataX.reshape(Number,4))
+    # print(MyDataX.reshape(Number,4))
+    MyDataX.reshape(Number,4)[:,3]=1
     glVertexPointerf(MyDataX.reshape(Number,4))
+    # cl.enqueue_copy(queue, MyDataV, clDataV)
+    # print(MyDataV.reshape(Number,4))
+    # MyDataV.reshape(Number,4)[:,3]=1
+    # glVertexPointerf(MyDataV.reshape(Number,4))
     glEnableClientState(GL_VERTEX_ARRAY)
     glDrawArrays(GL_POINTS, 0, Number)
     glDisableClientState(GL_VERTEX_ARRAY)
     glFlush()
+    Iterations+=1
     glutSwapBuffers()
 
 def halt():
     pass
 
-def keyboard(*args):
-    return()
+def keyboard(k, x, y):
+    global view_rotz
+    LC_Z = as_8_bit( 'z' )
+    UC_Z = as_8_bit( 'Z' )
 
+    if k == LC_Z:
+        view_rotz += 1.0
+    elif k == UC_Z:
+        view_rotz -= 1.0
+    elif ord(k) == 27: # Escape
+        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION)
+        glutSetOption(GLUT_ACTION_GLUTMAINLOOP_RETURNS,GLUT_ACTION_CONTINUE_EXECUTION) 
+        glutLeaveMainLoop()
+        return(False)
+    else:
+        return
+    glRotatef(view_rotz, 0.0, 0.0, 1.0)
+    glutPostRedisplay()
+
+def special(k, x, y):
+    global view_rotx, view_roty, view_rotz
+
+    if k == GLUT_KEY_UP:
+        view_rotx += 1.0
+    elif k == GLUT_KEY_DOWN:
+        view_rotx -= 1.0
+    elif k == GLUT_KEY_LEFT:
+        view_roty += 1.0
+    elif k == GLUT_KEY_RIGHT:
+        view_roty -= 1.0
+    else:
+        return
+    glRotatef(view_rotx, 1.0, 0.0, 0.0)
+    glRotatef(view_roty, 0.0, 1.0, 0.0)
+    glutPostRedisplay()
+
 def mouse(button, state, x, y):
     global angle, delta_angle, halted
     if button == GLUT_LEFT_BUTTON:
@@ -425,25 +470,11 @@
     glMatrixMode(GL_PROJECTION)
     glLoadIdentity()
     glOrtho(-SizeOfBox, SizeOfBox, -SizeOfBox, SizeOfBox, -SizeOfBox, SizeOfBox)
-
+    
 def reshape(w, h):
     glViewport(0, 0, w, h)
     setup_viewport()
 
-def main():
-
-    glutInit(sys.argv)
-    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
-    glutInitWindowSize(400,400)
-    glutCreateWindow(b'NBodyGL')
-    setup_viewport()
-#   glutReshapeFunc(reshape)
-    glutDisplayFunc(display)
-    glutIdleFunc(display)
-#   glutMouseFunc(mouse)
-    glutKeyboardFunc(keyboard)
-    glutMainLoop()
-
 if __name__=='__main__':
 
     global Number,Step,clDataX,clDataV,MyDataX,MyDataV,Method,SizeOfBox
@@ -593,22 +624,22 @@
 
     print(Marsaglia[RNG],Computing[ValueType])
     # Build all routines used for the computing
-    #BuildOptions="-DTRNG=%i -DTYPE=%i" % (Marsaglia[RNG],Computing[ValueType])
-    #BuildOptions="-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%i" % (Marsaglia[RNG],Computing[ValueType])
     BuildOptions="-cl-mad-enable -cl-kernel-arg-info -cl-fast-relaxed-math -cl-std=CL1.2 -DTRNG=%i -DTYPE=%i" % (Marsaglia[RNG],Computing[ValueType])
     
-    if 'Intel' in PlatForm.name or 'Clover' in PlatForm.name or 'Portable' in PlatForm.name :
+    if 'Intel' in PlatForm.name or 'Experimental' in PlatForm.name or 'Clover' in PlatForm.name or 'Portable' in PlatForm.name :
         MyRoutines = cl.Program(ctx, BlobOpenCL).build(options = BuildOptions)
     else:
         MyRoutines = cl.Program(ctx, BlobOpenCL).build(options = BuildOptions+" -cl-strict-aliasing")
     
     mf = cl.mem_flags
+    # Read/Write approach for buffering
     # clDataX = cl.Buffer(ctx, mf.READ_WRITE, MyDataX.nbytes)
     # clDataV = cl.Buffer(ctx, mf.READ_WRITE, MyDataV.nbytes)
     # clPotential = cl.Buffer(ctx, mf.READ_WRITE, MyPotential.nbytes)
     # clKinetic = cl.Buffer(ctx, mf.READ_WRITE, MyKinetic.nbytes)
     # clCoM = cl.Buffer(ctx, mf.READ_WRITE, MyCoM.nbytes)
 
+    # Write/HostPoniter approach for buffering
     clDataX = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyDataX)
     clDataV = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyDataV)
     clPotential = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyPotential)
@@ -617,8 +648,6 @@
 
     print('All particles superimposed.')
 
-    print(SizeOfBox.dtype)
-    
     # Set particles to RNG points
     if InitialRandom:
         MyRoutines.SplutterPoints(queue,(Number,1),None,clDataX,SizeOfBox,np.uint32(nprnd(2**32)),np.uint32(nprnd(2**32)))
@@ -657,12 +686,28 @@
         # t1=np.array([[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]]])
         # tL=np.array([[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]]])
 
-    time_start=time.time()
+    wall_time_start=time.time()
+
     print("Use the mouse buttons to control some of the dots.")
     print("Hit any key to quit.")
-    main()
-    print("\nDuration on %s for each %s\n" % (Device,(time.time()-time_start)/Iterations))
+    global view_rotx,view_roty,view_rotz,Iterations
+    (view_rotx,view_roty,view_rotz)=(0.0, 0.0, 0.0)
+    Iterations=0
+    glutInit(sys.argv)
+    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
+    glutInitWindowSize(512,512)
+    glutCreateWindow(b'NBodyGL')
+    setup_viewport()
+    glutReshapeFunc(reshape)
+    glutDisplayFunc(display)
+    glutIdleFunc(display)
+#   glutMouseFunc(mouse)
+    glutSpecialFunc(special)
+    Loop=glutKeyboardFunc(keyboard)
+    glutMainLoop()
     
+    print("\nWall Duration on %s for each %s\n" % (Device,(time.time()-wall_time_start)/Iterations))
+    
     MyRoutines.CenterOfMass(queue,(1,1),None,clDataX,clCoM,np.int32(Number))
     CLLaunch=MyRoutines.Potential(queue,(Number,1),None,clDataX,clPotential)
     CLLaunch=MyRoutines.Kinetic(queue,(Number,1),None,clDataV,clKinetic)
