Index: PiXPU.py
===================================================================
--- PiXPU.py	(revision 105)
+++ PiXPU.py	(revision 106)
@@ -456,19 +456,19 @@
 
 #def MetropolisOpenCL(circle,iterations,steps,blocks,threads,Device,
 #                     RNG,ValueType):
-def MetropolisOpenCL(MetroParamCL):
+def MetropolisOpenCL(InputCL):
 
     import pyopencl as cl
 
-    iterations=MetroParamCL['Iterations']
-    steps=MetroParamCL['Steps']
-    blocks=MetroParamCL['Blocks']
-    threads=MetroParamCL['Threads']
-    Device=MetroParamCL['Device']
-    RNG=MetroParamCL['RNG']
-    ValueType=MetroParamCL['ValueType']
+    iterations=InputCL['Iterations']
+    steps=InputCL['Steps']
+    blocks=InputCL['Blocks']
+    threads=InputCL['Threads']
+    Device=InputCL['Device']
+    RNG=InputCL['RNG']
+    ValueType=InputCL['ValueType']
 
-    print iterations,steps,blocks,threads,Device,RNG,ValueType
+    # print iterations,steps,blocks,threads,Device,RNG,ValueType
     
     Marsaglia,Computing=DictionariesAPI()
     
@@ -479,6 +479,7 @@
     for platform in cl.get_platforms():
         for device in platform.get_devices():
             if Id==Device:
+                PlatForm=platform
                 XPU=device
                 print "CPU/GPU selected: ",device.name.lstrip()
                 HasXPU=True
@@ -489,14 +490,18 @@
         sys.exit()              
 
     # Je cree le contexte et la queue pour son execution
-    ctx = cl.Context([XPU])
-    queue = cl.CommandQueue(ctx,properties=cl.command_queue_properties.PROFILING_ENABLE)
+    try:
+        ctx = cl.Context([XPU])
+        queue = cl.CommandQueue(ctx,properties=cl.command_queue_properties.PROFILING_ENABLE)
+    except:
+        print "Crash during context creation"
 
     # Je recupere les flag possibles pour les buffers
     mf = cl.mem_flags
 	
+    circle=numpy.zeros(blocks*threads).astype(numpy.uint64)
     circleCL = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=circle)
-  
+    
     MetropolisCL = cl.Program(ctx,KernelCodeOpenCL()).build( options = "-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%s" % (Marsaglia[RNG],Computing[ValueType]))
 
     MyPi=numpy.zeros(steps)
@@ -504,10 +509,9 @@
   
     jobs=blocks*threads;
 
-    if iterations%jobs==0:
-        iterationsCL=numpy.uint64(iterations/jobs)
-    else:
-        iterationsCL=numpy.uint64(iterations/jobs+1)
+    iterationsCL=numpy.uint64(iterations/jobs)
+    if iterations%jobs!=0:
+        iterationsCL+=1
 
     for i in range(steps):
         start_time=time.time()
@@ -541,7 +545,9 @@
 
     circleCL.release()
 
-    return(sum(circle),iterationsCL*jobs,MyDuration)
+    OutputCL={'Inside':sum(circle),'NewIterations':numpy.uint64(iterationsCL*jobs),'Duration':MyDuration}
+    print OutputCL
+    return(OutputCL)
 
 
 def FitAndPrint(N,D,Curves):
@@ -798,16 +804,18 @@
                         print "Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads)
                 elif GpuStyle=='OpenCL':
                     try:
-                        MetroParamCL={}
-                        MetroParamCL['Iterations']=Iterations
-                        MetroParamCL['Steps']=1
-                        MetroParamCL['Blocks']=Blocks
-                        MetroParamCL['Threads']=Threads
-                        MetroParamCL['Device']=Devices[0]
-                        MetroParamCL['RNG']=RNG
-                        MetroParamCL['ValueType']=ValueType
-                    
-                        Inside,NewIterations,DurationItem=MetropolisOpenCL(MetroParamCL)
+                        InputCL={}
+                        InputCL['Iterations']=Iterations
+                        InputCL['Steps']=1
+                        InputCL['Blocks']=Blocks
+                        InputCL['Threads']=Threads
+                        InputCL['Device']=Devices[0]
+                        InputCL['RNG']=RNG
+                        InputCL['ValueType']=ValueType                    
+                        OutputCL=MetropolisOpenCL(InputCL)
+                        Inside=OutputCL['Circle']
+                        NewIterations=OutputCL['NewIterations']
+                        Duration=OutputCL['Duration']
                     except:
                         print "Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads)            
                 Duration=numpy.append(Duration,time.time()-start)
@@ -820,15 +828,18 @@
                     print "Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads)
             elif GpuStyle=='OpenCL':
                 try:
-                    MetroParamCL={}
-                    MetroParamCL['Iterations']=Iterations
-                    MetroParamCL['Steps']=Redo
-                    MetroParamCL['Blocks']=Blocks
-                    MetroParamCL['Threads']=Threads
-                    MetroParamCL['Device']=Devices[0]
-                    MetroParamCL['RNG']=RNG
-                    MetroParamCL['ValueType']=ValueType
-                    Inside,NewIterations,Duration=MetropolisOpenCL(MetroParamCL)
+                    InputCL={}
+                    InputCL['Iterations']=Iterations
+                    InputCL['Steps']=Redo
+                    InputCL['Blocks']=Blocks
+                    InputCL['Threads']=Threads
+                    InputCL['Device']=Devices[0]
+                    InputCL['RNG']=RNG
+                    InputCL['ValueType']=ValueType
+                    OutputCL=MetropolisOpenCL(InputCL)
+                    Inside=OutputCL['Inside']
+                    NewIterations=OutputCL['NewIterations']
+                    Duration=OutputCL['Duration']
                 except:
                     print "Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads)            
             Rate=NewIterations/Duration
