Index: PiXPU.py
===================================================================
--- PiXPU.py	(revision 126)
+++ PiXPU.py	(revision 127)
@@ -1,4 +1,4 @@
-#!/usr/bin/env python
+#!/usr/bin/env python3
 
 #
 # Pi-by-MonteCarlo using PyCUDA/PyOpenCL
@@ -39,7 +39,7 @@
         self.Max=numpy.max(Data)
         self.Min=numpy.min(Data)
     def display(self):
-        print "%s %s %s %s %s" % (self.Avg,self.Med,self.Std,self.Min,self.Max)
+        print("%s %s %s %s %s" % (self.Avg,self.Med,self.Std,self.Min,self.Max))
 
 class Experience:
     """Metrology for experiences"""
@@ -63,8 +63,8 @@
     def Metrology(self,Data):
         Duration=PenStacle(Data)
         Rate=PenStacle(Iterations/Data)
-        print "Duration %s" % Duration
-        print "Rate %s" % Rate
+        print("Duration %s" % Duration)
+        print("Rate %s" % Rate)
 
 
         
@@ -401,7 +401,7 @@
     
 def MetropolisCuda(InputCU):
 
-    print "Inside ",InputCU
+    print("Inside ",InputCU)
     
     iterations=InputCU['Iterations']
     steps=InputCU['Steps']
@@ -422,7 +422,7 @@
         for Id in range(cuda.Device.count()):
             if Id==Device:
                 XPU=cuda.Device(Id)
-                print "GPU selected %s" % (XPU.name())
+                print("GPU selected %s" % XPU.name())
         print
 
 #        import pycuda.driver as cuda
@@ -430,7 +430,7 @@
 #        import pycuda.autoinit
 
     except ImportError:
-        print "Platform does not seem to support CUDA"
+        print("Platform does not seem to support CUDA")
 
     Context=XPU.make_context()
     circle=numpy.zeros(blocks*threads).astype(numpy.uint64)  
@@ -441,7 +441,7 @@
     try:
         mod = SourceModule(KernelCodeCuda(),options=['--compiler-options','-DTRNG=%i -DTYPE=%s' % (Marsaglia[RNG],Computing[ValueType])])
     except:
-        print "Compilation seems to broke"
+        print("Compilation seems to broke")
   
     MetropolisBlocksCU=mod.get_function("MainLoopBlocks")
     MetropolisThreadsCU=mod.get_function("MainLoopThreads")
@@ -465,15 +465,15 @@
                                numpy.uint32(nprnd(2**32)),
                                grid=(blocks,1),block=(threads,1,1))
         except:
-            print "Crash during CUDA call"
+            print("Crash during CUDA call")
 
         elapsed = time.time()-start_time
-        print "(Blocks/Threads)=(%i,%i) method done in %.2f s..." % (blocks,threads,elapsed)
+        print("(Blocks/Threads)=(%i,%i) method done in %.2f s..." % (blocks,threads,elapsed))
 
         MyDuration[i]=elapsed
 
     OutputCU={'Inside':sum(circle),'NewIterations':numpy.uint64(iterationsCU*jobs),'Duration':MyDuration}
-    print OutputCU
+    print(OutputCU)
     
     Context.detach()
     return(OutputCU)
@@ -482,7 +482,7 @@
 
     import pyopencl as cl
 
-    print "Inside ",InputCL
+    print("Inside ",InputCL)
     
     iterations=InputCL['Iterations']
     steps=InputCL['Steps']
@@ -501,12 +501,12 @@
         for device in platform.get_devices():
             if Id==Device:
                 XPU=device
-                print "CPU/GPU selected: ",device.name.lstrip()
+                print("CPU/GPU selected: ",device.name.lstrip())
                 HasXPU=True
             Id+=1
 
     if HasXPU==False:
-        print "No XPU #%i found in all of %i devices, sorry..." % (Device,Id-1)
+        print("No XPU #%i found in all of %i devices, sorry..." % (Device,Id-1))
         sys.exit()              
 
     # Je cree le contexte et la queue pour son execution
@@ -514,7 +514,7 @@
         ctx = cl.Context([XPU])
         queue = cl.CommandQueue(ctx,properties=cl.command_queue_properties.PROFILING_ENABLE)
     except:
-        print "Crash during context creation"
+        print("Crash during context creation")
 
     # Je recupere les flag possibles pour les buffers
     mf = cl.mem_flags
@@ -551,7 +551,7 @@
         cl.enqueue_copy(queue, circle, circleCL).wait()
 
         elapsed = time.time()-start_time
-        print "(Blocks/Threads)=(%i,%i) method done in %.2f s..." % (blocks,threads,elapsed)
+        print("(Blocks/Threads)=(%i,%i) method done in %.2f s..." % (blocks,threads,elapsed))
             
         # Elapsed method based on CLLaunch doesn't work for Beignet OpenCL
         # elapsed = 1e-9*(CLLaunch.profile.end - CLLaunch.profile.start)
@@ -565,7 +565,7 @@
     circleCL.release()
 
     OutputCL={'Inside':sum(circle),'NewIterations':numpy.uint64(iterationsCL*jobs),'Duration':MyDuration}
-    print OutputCL
+    print(OutputCL)
     return(OutputCL)
 
 
@@ -581,10 +581,9 @@
         coeffs_Amdahl[1]=coeffs_Amdahl[1]*coeffs_Amdahl[0]/D[0]
         coeffs_Amdahl[2]=coeffs_Amdahl[2]*coeffs_Amdahl[0]/D[0]
         coeffs_Amdahl[0]=D[0]
-        print "Amdahl Normalized: T=%.2f(%.6f+%.6f/N)" % \
-            (coeffs_Amdahl[0],coeffs_Amdahl[1],coeffs_Amdahl[2])
+        print("Amdahl Normalized: T=%.2f(%.6f+%.6f/N)" % (coeffs_Amdahl[0],coeffs_Amdahl[1],coeffs_Amdahl[2]))
     except:
-        print "Impossible to fit for Amdahl law : only %i elements" % len(D) 
+        print("Impossible to fit for Amdahl law : only %i elements" % len(D))
 
     try:
         coeffs_AmdahlR, matcov_AmdahlR = curve_fit(AmdahlR, N, D)
@@ -592,12 +591,10 @@
         D_AmdahlR=AmdahlR(N,coeffs_AmdahlR[0],coeffs_AmdahlR[1])
         coeffs_AmdahlR[1]=coeffs_AmdahlR[1]*coeffs_AmdahlR[0]/D[0]
         coeffs_AmdahlR[0]=D[0]
-        print "Amdahl Reduced Normalized: T=%.2f(%.6f+%.6f/N)" % \
-            (coeffs_AmdahlR[0],1-coeffs_AmdahlR[1],coeffs_AmdahlR[1])
+        print("Amdahl Reduced Normalized: T=%.2f(%.6f+%.6f/N)" % (coeffs_AmdahlR[0],1-coeffs_AmdahlR[1],coeffs_AmdahlR[1]))
 
     except:
-        print "Impossible to fit for Reduced Amdahl law : only %i elements" \
-            % len(D) 
+        print("Impossible to fit for Reduced Amdahl law : only %i elements" % len(D))
 
     try:
         coeffs_Mylq, matcov_Mylq = curve_fit(Mylq, N, D)
@@ -606,14 +603,14 @@
         # coeffs_Mylq[2]=coeffs_Mylq[2]*coeffs_Mylq[0]/D[0]
         coeffs_Mylq[3]=coeffs_Mylq[3]*coeffs_Mylq[0]/D[0]
         coeffs_Mylq[0]=D[0]
-        print "Mylq Normalized : T=%.2f(%.6f+%.6f/N)+%.6f*N" % (coeffs_Mylq[0],
+        print("Mylq Normalized : T=%.2f(%.6f+%.6f/N)+%.6f*N" % (coeffs_Mylq[0],
                                                                 coeffs_Mylq[1],
                                                                 coeffs_Mylq[3],
-                                                                coeffs_Mylq[2])
+                                                                coeffs_Mylq[2]))
         D_Mylq=Mylq(N,coeffs_Mylq[0],coeffs_Mylq[1],coeffs_Mylq[2],
                     coeffs_Mylq[3])
     except:
-        print "Impossible to fit for Mylq law : only %i elements" % len(D) 
+        print("Impossible to fit for Mylq law : only %i elements" % len(D))
 
     try:
         coeffs_Mylq2, matcov_Mylq2 = curve_fit(Mylq2, N, D)
@@ -623,12 +620,10 @@
         # coeffs_Mylq2[3]=coeffs_Mylq2[3]*coeffs_Mylq2[0]/D[0]
         coeffs_Mylq2[4]=coeffs_Mylq2[4]*coeffs_Mylq2[0]/D[0]
         coeffs_Mylq2[0]=D[0]
-        print "Mylq 2nd order Normalized: T=%.2f(%.6f+%.6f/N)+%.6f*N+%.6f*N^2" % \
-            (coeffs_Mylq2[0],coeffs_Mylq2[1],
-             coeffs_Mylq2[4],coeffs_Mylq2[2],coeffs_Mylq2[3])
+        print("Mylq 2nd order Normalized: T=%.2f(%.6f+%.6f/N)+%.6f*N+%.6f*N^2" % (coeffs_Mylq2[0],coeffs_Mylq2[1],coeffs_Mylq2[4],coeffs_Mylq2[2],coeffs_Mylq2[3]))
 
     except:
-        print "Impossible to fit for 2nd order Mylq law : only %i elements" % len(D) 
+        print("Impossible to fit for 2nd order Mylq law : only %i elements" % len(D))
 
     if Curves:
         plt.xlabel("Number of Threads/work Items")
@@ -639,7 +634,7 @@
         pAmdahl,=plt.plot(N,D_Amdahl,label="Loi de Amdahl")    
         pMylq,=plt.plot(N,D_Mylq,label="Loi de Mylq")
     except:
-        print "Fit curves seem not to be available"
+        print("Fit curves seem not to be available")
 
     plt.legend()
     plt.show()
@@ -685,7 +680,7 @@
     try:
         opts, args = getopt.getopt(sys.argv[1:],"hocg:i:b:e:s:f:l:t:r:d:m:v:",["gpustyle=","iterations=","blocksBegin=","blocksEnd=","blocksStep=","threadsFirst=","threadsLast=","threadssTep=","redo=","device=","marsaglia=","valuetype="])
     except getopt.GetoptError:
-        print HowToUse % sys.argv[0]
+        print(HowToUse % sys.argv[0])
         sys.exit(2)
 
     # List of Devices
@@ -694,9 +689,9 @@
         
     for opt, arg in opts:
         if opt == '-h':
-            print HowToUse % sys.argv[0]
+            print(HowToUse % sys.argv[0])
 
-            print "\nInformations about devices detected under OpenCL API:"
+            print("\nInformations about devices detected under OpenCL API:")
             # For PyOpenCL import
             try:
                 import pyopencl as cl
@@ -704,23 +699,23 @@
                 for platform in cl.get_platforms():
                     for device in platform.get_devices():
                         deviceType=cl.device_type.to_string(device.type)
-                        print "Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip())
+                        print("Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip()))
                         Id=Id+1
 
             except:
-                print "Your platform does not seem to support OpenCL"
+                print("Your platform does not seem to support OpenCL")
 
-            print "\nInformations about devices detected under CUDA API:"
+            print("\nInformations about devices detected under CUDA API:")
             # For PyCUDA import
             try:
                 import pycuda.driver as cuda
                 cuda.init()
                 for Id in range(cuda.Device.count()):
                     device=cuda.Device(Id)
-                    print "Device #%i of type GPU : %s" % (Id,device.name())
+                    print("Device #%i of type GPU : %s" % (Id,device.name()))
                 print
             except:
-                print "Your platform does not seem to support CUDA"
+                print("Your platform does not seem to support CUDA")
         
             sys.exit()
         
@@ -755,19 +750,19 @@
         elif opt in ("-r", "--redo"):
             Redo = int(arg)
 
-    print "Devices Identification : %s" % Devices
-    print "GpuStyle used : %s" % GpuStyle
-    print "Iterations : %s" % Iterations
-    print "Number of Blocks on begin : %s" % BlocksBegin
-    print "Number of Blocks on end : %s" % BlocksEnd
-    print "Step on Blocks : %s" % BlocksStep
-    print "Number of Threads on begin : %s" % ThreadsBegin
-    print "Number of Threads on end : %s" % ThreadsEnd
-    print "Step on Threads : %s" % ThreadsStep
-    print "Number of redo : %s" % Redo
-    print "Metrology done out of XPU : %r" % OutMetrology
-    print "Type of Marsaglia RNG used : %s" % RNG
-    print "Type of variable : %s" % ValueType
+    print("Devices Identification : %s" % Devices)
+    print("GpuStyle used : %s" % GpuStyle)
+    print("Iterations : %s" % Iterations)
+    print("Number of Blocks on begin : %s" % BlocksBegin)
+    print("Number of Blocks on end : %s" % BlocksEnd)
+    print("Step on Blocks : %s" % BlocksStep)
+    print("Number of Threads on begin : %s" % ThreadsBegin)
+    print("Number of Threads on end : %s" % ThreadsEnd)
+    print("Step on Threads : %s" % ThreadsStep)
+    print("Number of redo : %s" % Redo)
+    print("Metrology done out of XPU : %r" % OutMetrology)
+    print("Type of Marsaglia RNG used : %s" % RNG)
+    print("Type of variable : %s" % ValueType)
 
     if GpuStyle=='CUDA':
         try:
@@ -777,12 +772,12 @@
             cuda.init()
             for Id in range(cuda.Device.count()):
                 device=cuda.Device(Id)
-                print "Device #%i of type GPU : %s" % (Id,device.name())
+                print("Device #%i of type GPU : %s" % (Id,device.name()))
                 if Id in Devices:
                     Alu[Id]='GPU'
             
         except ImportError:
-            print "Platform does not seem to support CUDA"
+            print("Platform does not seem to support CUDA")
 
     if GpuStyle=='OpenCL':
         try:
@@ -792,19 +787,19 @@
             for platform in cl.get_platforms():
                 for device in platform.get_devices():
                     deviceType=cl.device_type.to_string(device.type)
-                    print "Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip().rstrip(),deviceType,device.name.lstrip().rstrip())
+                    print("Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip().rstrip(),deviceType,device.name.lstrip().rstrip()))
 
                     if Id in Devices:
                     # Set the Alu as detected Device Type
                         Alu[Id]=deviceType
                     Id=Id+1
         except ImportError:
-            print "Platform does not seem to support OpenCL"
+            print("Platform does not seem to support OpenCL")
 
-    print Devices,Alu
+    print(Devices,Alu)
             
-    BlocksList=xrange(BlocksBegin,BlocksEnd+BlocksStep,BlocksStep)
-    ThreadsList=xrange(ThreadsBegin,ThreadsEnd+ThreadsStep,ThreadsStep)
+    BlocksList=range(BlocksBegin,BlocksEnd+BlocksStep,BlocksStep)
+    ThreadsList=range(ThreadsBegin,ThreadsEnd+ThreadsStep,ThreadsStep)
     
     ExploredJobs=numpy.array([]).astype(numpy.uint32)
     ExploredBlocks=numpy.array([]).astype(numpy.uint32)
@@ -849,7 +844,7 @@
                         NewIterations=OutputCU['NewIterations']
                         Duration=OutputCU['Duration']
                     except:
-                        print "Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads)
+                        print("Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads))
                 elif GpuStyle=='OpenCL':
                     try:
                         InputCL={}
@@ -865,7 +860,7 @@
                         NewIterations=OutputCL['NewIterations']
                         Duration=OutputCL['Duration']
                     except:
-                        print "Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads)            
+                        print("Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads))
                 Duration=numpy.append(Duration,time.time()-start)
                 Rate=numpy.append(Rate,NewIterations/Duration[-1])
         else:
@@ -884,7 +879,7 @@
                     NewIterations=OutputCU['NewIterations']
                     Duration=OutputCU['Duration']
                 except:
-                    print "Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads)
+                    print("Problem with (%i,%i) // computations on Cuda" % (Blocks,Threads))
             elif GpuStyle=='OpenCL':
                 try:
                     InputCL={}
@@ -900,7 +895,7 @@
                     NewIterations=OutputCL['NewIterations']
                     Duration=OutputCL['Duration']
                 except:
-                    print "Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads)            
+                    print("Problem with (%i,%i) // computations on OpenCL" % (Blocks,Threads))
             Rate=NewIterations/Duration
             
         avgD=numpy.append(avgD,numpy.average(Duration))
@@ -914,7 +909,7 @@
         minR=numpy.append(minR,numpy.min(Rate))
         maxR=numpy.append(maxR,numpy.max(Rate))
 
-        print "%.2f %.2f %.2f %.2f %.2f %i %i %i %i %i" % (avgD[-1],medD[-1],stdD[-1],minD[-1],maxD[-1],avgR[-1],medR[-1],stdR[-1],minR[-1],maxR[-1])
+        print("%.2f %.2f %.2f %.2f %.2f %i %i %i %i %i" % (avgD[-1],medD[-1],stdD[-1],minD[-1],maxD[-1],avgR[-1],medR[-1],stdR[-1],minR[-1],maxR[-1]))
         
         numpy.savez("Pi_%s_%s_%s_%s_%s_%s_%s_%s_%.8i_Device%i_%s_%s" % (ValueType,RNG,Alu[Devices[0]],GpuStyle,BlocksBegin,BlocksEnd,ThreadsBegin,ThreadsEnd,Iterations,Devices[0],Metrology,gethostname()),(ExploredBlocks,ExploredThreads,avgD,medD,stdD,minD,maxD,avgR,medR,stdR,minR,maxR))
         ToSave=[ ExploredBlocks,ExploredThreads,avgD,medD,stdD,minD,maxD,avgR,medR,stdR,minR,maxR ]
