Index: Pi-GPU.py
===================================================================
--- Pi-GPU.py	(revision 72)
+++ Pi-GPU.py	(revision 73)
@@ -68,7 +68,16 @@
   return (T1*(s+p/N)+c1*N+c2*N*N)
 
 KERNEL_CODE_CUDA="""
+#define TCONG 0
+#define TSHR3 1
+#define TMWC 2
+#define TKISS 3
 
+#define TINT32 0
+#define TINT64 1
+#define TFP32 2
+#define TFP64 3
+
 // Marsaglia RNG very simple implementation
 
 #define znew  ((z=36969*(z&65535)+(z>>16))<<16)
@@ -233,8 +242,6 @@
 #define TFP32 2
 #define TFP64 3
 
-#pragma OPENCL EXTENSION cl_khr_fp64: enable
-
 // Marsaglia RNG very simple implementation
 #define znew  ((z=36969*(z&65535)+(z>>16))<<16)
 #define wnew  ((w=18000*(w&65535)+(w>>16))&65535)
@@ -249,208 +256,119 @@
 #define CONGfp CONG * 2.328306435454494e-10f
 #define SHR3fp SHR3 * 2.328306435454494e-10f
 
-__kernel void MainLoopGlobal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
+ulong MainLoop(ulong iterations,uint seed_z,uint seed_w,size_t work)
 {
 
-// Initialization of RNG numbers
 #if TRNG == TCONG
-   uint jcong=seed_z+get_global_id(0);
+   uint jcong=seed_z+work;
 #elif TRNG == TSHR3
-   uint jsr=seed_w+get_global_id(0);
+   uint jsr=seed_w+work;
 #elif TRNG == TMWC
-   uint z=seed_z+get_global_id(0);
-   uint w=seed_w+get_global_id(0);
+   uint z=seed_z+work;
+   uint w=seed_w+work;
 #elif TRNG == TKISS
-   uint jcong=seed_z+get_global_id(0);
-   uint jsr=seed_w+get_global_id(0);
-   uint z=seed_z-get_global_id(0);
-   uint w=seed_w-get_global_id(0);
+   uint jcong=seed_z+work;
+   uint jsr=seed_w+work;
+   uint z=seed_z-work;
+   uint w=seed_w-work;
 #endif
 
    ulong total=0;
 
-   // Main Loop
    for (ulong i=0;i<iterations;i++) {
 
-//
-
 #if TYPE == TINT32
-#define THEONE 1073741824
-#if TRNG == TCONG
-      uint x=CONG>>17 ;
-      uint y=CONG>>17 ;
-#elif TRNG == TSHR3
-      uint x=SHR3>>17 ;
-      uint y=SHR3>>17 ;
-#elif TRNG == TMWC
-      uint x=MWC>>17 ;
-      uint y=MWC>>17 ;
-#elif TRNG == TKISS
-      uint x=KISS>>17 ;
-      uint y=KISS>>17 ;
-#endif
+    #define THEONE 1073741824
+    #if TRNG == TCONG
+        uint x=CONG>>17 ;
+        uint y=CONG>>17 ;
+    #elif TRNG == TSHR3
+        uint x=SHR3>>17 ;
+        uint y=SHR3>>17 ;
+    #elif TRNG == TMWC
+        uint x=MWC>>17 ;
+        uint y=MWC>>17 ;
+    #elif TRNG == TKISS
+        uint x=KISS>>17 ;
+        uint y=KISS>>17 ;
+    #endif
 #elif TYPE == TINT64
-#define THEONE 4611686018427387904
-#if TRNG == TCONG
-      ulong x=(ulong)(CONG>>1) ;
-      ulong y=(ulong)(CONG>>1) ;
-#elif TRNG == TSHR3
-      ulong x=(ulong)(SHR3>>1) ;
-      ulong y=(ulong)(SHR3>>1) ;
-#elif TRNG == TMWC
-      ulong x=(ulong)(MWC>>1) ;
-      ulong y=(ulong)(MWC>>1) ;
-#elif TRNG == TKISS
-      ulong x=(ulong)(KISS>>1) ;
-      ulong y=(ulong)(KISS>>1) ;
-#endif
+    #define THEONE 4611686018427387904
+    #if TRNG == TCONG
+        ulong x=(ulong)(CONG>>1) ;
+        ulong y=(ulong)(CONG>>1) ;
+    #elif TRNG == TSHR3
+        ulong x=(ulong)(SHR3>>1) ;
+        ulong y=(ulong)(SHR3>>1) ;
+    #elif TRNG == TMWC
+        ulong x=(ulong)(MWC>>1) ;
+        ulong y=(ulong)(MWC>>1) ;
+    #elif TRNG == TKISS
+        ulong x=(ulong)(KISS>>1) ;
+        ulong y=(ulong)(KISS>>1) ;
+    #endif
 #elif TYPE == TFP32
-#define THEONE 1.0f
-#if TRNG == TCONG
-      float x=CONGfp ;
-      float y=CONGfp ;
-#elif TRNG == TSHR3
-      float x=SHR3fp ;
-      float y=SHR3fp ;
-#elif TRNG == TMWC
-      float x=MWCfp ;
-      float y=MWCfp ;
-#elif TRNG == TKISS
+    #define THEONE 1.0f
+    #if TRNG == TCONG
+        float x=CONGfp ;
+        float y=CONGfp ;
+    #elif TRNG == TSHR3
+        float x=SHR3fp ;
+        float y=SHR3fp ;
+    #elif TRNG == TMWC
+        float x=MWCfp ;
+        float y=MWCfp ;
+    #elif TRNG == TKISS
       float x=KISSfp ;
       float y=KISSfp ;
-#endif
+    #endif
 #elif TYPE == TFP64
-#define THEONE 1.0f
-#if TRNG == TCONG
-      double x=(double)CONGfp ;
-      double y=(double)CONGfp ;
-#elif TRNG == TSHR3
-      double x=(double)SHR3fp ;
-      double y=(double)SHR3fp ;
-#elif TRNG == TMWC
-      double x=(double)MWCfp ;
-      double y=(double)MWCfp ;
-#elif TRNG == TKISS
-      double x=(double)KISSfp ;
-      double y=(double)KISSfp ;
+#pragma OPENCL EXTENSION cl_khr_fp64: enable
+    #define THEONE 1.0f
+    #if TRNG == TCONG
+        double x=(double)CONGfp ;
+        double y=(double)CONGfp ;
+    #elif TRNG == TSHR3
+        double x=(double)SHR3fp ;
+        double y=(double)SHR3fp ;
+    #elif TRNG == TMWC
+        double x=(double)MWCfp ;
+        double y=(double)MWCfp ;
+    #elif TRNG == TKISS
+        double x=(double)KISSfp ;
+        double y=(double)KISSfp ;
+    #endif
 #endif
-#endif
 
-      // Matching test
       ulong inside=((x*x+y*y) <= THEONE) ? 1:0;
       total+=inside;
    }
+   
+   return(total);
+}
 
+__kernel void MainLoopGlobal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
+{
+   ulong total=MainLoop(iterations,seed_z,seed_w,get_global_id(0));
    barrier(CLK_GLOBAL_MEM_FENCE);
-   s[get_global_id(0)]=total;
-      
+   s[get_global_id(0)]=total;     
 }
 
+
 __kernel void MainLoopLocal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z+get_local_id(0);
-   uint w=seed_w+get_local_id(0);
-
-   ulong total=0;
-
-   for (ulong i=0;i<iterations;i++) {
-
-      float x=MWCfp ;
-      float y=MWCfp ;
-
-      // Matching test
-      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
-      total+=inside;
-   }
+   ulong total=MainLoop(iterations,seed_z,seed_w,get_local_id(0));
    barrier(CLK_LOCAL_MEM_FENCE);
    s[get_local_id(0)]=total;
-      
 }
 
 __kernel void MainLoopHybrid(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z+get_global_id(0);
-   uint w=seed_w+get_global_id(0);
-
-   ulong total=0;
-
-   for (uint i=0;i<iterations;i++) {
-
-      float x=MWCfp ;
-      float y=MWCfp ;
-
-      // Matching test
-      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
-      total+=inside;
-   }
-   barrier(CLK_GLOBAL_MEM_FENCE || CLK_GLOBAL_MEM_FENCE);
-   // s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
+   ulong total=MainLoop(iterations,seed_z,seed_w,get_global_id(0));
+   barrier(CLK_GLOBAL_MEM_FENCE || CLK_LOCAL_MEM_FENCE);
    s[get_global_id(0)]=total;
-      
 }
 
-__kernel void MainLoopGlobal64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
-{
-   uint z=seed_z+get_global_id(0);
-   uint w=seed_w+get_global_id(0);
-
-   ulong total=0;
-
-   for (ulong i=0;i<iterations;i++) {
-
-      double x=(double)MWCfp ;
-      double y=(double)MWCfp ;
-
-      // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
-      total+=inside;
-   }
-   barrier(CLK_GLOBAL_MEM_FENCE);
-   s[get_global_id(0)]=total;
-      
-}
-
-__kernel void MainLoopLocal64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
-{
-   uint z=seed_z+get_local_id(0);
-   uint w=seed_w+get_local_id(0);
-
-   ulong total=0;
-
-   for (ulong i=0;i<iterations;i++) {
-
-      double x=(double)MWCfp ;
-      double y=(double)MWCfp ;
-
-      // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
-      total+=inside;
-   }
-   barrier(CLK_LOCAL_MEM_FENCE);
-   s[get_local_id(0)]=total;
-      
-}
-
-__kernel void MainLoopHybrid64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
-{
-   uint z=seed_z+get_global_id(0);
-   uint w=seed_w+get_global_id(0);
-
-   ulong total=0;
-
-   for (uint i=0;i<iterations;i++) {
-
-      double x=(double)MWCfp ;
-      double y=(double)MWCfp ;
-
-      // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
-      total+=inside;
-   }
-   barrier(CLK_LOCAL_MEM_FENCE);
-   s[get_global_id(0)]=total;
-      
-}
 """
 
 def MetropolisCuda(circle,iterations,steps,jobs,ParaStyle,DoublePrecision):
@@ -554,7 +472,7 @@
 
 
 def MetropolisOpenCL(circle,iterations,steps,jobs,ParaStyle,Alu,Device,
-                     DoublePrecision,RNG,ValueType):
+                     RNG,ValueType):
 	
   # Initialisation des variables en les CASTant correctement
     
@@ -583,7 +501,7 @@
         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
+          print "CPU/GPU selected: ",device.name.lstrip()
           HasXPU=True
         Id=Id+1
     if HasXPU==False:
@@ -627,52 +545,31 @@
       # SeedZCL is lattice translated in CL format
       # SeedWCL is lattice translated in CL format
       # step is number of iterations
-      if DoublePrecision:
-        CLLaunch=MetropolisCL.MainLoopGlobal64(queue,(jobs,),None,
-                                               circleCL,
-                                               numpy.uint64(iterationsCL),
-                                               numpy.uint32(nprnd(2**30/jobs)),
-                                               numpy.uint32(nprnd(2**30/jobs)))
-      else:
-        CLLaunch=MetropolisCL.MainLoopGlobal(queue,(jobs,),None,
-                                             circleCL,
-                                             numpy.uint64(iterationsCL),
-                                             numpy.uint32(nprnd(2**30/jobs)),
-                                             numpy.uint32(nprnd(2**30/jobs)))
+      CLLaunch=MetropolisCL.MainLoopGlobal(queue,(jobs,),None,
+                                           circleCL,
+                                           numpy.uint64(iterationsCL),
+                                           numpy.uint32(nprnd(2**30/jobs)),
+                                           numpy.uint32(nprnd(2**30/jobs)))
       print "%s with (WorkItems/Threads)=(%i,%i) %s method done" % \
             (Alu,jobs,1,ParaStyle)
     elif ParaStyle=='Hybrid':
       threads=BestThreadsNumber(jobs)
       # en OpenCL, necessaire de mettre un Global_id identique au local_id
-      if DoublePrecision:
-        CLLaunch=MetropolisCL.MainLoopHybrid64(queue,(jobs,),(threads,),
-                                               circleCL,
-                                               numpy.uint64(iterationsCL),
-                                               numpy.uint32(nprnd(2**30/jobs)),
-                                               numpy.uint32(nprnd(2**30/jobs)))
-      else:
-        CLLaunch=MetropolisCL.MainLoopHybrid(queue,(jobs,),(threads,),
-                                             circleCL,
-                                             numpy.uint64(iterationsCL),
-                                             numpy.uint32(nprnd(2**30/jobs)),
-                                             numpy.uint32(nprnd(2**30/jobs)))
+      CLLaunch=MetropolisCL.MainLoopHybrid(queue,(jobs,),(threads,),
+                                          circleCL,
+                                          numpy.uint64(iterationsCL),
+                                          numpy.uint32(nprnd(2**30/jobs)),
+                                          numpy.uint32(nprnd(2**30/jobs)))
         
       print "%s with (WorkItems/Threads)=(%i,%i) %s method done" % \
             (Alu,jobs/threads,threads,ParaStyle)
     else:
       # en OpenCL, necessaire de mettre un Global_id identique au local_id
-      if DoublePrecision:
-        CLLaunch=MetropolisCL.MainLoopLocal64(queue,(jobs,),(jobs,),
-                                              circleCL,
-                                              numpy.uint64(iterationsCL),
-                                              numpy.uint32(nprnd(2**30/jobs)),
-                                              numpy.uint32(nprnd(2**30/jobs)))
-      else:
-        CLLaunch=MetropolisCL.MainLoopLocal(queue,(jobs,),(jobs,),
-                                            circleCL,
-                                            numpy.uint64(iterationsCL),
-                                            numpy.uint32(nprnd(2**30/jobs)),
-                                            numpy.uint32(nprnd(2**30/jobs)))
+      CLLaunch=MetropolisCL.MainLoopLocal(queue,(jobs,),(jobs,),
+                                          circleCL,
+                                          numpy.uint64(iterationsCL),
+                                          numpy.uint32(nprnd(2**30/jobs)),
+                                          numpy.uint32(nprnd(2**30/jobs)))
       print "%s with %i %s done" % (Alu,jobs,ParaStyle)
 
     CLLaunch.wait()
@@ -796,8 +693,6 @@
   Curves=False
   # Fit is True to print the curves
   Fit=False
-  # DoublePrecision on FP calculus
-  DoublePrecision=False
   # Marsaglia RNG
   RNG='KISS'
   # Value type : INT32, INT64, FP32, FP64
@@ -821,7 +716,7 @@
         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,deviceType,device.name.lstrip())
+            print "Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip())
             Id=Id+1
 
         print
@@ -832,8 +727,6 @@
     elif opt == '-o':
       OutMetrology=True
       Metrology='OutMetro'
-    elif opt == '-l':
-      DoublePrecision=True
     elif opt == '-c':
       Curves=True
     elif opt == '-f':
@@ -878,7 +771,6 @@
   print "Number of threads on end : %s" % JobEnd
   print "Number of redo : %s" % Redo
   print "Metrology done out of CPU/GPU : %r" % OutMetrology
-  print "Double Precision in Kernels : %r" % DoublePrecision
   print "Type of Marsaglia RNG used : %s" % RNG
   print "Type of variable : %s" % ValueType
 
@@ -900,7 +792,8 @@
       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)
+          print "Device #%i from %s of type %s : %s" % (Id,platform.vendor.lstrip(),deviceType,device.name.lstrip())
+
           if Id == Device:
             # Set the Alu as detected Device Type
             Alu=deviceType
@@ -927,14 +820,13 @@
         start=time.time()
         if GpuStyle=='CUDA':
           try:
-            a,m,s=MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle,
-                                 DoublePrecision)
+            a,m,s=MetropolisCuda(circle,Iterations,1,Jobs,ParaStyle)
           except:
             print "Problem with %i // computations on Cuda" % Jobs
         elif GpuStyle=='OpenCL':
           try:
             a,m,s=MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,
-                                   Alu,Device,DoublePrecision,RNG,ValueType)
+                                   Alu,Device,RNG,ValueType)
           except:
             print "Problem with %i // computations on OpenCL" % Jobs            
         duration=numpy.append(duration,time.time()-start)
@@ -947,14 +839,13 @@
     else:
       if GpuStyle=='CUDA':
         try:
-          avg,med,std=MetropolisCuda(circle,Iterations,Redo,Jobs,ParaStyle,
-                                     DoublePrecision)
+          avg,med,std=MetropolisCuda(circle,Iterations,Redo,Jobs,ParaStyle)
         except:
           print "Problem with %i // computations on Cuda" % Jobs
       elif GpuStyle=='OpenCL':
         try:
           avg,med,std=MetropolisOpenCL(circle,Iterations,Redo,Jobs,ParaStyle,
-                                       Alu,Device,DoublePrecision,RNG,ValueType)
+                                       Alu,Device,RNG,ValueType)
         except:
           print "Problem with %i // computations on OpenCL" % Jobs            
 
@@ -966,14 +857,10 @@
     else:
       print "Values seem to be wrong..."
     #THREADS*=2
-    if DoublePrecision:
-      Precision='DP'
-    else:
-      Precision='SP'
     if len(average)!=0:
-      numpy.savez("Pi%s_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Precision,Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
+      numpy.savez("Pi%s_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (ValueType,Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),(ExploredJobs,average,median,stddev))
       ToSave=[ ExploredJobs,average,median,stddev ]
-      numpy.savetxt("Pi%s_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (Precision,Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),numpy.transpose(ToSave))
+      numpy.savetxt("Pi%s_%s_%s_%s_%s_%i_%.8i_Device%i_%s_%s" % (ValueType,Alu,GpuStyle,ParaStyle,JobStart,JobEnd,Iterations,Device,Metrology,gethostname()),numpy.transpose(ToSave))
     Jobs+=JobStep
 
   if Fit:
