Index: NBody.py
===================================================================
--- NBody.py	(revision 169)
+++ NBody.py	(revision 170)
@@ -12,24 +12,85 @@
 import pyopencl as cl
 import pyopencl.array as cl_array
 from numpy.random import randint as nprnd
+import string, sys
+from OpenGL.GL import *
+from OpenGL.GLUT import *
 
 def DictionariesAPI():
     Marsaglia={'CONG':0,'SHR3':1,'MWC':2,'KISS':3}
     Computing={'FP32':0,'FP64':1}
-    return(Marsaglia,Computing)
+    Interaction={'Force':0,'Potential':1}
+    return(Marsaglia,Computing,Interaction)
 
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
 BlobOpenCL= """
-#define znew  ((z=36969*(z&65535)+(z>>16))<<16)
-#define wnew  ((w=18000*(w&65535)+(w>>16))&65535)
-#define MWC   (znew+wnew)
-#define SHR3  (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5))
-#define CONG  (jcong=69069*jcong+1234567)
-#define KISS  ((MWC^CONG)+SHR3)
-
 #define TFP32 0
 #define TFP64 1
 
-#define LENGTH 1.e0f
+#define TFORCE 0
+#define TPOTENTIAL 1
 
 #if TYPE == TFP32
 #define MYFLOAT4 float4
@@ -37,19 +98,24 @@
 #define MYFLOAT float
 #define DISTANCE fast_distance
 #else
-#if defined(cl_khr_fp64)  // Khronos extension available?
-#pragma OPENCL EXTENSION cl_khr_fp64 : enable
-#define DOUBLE_SUPPORT_AVAILABLE
-#elif defined(cl_amd_fp64)  // AMD extension available?
-#pragma OPENCL EXTENSION cl_amd_fp64 : enable
-#define DOUBLE_SUPPORT_AVAILABLE
-#endif
 #define MYFLOAT4 double4
 #define MYFLOAT8 double8
 #define MYFLOAT double
 #define DISTANCE distance
+#if defined(cl_khr_fp64)  // Khronos extension available?
+#pragma OPENCL EXTENSION cl_khr_fp64 : enable
 #endif
+#endif
 
+
+#define znew  ((zmwc=36969*(zmwc&65535)+(zmwc>>16))<<16)
+#define wnew  ((wmwc=18000*(wmwc&65535)+(wmwc>>16))&65535)
+#define MWC   (znew+wnew)
+#define SHR3  (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5))
+#define CONG  (jcong=69069*jcong+1234567)
+#define KISS  ((MWC^CONG)+SHR3)
+
+
 #define MWCfp (MYFLOAT)(MWC * 2.3283064365386963e-10f)
 #define KISSfp (MYFLOAT)(KISS * 2.3283064365386963e-10f)
 #define SHR3fp (MYFLOAT)(SHR3 * 2.3283064365386963e-10f)
@@ -57,29 +123,71 @@
 
 #define PI (MYFLOAT)3.141592653589793238462643197169399375105820974944592307816406286e0f
 
-#define SMALL_NUM 1.e-9f
+#define SMALL_NUM (MYFLOAT)1.e-9f
 
-MYFLOAT4 Interaction(MYFLOAT4 m,MYFLOAT4 n)
-{
-    private MYFLOAT r=DISTANCE(n,m);
+#define LENGTH 1.e0f
 
-    return((n-m)/(MYFLOAT)(r*r*r));
-}
+// Create my own Distance implementation: distance buggy on Oland AMD chipset
 
-MYFLOAT4 InteractionCore(MYFLOAT4 m,MYFLOAT4 n)
+MYFLOAT MyDistance(MYFLOAT4 n,MYFLOAT4 m)
 {
-    private MYFLOAT core=(MYFLOAT)1.e5f;
-    private MYFLOAT r=DISTANCE(n,m);
-    private MYFLOAT d=r*r+core*core;
-
-    return(core*(n-m)/(MYFLOAT)(d*d));
+    private MYFLOAT x2,y2,z2;
+    x2=n.s0-m.s0;
+    x2*=x2;
+    y2=n.s1-m.s1;
+    y2*=y2;
+    z2=n.s2-m.s2;
+    z2*=z2;
+    return(sqrt(x2+y2+z2));
 }
 
+// Interaction to avoid artevasion of bodies : 1-e^-x*x is x*x near 0
+
+//MYFLOAT4 InteractionCore(MYFLOAT4 m,MYFLOAT4 n)
+//{
+//    private MYFLOAT r=MyDistance((MYFLOAT4)n,(MYFLOAT4)m);
+//    private MYFLOAT r2=r*r;
+//    private MYFLOAT c=1.e0f/(MYFLOAT)get_global_size(0);
+
+//    private MYFLOAT4 unity=normalize(n,m);
+
+//    return(((MYFLOAT4)n-(MYFLOAT4)m)*(MYFLOAT)(1.e0f-exp(-c*r2))/(MYFLOAT)(r*r2));
+//}
+
 MYFLOAT PairPotential(MYFLOAT4 m,MYFLOAT4 n)
 {
+
+//    return((MYFLOAT)(-1.e0f)/(MyDistance(m,n)));
+
+//    MYFLOAT r=DISTANCE(n,m);
+//    return((-1.e0f+exp(-r))/r);
+
+
     return((MYFLOAT)(-1.e0f)/(DISTANCE(n,m)));
 }
 
+MYFLOAT4 Interaction(MYFLOAT4 m,MYFLOAT4 n)
+#if INTERACTION == TFORCE
+// Simplest implementation of force (equals to acceleration)
+// seems to bo bad (numerous artevasions)
+// MYFLOAT4 InteractionForce(MYFLOAT4 m,MYFLOAT4 n)
+{
+    private MYFLOAT r=MyDistance(n,m);
+    return((n-m)/(MYFLOAT)(r*r*r));
+}
+#else
+// Force definited as gradient of potential
+// Estimate potential and proximate potential to estimate force
+// MYFLOAT4 InteractionPotential(MYFLOAT4 m,MYFLOAT4 n)
+{
+    private MYFLOAT epsilon=(MYFLOAT)(1.e0f/1048576);
+    private MYFLOAT4 er=normalize(n-m);
+    private MYFLOAT4 dr=er*(MYFLOAT)epsilon;
+
+    return(er*(PairPotential(m,n)-PairPotential(m+dr,n))/epsilon);
+}
+#endif
+
 MYFLOAT AtomicPotential(__global MYFLOAT4* clDataX,int gid)
 {
     private MYFLOAT potential=(MYFLOAT)0.e0f;
@@ -100,212 +208,265 @@
     return(PairPotential(clDataX[gid],clCoM[0]));
 }
 
+// Elements from : http://doswa.com/2009/01/02/fourth-order-runge-kutta-numerical-integration.html
+
 MYFLOAT8 AtomicRungeKutta(__global MYFLOAT4* clDataInX,__global MYFLOAT4* clDataInV,int gid,MYFLOAT dt)
 {
     private MYFLOAT4 a0,v0,x0,a1,v1,x1,a2,v2,x2,a3,v3,x3,a4,v4,x4,xf,vf;
+    MYFLOAT4 DT=dt*(MYFLOAT4)(1.e0f,1.e0f,1.e0f,1.e0f);
 
     a0=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
     v0=(MYFLOAT4)clDataInV[gid];
     x0=(MYFLOAT4)clDataInX[gid];
     int N = get_global_size(0);    
     
-    for (int i=0;i<N;i++)
+    for (private int i=0;i<N;i++)
     {
         if (gid != i)
         a0+=Interaction(x0,clDataInX[i]);
     }
         
     a1=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
-    v1=v0+a0*dt;
-    x1=x0+v0*dt;
-    for (int i=0;i<N;i++)
+    v1=a0*dt+v0;
+    x1=v0*dt+x0;
+    for (private int j=0;j<N;j++)
     {
-        if (gid != i)
-        a1+=Interaction(x1,clDataInX[i]);
+        if (gid != j)
+        a1+=Interaction(x1,clDataInX[j]);
     }
 
     a2=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
-    v2=v0+a1*dt*(MYFLOAT)5.e-1f;
-    x2=x0+v1*dt*(MYFLOAT)5.e-1f;
-    for (int i=0;i<N;i++)
+    v2=a1*(MYFLOAT)(dt/2.e0f)+v0;
+    x2=v1*(MYFLOAT)(dt/2.e0f)+x0;
+    for (private int k=0;k<N;k++)
     {
-        if (gid != i)
-        a2+=Interaction(x2,clDataInX[i]);
+        if (gid != k)
+        a2+=Interaction(x2,clDataInX[k]);
     }
     
     a3=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
-    v3=v0+a2*dt*(MYFLOAT)5.e-1f;
-    x3=x0+v2*dt*(MYFLOAT)5.e-1f;
-    for (int i=0;i<N;i++)
+    v3=a2*(MYFLOAT)(dt/2.e0f)+v0;
+    x3=v2*(MYFLOAT)(dt/2.e0f)+x0;
+    for (private int l=0;l<N;l++)
     {
-        if (gid != i)
-        a3+=Interaction(x3,clDataInX[i]);
+        if (gid != l)
+        a3+=Interaction(x3,clDataInX[l]);
     }
     
     a4=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
-    v4=v0+a3*dt;
-    x4=x0+v3*dt;
-    for (int i=0;i<N;i++)
+    v4=a3*dt+v0;
+    x4=v3*dt+x0;
+    for (private int m=0;m<N;m++)
     {
-        if (gid != i)
-        a4+=Interaction(x4,clDataInX[i]);
+        if (gid != m)
+        a4+=Interaction(x4,clDataInX[m]);
     }
     
     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,0.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
 }
 
-// Elements from : http://doswa.com/2009/01/02/fourth-order-runge-kutta-numerical-integration.html
-
 MYFLOAT8 AtomicHeun(__global MYFLOAT4* clDataInX,__global MYFLOAT4* clDataInV,int gid,MYFLOAT dt)
 {
-    private MYFLOAT4 x,v,a,xi,vi,ai,xf,vf;
+    private MYFLOAT4 x0,v0,a0,x1,v1,a1,xf,vf;
+    MYFLOAT4 Dt=dt*(MYFLOAT4)(1.e0f,1.e0f,1.e0f,1.e0f);
 
-    x=(MYFLOAT4)clDataInX[gid];
-    v=(MYFLOAT4)clDataInV[gid];
-    a=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
+    x0=(MYFLOAT4)clDataInX[gid];
+    v0=(MYFLOAT4)clDataInV[gid];
+    a0=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
 
-    for (int i=0;i<get_global_size(0);i++)
+    for (private int i=0;i<get_global_size(0);i++)
     {
         if (gid != i)
-        a+=Interaction(x,clDataInX[i]);
+        a0+=Interaction(x0,clDataInX[i]);
     }
 
-    vi=v+dt*a;
-    xi=x+dt*vi;
-    ai=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
+    a1=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
+    //v1=v0+dt*a0;
+    //x1=x0+dt*v0;
+    v1=dt*a0+v0;
+    x1=dt*v0+x0;
 
-    for (int i=0;i<get_global_size(0);i++)
+    for (private int j=0;j<get_global_size(0);j++)
     {
-        if (gid != i)
-        ai+=Interaction(xi,clDataInX[i]);
+        if (gid != j)
+        a1+=Interaction(x1,clDataInX[j]);
     }
-       
-    vf=v+dt*(a+ai)/(MYFLOAT)2.e0f;
-    xf=x+dt*(v+vi)/(MYFLOAT)2.e0f;
 
-    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,1.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
+    vf=v0+dt*(a0+a1)/(MYFLOAT)2.e0f;
+    xf=x0+dt*(v0+v1)/(MYFLOAT)2.e0f;
+
+    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,0.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
 }
 
 MYFLOAT8 AtomicImplicitEuler(__global MYFLOAT4* clDataInX,__global MYFLOAT4* clDataInV,int gid,MYFLOAT dt)
 {
-    private MYFLOAT4 x,v,a,xf,vf;
+    MYFLOAT4 x0,v0,a,xf,vf;
 
-    x=(MYFLOAT4)clDataInX[gid];
-    v=(MYFLOAT4)clDataInV[gid];
+    x0=(MYFLOAT4)clDataInX[gid];
+    v0=(MYFLOAT4)clDataInV[gid];
     a=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
 
-    for (int i=0;i<get_global_size(0);i++)
+    for (private int i=0;i<get_global_size(0);i++)
     {
         if (gid != i)
-        a+=Interaction(x,clDataInX[i]);
+          a+=Interaction(x0,clDataInX[i]);
     }
        
-    vf=v+dt*a;
-    xf=x+dt*vf;
- 
-    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,1.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
+    vf=v0+dt*a;
+    xf=x0+dt*vf;
+
+    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,0.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
 }
 
 MYFLOAT8 AtomicExplicitEuler(__global MYFLOAT4* clDataInX,__global MYFLOAT4* clDataInV,int gid,MYFLOAT dt)
 {
-    MYFLOAT4 x,v,a,xf,vf;
+    MYFLOAT4 x0,v0,a,xf,vf;
 
-    x=(MYFLOAT4)clDataInX[gid];
-    v=(MYFLOAT4)clDataInV[gid];
+    x0=(MYFLOAT4)clDataInX[gid];
+    v0=(MYFLOAT4)clDataInV[gid];
     a=(MYFLOAT4)(0.e0f,0.e0f,0.e0f,0.e0f);
 
-    for (int i=0;i<get_global_size(0);i++)
+    for (private int i=0;i<get_global_size(0);i++)
     {
         if (gid != i)
-        a+=Interaction(x,clDataInX[i]);
+        a+=Interaction(x0,clDataInX[i]);
     }
        
-    vf=v+dt*a;
-    xf=x+dt*v;
+    vf=v0+dt*a;
+    xf=x0+dt*v0;
  
-    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,1.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
+    return((MYFLOAT8)(xf.s0,xf.s1,xf.s2,0.e0f,vf.s0,vf.s1,vf.s2,0.e0f));
 }
 
-__kernel void SplutterPoints(__global MYFLOAT4* clDataX, MYFLOAT box, 
+__kernel void InBallSplutterPoints(__global MYFLOAT4* clDataX, 
+                                   MYFLOAT diameter,uint seed_z,uint seed_w)
+{
+    private int gid=get_global_id(0);
+    private uint zmwc=seed_z+gid;
+    private uint wmwc=seed_w+(gid+1)%2;
+    private MYFLOAT Heat;
+ 
+    for (int i=0;i<gid;i++)
+    {
+        Heat=MWCfp;
+    }
+
+// More accurate distribution based on spherical coordonates
+// Disactivated because of AMD Oland GPU crash on launch
+//     private MYFLOAT Radius,Theta,Phi,PosX,PosY,PosZ,SinTheta;
+//     Radius=MWCfp*diameter/2.e0f;
+//     Theta=(MYFLOAT)acos((float)(-2.e0f*MWCfp+1.0e0f));
+//     Phi=(MYFLOAT)(2.e0f*PI*MWCfp);
+//     SinTheta=sin((float)Theta);
+//     PosX=cos((float)Phi)*Radius*SinTheta;
+//     PosY=sin((float)Phi)*Radius*SinTheta;
+//     PosZ=cos((float)Theta)*Radius;
+//     clDataX[gid]=(MYFLOAT4)(PosX,PosY,PosZ,0.e0f);
+
+    private MYFLOAT Radius=diameter/2.e0f;
+    private MYFLOAT Length=diameter;
+    private MYFLOAT4 Position;
+    while (Length>Radius) {
+       Position=(MYFLOAT4)((MWCfp-0.5e0f)*diameter,(MWCfp-0.5e0f)*diameter,(MWCfp-0.5e0f)*diameter,0.e0f);
+       Length=(MYFLOAT)length((MYFLOAT4)Position);
+    }
+
+    clDataX[gid]=Position;    
+
+    barrier(CLK_GLOBAL_MEM_FENCE);
+}
+
+__kernel void InBoxSplutterPoints(__global MYFLOAT4* clDataX, MYFLOAT box, 
                              uint seed_z,uint seed_w)
 {
-    int gid = get_global_id(0);
-    uint z=seed_z+(uint)gid;
-    uint w=seed_w-(uint)gid;
-    
-    MYFLOAT x0=box*(MYFLOAT)(MWCfp-(MYFLOAT)5.e-1f);
-    MYFLOAT y0=box*(MYFLOAT)(MWCfp-(MYFLOAT)5.e-1f);
-    MYFLOAT z0=box*(MYFLOAT)(MWCfp-(MYFLOAT)5.e-1f);
+    int gid=get_global_id(0);
+    uint zmwc=seed_z+gid;
+    uint wmwc=seed_w-gid;
+    private MYFLOAT Heat;
+ 
+    for (int i=0;i<gid;i++)
+    {
+        Heat=MWCfp;
+    }
 
-    clDataX[gid].s0123 = (MYFLOAT4) (x0,y0,z0,1.e0f);
+    clDataX[gid]=(MYFLOAT4)((MWCfp-0.5e0f)*box,(MWCfp-0.5e0f)*box,(MWCfp-0.5e0f)*box,0.e0f);
+
+    barrier(CLK_GLOBAL_MEM_FENCE);
 }
 
 __kernel void SplutterStress(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,__global MYFLOAT4* clCoM, MYFLOAT velocity,uint seed_z,uint seed_w)
 {
     int gid = get_global_id(0);
     MYFLOAT N = (MYFLOAT)get_global_size(0);
-    uint z=seed_z+(uint)gid;
-    uint w=seed_w-(uint)gid;
+    uint zmwc=seed_z+(uint)gid;
+    uint wmwc=seed_w-(uint)gid;
+    MYFLOAT4 SpeedVector;
 
     if (velocity<SMALL_NUM) {
-       MYFLOAT4 SpeedVector=(MYFLOAT4)normalize(cross(clDataX[gid],clCoM[0]))*sqrt(-AtomicPotential(clDataX,gid)/(MYFLOAT)2.e0f);
-       clDataV[gid]=SpeedVector;
+       SpeedVector=(MYFLOAT4)normalize(cross(clDataX[gid],clCoM[0]))*sqrt((-AtomicPotential(clDataX,gid)/(MYFLOAT)2.e0f));
     }
     else
     {    
        // cast to float for sin,cos are NEEDED by Mesa FP64 implementation!
-       MYFLOAT theta=MWCfp*PI;
+       // Implemention on AMD Oland are probably broken in float
+
+       MYFLOAT theta=acos((float)(1.0e0f-2.e0f*MWCfp));
        MYFLOAT phi=MWCfp*PI*(MYFLOAT)2.e0f;
        MYFLOAT sinTheta=sin((float)theta);
+       MYFLOAT sinPhi=sin((float)phi);
 
-       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;
+       SpeedVector=(MYFLOAT4)((MWCfp-0.5e0f)*velocity,(MWCfp-0.5e0f)*velocity,
+                              (MWCfp-0.5e0f)*velocity,0.e0f);
     }
+    clDataV[gid]=SpeedVector;
+    barrier(CLK_GLOBAL_MEM_FENCE);
 }
 
 __kernel void RungeKutta(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
 {
-    int gid = get_global_id(0);
+    private int gid = get_global_id(0);
+    private MYFLOAT8 clDataGid;
     
-    MYFLOAT8 clDataGid=AtomicRungeKutta(clDataX,clDataV,gid,h);
+    clDataGid=AtomicRungeKutta(clDataX,clDataV,gid,h);
     barrier(CLK_GLOBAL_MEM_FENCE);
-    clDataX[gid]=clDataGid.lo;
-    clDataV[gid]=clDataGid.hi;
+    clDataX[gid]=clDataGid.s0123;
+    clDataV[gid]=clDataGid.s4567;
 }
 
-__kernel void ImplicitEuler(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
+__kernel void Heun(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
 {
-    int gid = get_global_id(0);
+    private int gid = get_global_id(0);
+    private MYFLOAT8 clDataGid;
     
-    MYFLOAT8 clDataGid=AtomicImplicitEuler(clDataX,clDataV,gid,h);
+    clDataGid=AtomicHeun(clDataX,clDataV,gid,h);
     barrier(CLK_GLOBAL_MEM_FENCE);
-    clDataX[gid]=clDataGid.lo;
-    clDataV[gid]=clDataGid.hi;
+    clDataX[gid]=clDataGid.s0123;
+    clDataV[gid]=clDataGid.s4567;
 }
 
-__kernel void Heun(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
+__kernel void ImplicitEuler(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
 {
-    int gid = get_global_id(0);
+    private int gid = get_global_id(0);
+    private MYFLOAT8 clDataGid;
     
-    MYFLOAT8 clDataGid=AtomicHeun(clDataX,clDataV,gid,h);
+    clDataGid=AtomicImplicitEuler(clDataX,clDataV,gid,h);
     barrier(CLK_GLOBAL_MEM_FENCE);
-    clDataX[gid]=clDataGid.lo;
-    clDataV[gid]=clDataGid.hi;
+    clDataX[gid]=clDataGid.s0123;
+    clDataV[gid]=clDataGid.s4567;
 }
 
 __kernel void ExplicitEuler(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
 {
-    int gid = get_global_id(0);
-    
-    MYFLOAT8 clDataGid=AtomicExplicitEuler(clDataX,clDataV,gid,h);
+    private int gid = get_global_id(0);
+    private MYFLOAT8 clDataGid;    
+
+    clDataGid=AtomicExplicitEuler(clDataX,clDataV,gid,h);
     barrier(CLK_GLOBAL_MEM_FENCE);
-    clDataX[gid]=clDataGid.lo;
-    clDataV[gid]=clDataGid.hi;
+    clDataX[gid]=clDataGid.s0123;
+    clDataV[gid]=clDataGid.s4567;
 }
 
 __kernel void CoMPotential(__global MYFLOAT4* clDataX,__global MYFLOAT4* clCoM,__global MYFLOAT* clPotential)
@@ -342,7 +503,7 @@
     }
 
     barrier(CLK_GLOBAL_MEM_FENCE);
-    clCoM[0]=(MYFLOAT4)(CoM.s0,CoM.s1,CoM.s2,1.e0f)/(MYFLOAT)Size;
+    clCoM[0]=(MYFLOAT4)(CoM.s0,CoM.s1,CoM.s2,0.e0f)/(MYFLOAT)Size;
 }
 
 __kernel void Kinetic(__global MYFLOAT4* clDataV,__global MYFLOAT* clKinetic)
@@ -353,49 +514,161 @@
     MYFLOAT d=(MYFLOAT)length(clDataV[gid]);
     clKinetic[gid]=(MYFLOAT)5.e-1f*(MYFLOAT)(d*d);
 }
+
 """
 
-def Energy(MyData):
-    return(sum(MyData*MyData))
+def MainOpenCL(clDataX,clDataV,Step,Method):
+    time_start=time.time()
+    if Method=="RungeKutta":
+        CLLaunch=MyRoutines.RungeKutta(queue,(Number,1),None,clDataX,clDataV,Step)
+    elif Method=="ExplicitEuler":
+        CLLaunch=MyRoutines.ExplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
+    elif Method=="Heun":
+        CLLaunch=MyRoutines.Heun(queue,(Number,1),None,clDataX,clDataV,Step)
+    else:
+        CLLaunch=MyRoutines.ImplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
+    CLLaunch.wait()
+    Elapsed=time.time()-time_start
+    return(Elapsed)
+    
+def display(*args):
 
+    global MyDataX,MyDataV,clDataX,clDataV,Step,Method,Number,Iterations,Durations,Verbose,SpeedRendering
+    
+    glClearColor(0.0, 0.0, 0.0, 0.0)
+    glClear(GL_COLOR_BUFFER_BIT)
+    glColor3f(1.0,1.0,1.0)
+    
+    Elapsed=MainOpenCL(clDataX,clDataV,Step,Method)
+    if SpeedRendering:
+        cl.enqueue_copy(queue, MyDataV, clDataV)
+        MyDataV.reshape(Number,4)[:,3]=1
+        glVertexPointerf(MyDataV.reshape(Number,4))
+    else:
+        cl.enqueue_copy(queue, MyDataX, clDataX)
+        MyDataX.reshape(Number,4)[:,3]=1
+        glVertexPointerf(MyDataX.reshape(Number,4))
+
+    if Verbose:
+        print("Positions for #%s iteration: %s" % (Iterations,MyDataX))
+    else:
+        sys.stdout.write('.')
+        sys.stdout.flush()
+    Durations=np.append(Durations,MainOpenCL(clDataX,clDataV,Step,Method))    
+    glEnableClientState(GL_VERTEX_ARRAY)
+    glDrawArrays(GL_POINTS, 0, Number)
+    glDisableClientState(GL_VERTEX_ARRAY)
+    glFlush()
+    Iterations+=1
+    glutSwapBuffers()
+
+def halt():
+    pass
+
+def keyboard(k,x,y):
+    global ViewRZ,SizeOfBox,SpeedRendering
+    LC_Z = as_8_bit( 'z' )
+    UC_Z = as_8_bit( 'Z' )
+    Plus = as_8_bit( '+' )
+    Minus = as_8_bit( '-' )
+    Switch = as_8_bit( 's' )
+
+    Zoom=1
+    if k == LC_Z:
+        ViewRZ += 1.0
+    elif k == UC_Z:
+        ViewRZ -= 1.0
+    elif k == Plus:
+        Zoom *= 2.0
+    elif k == Minus:
+        Zoom /= 2.0
+    elif k == Switch:
+        if SpeedRendering:
+            SpeedRendering=False
+        else:
+            SpeedRendering=True
+    elif ord(k) == 27: # Escape
+        glutLeaveMainLoop()
+        return(False)
+    else:
+        return
+    glRotatef(ViewRZ, 0.0, 0.0, 1.0)
+    glScalef(Zoom,Zoom,Zoom)
+    glutPostRedisplay()
+
+def special(k,x,y):
+    global ViewRX, ViewRY, ViewRZ
+
+    if k == GLUT_KEY_UP:
+        ViewRX += 1.0
+    elif k == GLUT_KEY_DOWN:
+        ViewRX -= 1.0
+    elif k == GLUT_KEY_LEFT:
+        ViewRY += 1.0
+    elif k == GLUT_KEY_RIGHT:
+        ViewRY -= 1.0
+    else:
+        return
+    glRotatef(ViewRX, 1.0, 0.0, 0.0)
+    glRotatef(ViewRY, 0.0, 1.0, 0.0)
+    glutPostRedisplay()
+
+def setup_viewport():
+    global SizeOfBox
+    glMatrixMode(GL_PROJECTION)
+    glLoadIdentity()
+    glOrtho(-SizeOfBox, SizeOfBox, -SizeOfBox, SizeOfBox, -SizeOfBox, SizeOfBox)
+    glutPostRedisplay()
+    
+def reshape(w, h):
+    glViewport(0, 0, w, h)
+    setup_viewport()
+
 if __name__=='__main__':
+
+    global Number,Step,clDataX,clDataV,MyDataX,MyDataV,Method,SizeOfBox,Iterations,Verbose,Durations
     
     # ValueType
     ValueType='FP32'
     class MyFloat(np.float32):pass
     #    clType8=cl_array.vec.float8
-    clType4=cl_array.vec.float4
     # Set defaults values
     np.set_printoptions(precision=2)  
     # Id of Device : 1 is for first find !
     Device=0
-    # Iterations is integer
+    # Number of bodies is integer
     Number=2
-    # Size of box
-    SizeOfBox=MyFloat(1.)
+    # Number of iterations (for standalone execution)
+    Iterations=10
+    # Size of shape
+    SizeOfShape=MyFloat(1.)
     # Initial velocity of particules
     Velocity=MyFloat(1.)
-    # Redo the last process
-    Iterations=int(np.pi*1024)
     # Step
-    Step=MyFloat(1./1024)
+    Step=MyFloat(1./32)
     # Method of integration
     Method='ImplicitEuler'
     # InitialRandom
     InitialRandom=False
     # RNG Marsaglia Method
     RNG='MWC'
-    # CheckEnergies
-    CheckEnergies=False
-    # Display samples in 3D
-    GraphSamples=False
     # Viriel Distribution of stress
     VirielStress=True
+    # Verbose
+    Verbose=False
+    # OpenGL real time rendering
+    OpenGL=False
+    # Speed rendering
+    SpeedRendering=False
+    # Shape to distribute
+    Shape='Ball'
+    # Type of Interaction
+    InterType='Potential'
     
-    HowToUse='%s -h [Help] -r [InitialRandom] -e [VirielStress] -g [GraphSamples] -c [CheckEnergies] -d <DeviceId> -n <NumberOfParticules> -z <SizeOfBox> -v <Velocity> -s <Step> -i <Iterations> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
+    HowToUse='%s -h [Help] -r [InitialRandom] -g [OpenGL] -e [VirielStress] -o [Verbose] -p [SpeedRendering] -f [Force] -d <DeviceId> -n <NumberOfParticules> -i <Iterations> -z <SizeOfBoxOrBall> -v <Velocity> -s <Step> -b <Ball|Box> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
 
     try:
-        opts, args = getopt.getopt(sys.argv[1:],"rehgcd:n:z:v:i:s:m:t:",["random","viriel","graph","check","device=","number=","size=","velocity=","iterations=","step=","method=","valuetype="])
+        opts, args = getopt.getopt(sys.argv[1:],"rpfgehod:n:i:z:v:s:m:t:b:",["random","rendering","force","opengl","viriel","verbose","device=","number=","iterations=","size=","velocity=","step=","method=","valuetype=","shape="])
     except getopt.GetoptError:
         print(HowToUse % sys.argv[0])
         sys.exit(2)
@@ -409,6 +682,7 @@
                 Id=0
                 for platform in cl.get_platforms():
                     for device in platform.get_devices():
+                        # Failed now because of POCL implementation
                         #deviceType=cl.device_type.to_string(device.type)
                         deviceType="xPU"
                         print("Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip()))
@@ -421,60 +695,67 @@
         elif opt in ("-t", "--valuetype"):
             if arg=='FP64':
                 class MyFloat(np.float64): pass
-                clType4=cl_array.vec.double4
             else:
                 class MyFloat(np.float32):pass
-                clType4=cl_array.vec.float4
             ValueType = arg
         elif opt in ("-d", "--device"):
             Device=int(arg)
         elif opt in ("-m", "--method"):
             Method=arg
+        elif opt in ("-b", "--shape"):
+            Shape=arg
         elif opt in ("-n", "--number"):
             Number=int(arg)
+        elif opt in ("-i", "--iterations"):
+            Iterations=int(arg)
         elif opt in ("-z", "--size"):
-            SizeOfBox=MyFloat(arg)
+            SizeOfShape=MyFloat(arg)
         elif opt in ("-v", "--velocity"):
             Velocity=MyFloat(arg)
             VirielStress=False
         elif opt in ("-s", "--step"):
             Step=MyFloat(arg)
-        elif opt in ("-i", "--iterations"):
-            Iterations=int(arg)
         elif opt in ("-r", "--random"):
             InitialRandom=True
         elif opt in ("-c", "--check"):
             CheckEnergies=True
-        elif opt in ("-g", "--graph"):
-            GraphSamples=True
         elif opt in ("-e", "--viriel"):
             VirielStress=True
-                        
-    SizeOfBox=MyFloat(Number*SizeOfBox)
+        elif opt in ("-g", "--opengl"):
+            OpenGL=True
+        elif opt in ("-p", "--rendering"):
+            SpeedRendering=True
+        elif opt in ("-o", "--verbose"):
+            Verbose=True
+        elif opt in ("-f", "--force"):
+            InterType='Force'
+
+    SizeOfShape=MyFloat(SizeOfShape*Number)
     Velocity=MyFloat(Velocity)
     Step=MyFloat(Step)
                 
     print("Device choosed : %s" % Device)
     print("Number of particules : %s" % Number)
-    print("Size of Box : %s" % SizeOfBox)
+    print("Size of Shape : %s" % SizeOfShape)
     print("Initial velocity : %s" % Velocity)
+    print("Step of iteration : %s" % Step)
     print("Number of iterations : %s" % Iterations)
-    print("Step of iteration : %s" % Step)
     print("Method of resolution : %s" % Method)
     print("Initial Random for RNG Seed : %s" % InitialRandom)
-    print("Check for Energies : %s" % CheckEnergies)
-    print("Graph for Samples : %s" % GraphSamples)
     print("ValueType is : %s" % ValueType)
-    print("Viriel distribution of stress %s" % VirielStress)
+    print("Viriel distribution of stress : %s" % VirielStress)
+    print("OpenGL real time rendering : %s" % OpenGL)
+    print("Speed rendering : %s" % SpeedRendering)
+    print("Interaction type : %s" % InterType)
 
     # Create Numpy array of CL vector with 8 FP32    
-    MyCoM = np.zeros(1,dtype=clType4)
-    MyDataX = np.zeros(Number, dtype=clType4)
-    MyDataV = np.zeros(Number, dtype=clType4)
+    MyCoM = np.zeros(4,dtype=MyFloat)
+    MyDataX = np.zeros(Number*4, dtype=MyFloat)
+    MyDataV = np.zeros(Number*4, dtype=MyFloat)
     MyPotential = np.zeros(Number, dtype=MyFloat)
     MyKinetic = np.zeros(Number, dtype=MyFloat)
 
-    Marsaglia,Computing=DictionariesAPI()
+    Marsaglia,Computing,Interaction=DictionariesAPI()
 
     # Scan the OpenCL arrays
     Id=0
@@ -500,101 +781,109 @@
     except:
         print("Crash during context creation")
 
-    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 :
+
+    #BuildOptions="-cl-mad-enable -cl-kernel-arg-info -cl-fast-relaxed-math -cl-std=CL1.2 -DTRNG=%i -DTYPE=%i" % (Marsaglia[RNG],Computing[ValueType])
+    BuildOptions="-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%i -DINTERACTION=%i" % (Marsaglia[RNG],Computing[ValueType],Interaction[InterType])
+
+    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)
     
-    mf = cl.mem_flags
-    # 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/HostPointer 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)
+    # clKinetic = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyKinetic)
+    # clCoM = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyCoM)
 
-    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)
-    clKinetic = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyKinetic)
-    clCoM = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=MyCoM)
-
     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)))
+        seed_w=np.uint32(nprnd(2**32))
+        seed_z=np.uint32(nprnd(2**32))
     else:
-        MyRoutines.SplutterPoints(queue,(Number,1),None,clDataX,SizeOfBox,np.uint32(110271),np.uint32(250173))
+        seed_w=np.uint32(19710211)
+        seed_z=np.uint32(20081010)
+            
+    if Shape=='Ball':
+        MyRoutines.InBallSplutterPoints(queue,(Number,1),None,clDataX,SizeOfShape,seed_w,seed_z)
+    else:
+        MyRoutines.InBoxSplutterPoints(queue,(Number,1),None,clDataX,SizeOfShape,seed_w,seed_z)
 
     print('All particules distributed')
 
     CLLaunch=MyRoutines.CenterOfMass(queue,(1,1),None,clDataX,clCoM,np.int32(Number))
     CLLaunch.wait()
     cl.enqueue_copy(queue,MyCoM,clCoM)
-    print('Center Of Mass: (%s,%s,%s)' % (MyCoM[0][0],MyCoM[0][1],MyCoM[0][2]))
+    print('Center Of Mass estimated: (%s,%s,%s)' % (MyCoM[0],MyCoM[1],MyCoM[2]))
     
     if VirielStress:
         CLLaunch=MyRoutines.SplutterStress(queue,(Number,1),None,clDataX,clDataV,clCoM,MyFloat(0.),np.uint32(110271),np.uint32(250173))
     else:
         CLLaunch=MyRoutines.SplutterStress(queue,(Number,1),None,clDataX,clDataV,clCoM,Velocity,np.uint32(110271),np.uint32(250173))
     CLLaunch.wait()
-        
-    if GraphSamples:
-        cl.enqueue_copy(queue, MyDataX, clDataX)
-        t0=np.array([[MyDataX[0][0],MyDataX[0][1],MyDataX[0][2]]])
-        t1=np.array([[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]]])
-        tL=np.array([[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]]])
 
+    print('All particules stressed')
+
     CLLaunch=MyRoutines.Potential(queue,(Number,1),None,clDataX,clPotential)
     CLLaunch=MyRoutines.Kinetic(queue,(Number,1),None,clDataV,clKinetic)
     CLLaunch.wait()
     cl.enqueue_copy(queue,MyPotential,clPotential)
     cl.enqueue_copy(queue,MyKinetic,clKinetic)
-    print('Viriel=%s Potential=%s Kinetic=%s'% (np.sum(MyPotential)+2*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
- 
-    if GraphSamples:
-        cl.enqueue_copy(queue, MyDataX, clDataX)
-        t0=np.array([[MyDataX[0][0],MyDataX[0][1],MyDataX[0][2]]])
-        t1=np.array([[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]]])
-        tL=np.array([[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]]])
+    print('Energy estimated: Viriel=%s Potential=%s Kinetic=%s\n'% (np.sum(MyPotential)+2*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
 
-    time_start=time.time()
-    for i in range(Iterations):
-        if Method=="RungeKutta":            
-            CLLaunch=MyRoutines.RungeKutta(queue,(Number,1),None,clDataX,clDataV,Step)
-        elif Method=="ExplicitEuler":
-            CLLaunch=MyRoutines.ExplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
-        elif Method=="Heun":
-            CLLaunch=MyRoutines.Heun(queue,(Number,1),None,clDataX,clDataV,Step)
-        else:
-            CLLaunch=MyRoutines.ImplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
-        CLLaunch.wait()
+    if SpeedRendering:
+        SizeOfBox=max(2*MyKinetic)
+    else:
+        SizeOfBox=SizeOfShape        
+    
+    wall_time_start=time.time()
 
-        if CheckEnergies:
-            CLLaunch=MyRoutines.Potential(queue,(Number,1),None,clDataX,clPotential)
-            CLLaunch=MyRoutines.Kinetic(queue,(Number,1),None,clDataV,clKinetic)
-            CLLaunch.wait()
-            cl.enqueue_copy(queue,MyPotential,clPotential)
-            cl.enqueue_copy(queue,MyKinetic,clKinetic)
-            print(np.sum(MyPotential)+2.*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic))
+    Durations=np.array([],dtype=MyFloat)
+    print('Starting!')
+    if OpenGL:
+        global ViewRX,ViewRY,ViewRZ
+        Iterations=0
+        ViewRX,ViewRY,ViewRZ = 0.,0.,0.
+        # Launch OpenGL Loop
+        glutInit(sys.argv)
+        glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
+        glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION)
+        glutInitWindowSize(512,512)
+        glutCreateWindow(b'NBodyGL')
+        setup_viewport()
+        glutReshapeFunc(reshape)
+        glutDisplayFunc(display)
+        glutIdleFunc(display)
+        #   glutMouseFunc(mouse)
+        glutSpecialFunc(special)
+        glutKeyboardFunc(keyboard)
+        glutMainLoop()
+    else:
+        for iteration in range(Iterations):
+            Elapsed=MainOpenCL(clDataX,clDataV,Step,Method)
+            if Verbose:
+                # print("Duration of #%s iteration: %s" % (iteration,Elapsed))
+                cl.enqueue_copy(queue, MyDataX, clDataX)
+                print("Positions for #%s iteration: %s" % (iteration,MyDataX))
+            else:
+                sys.stdout.write('.')
+                sys.stdout.flush()
+            Durations=np.append(Durations,Elapsed)
 
-            print(MyPotential,MyKinetic)
+    print('\nEnding!')
             
-        if GraphSamples:
-            cl.enqueue_copy(queue, MyDataX, clDataX)
-            t0=np.append(t0,[MyDataX[0][0],MyDataX[0][1],MyDataX[0][2]])
-            t1=np.append(t1,[MyDataX[1][0],MyDataX[1][1],MyDataX[1][2]])
-            tL=np.append(tL,[MyDataX[-1][0],MyDataX[-1][1],MyDataX[-1][2]])
-    print("\nDuration on %s for each %s\n" % (Device,(time.time()-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)
@@ -602,30 +891,20 @@
     cl.enqueue_copy(queue,MyCoM,clCoM)
     cl.enqueue_copy(queue,MyPotential,clPotential)
     cl.enqueue_copy(queue,MyKinetic,clKinetic)
-    print('Center Of Mass: (%s,%s,%s)' % (MyCoM[0][0],MyCoM[0][1],MyCoM[0][2]))
-    print('Viriel=%s Potential=%s Kinetic=%s'% (np.sum(MyPotential)+2.*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
-    
-    if GraphSamples:    
-        t0=np.transpose(np.reshape(t0,(Iterations+1,3)))
-        t1=np.transpose(np.reshape(t1,(Iterations+1,3)))
-        tL=np.transpose(np.reshape(tL,(Iterations+1,3)))
-    
-        import matplotlib.pyplot as plt
-        from mpl_toolkits.mplot3d import Axes3D
-    
-        fig = plt.figure()
-        ax = fig.gca(projection='3d')
-        ax.scatter(t0[0],t0[1],t0[2], marker='^',color='blue')
-        ax.scatter(t1[0],t1[1],t1[2], marker='o',color='red')
-        ax.scatter(tL[0],tL[1],tL[2], marker='D',color='green')
-   
-        ax.set_xlabel('X Label')
-        ax.set_ylabel('Y Label')
-        ax.set_zlabel('Z Label')
+    print('\nCenter Of Mass estimated: (%s,%s,%s)' % (MyCoM[0],MyCoM[1],MyCoM[2]))
+    print('Energy estimated: Viriel=%s Potential=%s Kinetic=%s\n'% (np.sum(MyPotential)+2.*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
 
-        plt.show()
-    
+    print("Duration stats on device %s with %s iterations :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n\n\tVariability:\t%s\n" % (Device,Iterations,np.mean(Durations),np.median(Durations),np.std(Durations),np.min(Durations),np.max(Durations),np.std(Durations)/np.median(Durations)))
+
+    # Contraction of Square*Size*Hertz: Size*Size/Elapsed
+    Squertz=np.ones(len(Durations))
+    Squertz*=Number*Number
+    Squertz/=Durations
+
+    print("Squertz in log10 stats on device %s with %s iterations :\n\tMean:\t%s\n\tMedian:\t%s\n\tStddev:\t%s\n\tMin:\t%s\n\tMax:\t%s\n" % (Device,Iterations,np.log10(np.mean(Squertz)),np.log10(np.median(Squertz)),np.log10(np.std(Squertz)),np.log10(np.min(Squertz)),np.log10(np.max(Squertz))))
+        
     clDataX.release()
     clDataV.release()
     clKinetic.release()
     clPotential.release()
+
