Index: Pi/GPU/Pi-GPU.py
===================================================================
--- Pi/GPU/Pi-GPU.py	(revision 45)
+++ Pi/GPU/Pi-GPU.py	(revision 46)
@@ -304,40 +304,42 @@
 	
   # Initialisation des variables en les CASTant correctement
     
-  # Je detecte un peripherique GPU dans la liste des peripheriques
-  # for platform in cl.get_platforms():
-  # 	for device in platform.get_devices():
-  # 		if cl.device_type.to_string(device.type)=='GPU':
-  # 			GPU=device
-  #print "GPU detected: ",device.name
-
-  HasGPU=False
-  Id=1
-  # Primary Device selection based on Device Id
-  for platform in cl.get_platforms():
-    for device in platform.get_devices():
-      deviceType=cl.device_type.to_string(device.type)
-      if Id==Device and not HasGPU:
-        GPU=device
-        print "CPU/GPU selected: ",device.name
-        HasGPU=True
-      Id=Id+1
-  # Default Device selection based on ALU Type
-  for platform in cl.get_platforms():
-    for device in platform.get_devices():
-      deviceType=cl.device_type.to_string(device.type)
-      if deviceType=="GPU" and Alu=="GPU" and not HasGPU:
-        GPU=device
-        print "GPU selected: ",device.name
-        HasGPU=True
-      if deviceType=="CPU" and Alu=="CPU" and not HasGPU:        
-        GPU=device
-        print "CPU selected: ",device.name
-        HasGPU=True
+  if Device==0:
+    print "Enter XPU selector based on ALU type: first selected"
+    HasXPU=False
+    # Default Device selection based on ALU Type
+    for platform in cl.get_platforms():
+      for device in platform.get_devices():
+        deviceType=cl.device_type.to_string(device.type)
+        if deviceType=="GPU" and Alu=="GPU" and not HasXPU:
+          XPU=device
+          print "GPU selected: ",device.name
+          HasXPU=True
+        if deviceType=="CPU" and Alu=="CPU" and not HasXPU:        
+          XPU=device
+          print "CPU selected: ",device.name
+          HasXPU=True
+  else:
+    print "Enter XPU selector based on device number & ALU type"
+    Id=1
+    HasXPU=False
+    # Primary Device selection based on Device Id
+    for platform in cl.get_platforms():
+      for device in platform.get_devices():
+        deviceType=cl.device_type.to_string(device.type)
+        if Id==Device and Alu==deviceType and HasXPU==False:
+          XPU=device
+          print "CPU/GPU selected: ",device.name
+          HasXPU=True
+        Id=Id+1
+    if HasXPU==False:
+      print "No XPU #%i of type %s found in all of %i devices, sorry..." % \
+          (Device,Alu,Id-1)
+      return(0,0,0)
 				
   # Je cree le contexte et la queue pour son execution
   #ctx = cl.create_some_context()
-  ctx = cl.Context([GPU])
+  ctx = cl.Context([XPU])
   queue = cl.CommandQueue(ctx,
                           properties=cl.command_queue_properties.PROFILING_ENABLE)
 
@@ -493,7 +495,7 @@
   # Set defaults values
   # Alu can be CPU or GPU
   Alu='CPU'
-  # Id of GPU : 0 is for first find !
+  # Id of GPU : 1 is for first find !
   Device=0
   # GPU style can be Cuda (Nvidia implementation) or OpenCL
   GpuStyle='OpenCL'
@@ -522,6 +524,17 @@
   for opt, arg in opts:
     if opt == '-h':
       print '%s -o (Out of Core Metrology) -c (Print Curves) -a <CPU/GPU> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -r <RedoToImproveStats>' % sys.argv[0]
+
+      print "\nInformations about devices detected under OpenCL:"
+      # For PyOpenCL import
+      import pyopencl as cl
+      Id=1
+      for platform in cl.get_platforms():
+        for device in platform.get_devices():
+          deviceType=cl.device_type.to_string(device.type)
+          print "Device #%i of type %s : %s" % (Id,deviceType,device.name)
+          Id=Id+1
+
       sys.exit()
     elif opt == '-o':
       OutMetrology=True
@@ -599,18 +612,21 @@
         start=time.time()
         if GpuStyle=='CUDA':
           try:
-            MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle)
+            a,m,s=MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle)
           except:
             print "Problem with %i // computations on Cuda" % Jobs
         elif GpuStyle=='OpenCL':
           try:
-            MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,Alu,Device)
+            a,m,s=MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,Alu,Device)
           except:
             print "Problem with %i // computations on OpenCL" % Jobs            
         duration=numpy.append(duration,time.time()-start)
-      avg=numpy.mean(duration)
-      med=numpy.median(duration)
-      std=numpy.std(duration)
+      if (a,m,s) != (0,0,0):
+        avg=numpy.mean(duration)
+        med=numpy.median(duration)
+        std=numpy.std(duration)
+      else:
+        print "Values seem to be wrong..."
     else:
       if GpuStyle=='CUDA':
         try:
@@ -632,8 +648,9 @@
     else:
       print "Values seem to be wrong..."
     #THREADS*=2
-    numpy.savez("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
-    numpy.savetxt("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
+    if len(average)!=0:
+      numpy.savez("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
+      numpy.savetxt("Pi_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
     Jobs+=1
 
   FitAndPrint(ExploredJobs,median,Curves)
