Index: NBody/NBodyGL.py
===================================================================
--- NBody/NBodyGL.py	(revision 168)
+++ NBody/NBodyGL.py	(revision 169)
@@ -23,19 +23,7 @@
 
 
 
-Blob="""
-__kernel void RungeKutta(__global MYFLOAT4* clDataX,__global MYFLOAT4* clDataV,MYFLOAT h)
-{
-    private int gid = get_global_id(0);
-    private MYFLOAT8 clDataGid;
-    
-    clDataGid=AtomicRungeKutta(clDataX,clDataV,gid,h);
-    barrier(CLK_GLOBAL_MEM_FENCE);
-    clDataX[gid]=clDataGid.s0123;
-    clDataV[gid]=clDataGid.s4567;
-}
 
-"""
 
 
 
@@ -96,7 +84,6 @@
 
 
 
-
 BlobOpenCL= """
 #define TFP32 0
 #define TFP64 1
@@ -486,14 +473,7 @@
 
 """
 
-def display(*args):
-
-    global MyDataX,MyDataV,clDataX,clDataV,Step,Method,Number,Iterations,Durations,Verbose
-    
-    glClearColor(0.0, 0.0, 0.0, 0.0)
-    glClear(GL_COLOR_BUFFER_BIT)
-    glColor3f(1.0,1.0,1.0)
-    
+def MainOpenCL(clDataX,clDataV,Step,Method):
     time_start=time.time()
     if Method=="RungeKutta":
         CLLaunch=MyRoutines.RungeKutta(queue,(Number,1),None,clDataX,clDataV,Step)
@@ -505,20 +485,32 @@
         CLLaunch=MyRoutines.ImplicitEuler(queue,(Number,1),None,clDataX,clDataV,Step)
     CLLaunch.wait()
     Elapsed=time.time()-time_start
-    Durations=np.append(Durations,Elapsed)
+    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("Duration of #%s iteration: %s" % (Iterations,Elapsed))
     else:
         sys.stdout.write('.')
         sys.stdout.flush()
-    cl.enqueue_copy(queue, MyDataX, clDataX)
-    # 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))
+    Durations=np.append(Durations,MainOpenCL(clDataX,clDataV,Step,Method))    
     glEnableClientState(GL_VERTEX_ARRAY)
     glDrawArrays(GL_POINTS, 0, Number)
     glDisableClientState(GL_VERTEX_ARRAY)
@@ -530,11 +522,12 @@
     pass
 
 def keyboard(k,x,y):
-    global ViewRZ,SizeOfBox
+    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:
@@ -545,6 +538,11 @@
         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)
@@ -614,15 +612,17 @@
     VirielStress=True
     # Verbose
     Verbose=False
-    # OpenGL demo
+    # OpenGL real time rendering
     OpenGL=False
+    # Speed rendering
+    SpeedRendering=False
     # Shape to distribute
     Shape='Box'
     
-    HowToUse='%s -h [Help] -r [InitialRandom] -g [OpenGL] -e [VirielStress] -d <DeviceId> -n <NumberOfParticules> -i <Iterations> -z <SizeOfBoxOrBall> -v <Velocity> -s <Step> -b <Ball|Box> -m <ImplicitEuler|RungeKutta|ExplicitEuler|Heun> -t <FP32|FP64>'
+    HowToUse='%s -h [Help] -r [InitialRandom] -g [OpenGL] -e [VirielStress] -d <DeviceId> -p [SpeedRendering] -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:],"rgehd:n:i:z:v:s:m:t:b:",["random","opengl","viriel","device=","number=","iterations=","size=","velocity=","step=","method=","valuetype=","shape="])
+        opts, args = getopt.getopt(sys.argv[1:],"rpgehd:n:i:z:v:s:m:t:b:",["random","rendering","opengl","viriel","device=","number=","iterations=","size=","velocity=","step=","method=","valuetype=","shape="])
     except getopt.GetoptError:
         print(HowToUse % sys.argv[0])
         sys.exit(2)
@@ -677,6 +677,8 @@
             VirielStress=True
         elif opt in ("-g", "--opengl"):
             OpenGL=True
+        elif opt in ("-p", "--rendering"):
+            SpeedRendering=True
                         
     SizeOfShape=MyFloat(SizeOfShape*Number)
     Velocity=MyFloat(Velocity)
@@ -692,6 +694,8 @@
     print("Initial Random for RNG Seed : %s" % InitialRandom)
     print("ValueType is : %s" % ValueType)
     print("Viriel distribution of stress : %s" % VirielStress)
+    print("OpenGL real time rendering : %s" % OpenGL)
+    print("Speed rendering : %s" % SpeedRendering)
 
     # Create Numpy array of CL vector with 8 FP32    
     MyCoM = np.zeros(4,dtype=MyFloat)
@@ -787,30 +791,46 @@
     cl.enqueue_copy(queue,MyPotential,clPotential)
     cl.enqueue_copy(queue,MyKinetic,clKinetic)
     print('Energy estimated: Viriel=%s Potential=%s Kinetic=%s\n'% (np.sum(MyPotential)+2*np.sum(MyKinetic),np.sum(MyPotential),np.sum(MyKinetic)))
- 
+
+    if SpeedRendering:
+        SizeOfBox=max(2*MyKinetic)
+    else:
+        SizeOfBox=SizeOfShape        
+    
     wall_time_start=time.time()
 
-    # Launch OpenGL Loop
-    global SizeOfBox,ViewRX,ViewRY,ViewRZ
-    ViewRX,ViewRY,ViewRZ = 0.,0.,0.
-    SizeOfBox=SizeOfShape
-    Iterations=0
     Durations=np.array([],dtype=MyFloat)
-    glutInit(sys.argv)
-    glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGB)
-    glutSetOption(GLUT_ACTION_ON_WINDOW_CLOSE,GLUT_ACTION_CONTINUE_EXECUTION)
-    glutSetOption(GLUT_ACTION_GLUTMAINLOOP_RETURNS,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()
-    
+    print('Starting!')
+    if OpenGL:
+        global SizeOfBox,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" % (Iterations,Elapsed))
+            else:
+                sys.stdout.write('.')
+                sys.stdout.flush()
+            Durations=np.append(Durations,Elapsed)
+
+    print('\nEnding!')
+            
     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)
