Index: Pi-GPU.py
===================================================================
--- Pi-GPU.py	(revision 71)
+++ Pi-GPU.py	(revision 72)
@@ -22,6 +22,9 @@
 import math
 from socket import gethostname
 
+Marsaglia={'CONG':0,'SHR3':1,'MWC':2,'KISS':3}
+Computing={'INT32':0,'INT64':1,'FP32':2,'FP64':3}
+
 # find prime factors of a number
 # Get for WWW :
 # http://pythonism.wordpress.com/2008/05/17/looking-at-factorisation-in-python/
@@ -77,6 +80,8 @@
 
 #define MWCfp MWC * 2.328306435454494e-10f
 #define KISSfp KISS * 2.328306435454494e-10f
+#define SHR3fp SHR3 * 2.328306435454494e-10f
+#define CONGfp CONG * 2.328306435454494e-10f
 
 __global__ void MainLoopBlocks(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
@@ -103,8 +108,8 @@
 
 __global__ void MainLoopThreads(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(threadIdx.x+1);
-   uint w=seed_w/(threadIdx.x+1);
+   uint z=seed_z+threadIdx.x;
+   uint w=seed_w+threadIdx.x;
 
    ulong total=0;
 
@@ -126,8 +131,8 @@
 
 __global__ void MainLoopHybrid(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(blockDim.x*blockIdx.x+threadIdx.x+1);
-   uint w=seed_w/(blockDim.x*blockIdx.x+threadIdx.x+1);
+   uint z=seed_z+(blockDim.x*blockIdx.x+threadIdx.x+1);
+   uint w=seed_w+(blockDim.x*blockIdx.x+threadIdx.x+1);
 
    ulong total=0;
 
@@ -149,8 +154,8 @@
 
 __global__ void MainLoopBlocks64(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(blockIdx.x+1);
-   uint w=seed_w/(blockIdx.x+1);
+   uint z=seed_z+blockIdx.x;
+   uint w=seed_w+blockIdx.x;
 
    ulong total=0;
 
@@ -172,8 +177,8 @@
 
 __global__ void MainLoopThreads64(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(threadIdx.x+1);
-   uint w=seed_w/(threadIdx.x+1);
+   uint z=seed_z+threadIdx.x;
+   uint w=seed_w+threadIdx.x;
 
    ulong total=0;
 
@@ -195,8 +200,8 @@
 
 __global__ void MainLoopHybrid64(ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(blockDim.x*blockIdx.x+threadIdx.x+1);
-   uint w=seed_w/(blockDim.x*blockIdx.x+threadIdx.x+1);
+   uint z=seed_z+blockDim.x*blockIdx.x+threadIdx.x;
+   uint w=seed_w+blockDim.x*blockIdx.x+threadIdx.x;
 
    ulong total=0;
 
@@ -218,11 +223,22 @@
 """
 
 KERNEL_CODE_OPENCL="""
+#define TCONG 0
+#define TSHR3 1
+#define TMWC 2
+#define TKISS 3
+
+#define TINT32 0
+#define TINT64 1
+#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)
+
 #define MWC   (znew+wnew)
 #define SHR3  (jsr=(jsr=(jsr=jsr^(jsr<<17))^(jsr>>13))^(jsr<<5))
 #define CONG  (jcong=69069*jcong+1234567)
@@ -230,23 +246,101 @@
 
 #define MWCfp MWC * 2.328306435454494e-10f
 #define KISSfp KISS * 2.328306435454494e-10f
+#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)
 {
+
+// Initialization of RNG numbers
+#if TRNG == TCONG
+   uint jcong=seed_z+get_global_id(0);
+#elif TRNG == TSHR3
+   uint jsr=seed_w+get_global_id(0);
+#elif TRNG == TMWC
    uint z=seed_z+get_global_id(0);
    uint w=seed_w+get_global_id(0);
+#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);
+#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
+#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
+#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
+      float x=KISSfp ;
+      float y=KISSfp ;
+#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 ;
+#endif
+#endif
 
       // Matching test
-      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
+      ulong inside=((x*x+y*y) <= THEONE) ? 1:0;
       total+=inside;
    }
+
    barrier(CLK_GLOBAL_MEM_FENCE);
    s[get_global_id(0)]=total;
       
@@ -460,7 +554,7 @@
 
 
 def MetropolisOpenCL(circle,iterations,steps,jobs,ParaStyle,Alu,Device,
-                     DoublePrecision):
+                     DoublePrecision,RNG,ValueType):
 	
   # Initialisation des variables en les CASTant correctement
     
@@ -507,8 +601,9 @@
 	
   circleCL = cl.Buffer(ctx, mf.WRITE_ONLY|mf.COPY_HOST_PTR,hostbuf=circle)
 
+  
   MetropolisCL = cl.Program(ctx,KERNEL_CODE_OPENCL).build( \
-    options = "-cl-mad-enable -cl-fast-relaxed-math")
+    options = "-cl-mad-enable -cl-fast-relaxed-math -DTRNG=%i -DTYPE=%s" % (Marsaglia[RNG],Computing[ValueType]))
 
   i=0
 
@@ -703,16 +798,20 @@
   Fit=False
   # DoublePrecision on FP calculus
   DoublePrecision=False
-
+  # Marsaglia RNG
+  RNG='KISS'
+  # Value type : INT32, INT64, FP32, FP64
+  ValueType='INT32'
+  
   try:
-    opts, args = getopt.getopt(sys.argv[1:],"hoclfa:g:p:i:s:e:t:r:d:",["alu=","gpustyle=","parastyle=","iterations=","jobstart=","jobend=","jobstep=","redo=","device="])
+    opts, args = getopt.getopt(sys.argv[1:],"hocfa:g:p:i:s:e:t:r:d:m:v:",["alu=","gpustyle=","parastyle=","iterations=","jobstart=","jobend=","jobstep=","redo=","device=","marsaglia=","valuetype="])
   except getopt.GetoptError:
-    print '%s -o (Out of Core Metrology) -c (Print Curves) -l (Double Precision) -f (Fit to Amdahl Law) -a <CPU/GPU/ACCELERATOR> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -t <JobStep> -r <RedoToImproveStats> ' % sys.argv[0]
+    print '%s -o (Out of Core Metrology) -c (Print Curves) -f (Fit to Amdahl Law) -a <CPU/GPU/ACCELERATOR> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -t <JobStep> -r <RedoToImproveStats> -m <SHR3/CONG/MWC/KISS> -v <INT32/INT64/FP32/FP64> ' % sys.argv[0]
     sys.exit(2)
     
   for opt, arg in opts:
     if opt == '-h':
-      print '%s -o (Out of Core Metrology) -c (Print Curves) -l (Double Precision) -f (Fit to Amdahl Law) -a <CPU/GPU/ACCELERATOR> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -t <JobStep> -r <RedoToImproveStats>' % sys.argv[0]
+      print '%s -o (Out of Core Metrology) -c (Print Curves) -f (Fit to Amdahl Law) -a <CPU/GPU/ACCELERATOR> -d <DeviceId> -g <CUDA/OpenCL> -p <Threads/Hybrid/Blocks> -i <Iterations> -s <JobStart> -e <JobEnd> -t <JobStep> -r <RedoToImproveStats> -m <SHR3/CONG/MWC/KISS> -v <INT32/INT64/FP32/FP64>' % sys.argv[0]
 
       print "\nInformations about devices detected under OpenCL:"
       # For PyOpenCL import
@@ -747,6 +846,10 @@
       GpuStyle = arg
     elif opt in ("-p", "--parastyle"):
       ParaStyle = arg
+    elif opt in ("-m", "--marsaglia"):
+      RNG = arg
+    elif opt in ("-v", "--valuetype"):
+      ValueType = arg
     elif opt in ("-i", "--iterations"):
       Iterations = numpy.uint64(arg)
     elif opt in ("-s", "--jobstart"):
@@ -776,6 +879,8 @@
   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
 
   if GpuStyle=='CUDA':
     try:
@@ -829,7 +934,7 @@
         elif GpuStyle=='OpenCL':
           try:
             a,m,s=MetropolisOpenCL(circle,Iterations,1,Jobs,ParaStyle,
-                                   Alu,Device,DoublePrecision)
+                                   Alu,Device,DoublePrecision,RNG,ValueType)
           except:
             print "Problem with %i // computations on OpenCL" % Jobs            
         duration=numpy.append(duration,time.time()-start)
@@ -848,7 +953,8 @@
           print "Problem with %i // computations on Cuda" % Jobs
       elif GpuStyle=='OpenCL':
         try:
-          avg,med,std=MetropolisOpenCL(circle,Iterations,Redo,Jobs,ParaStyle,Alu,Device,DoublePrecision)
+          avg,med,std=MetropolisOpenCL(circle,Iterations,Redo,Jobs,ParaStyle,
+                                       Alu,Device,DoublePrecision,RNG,ValueType)
         except:
           print "Problem with %i // computations on OpenCL" % Jobs            
 
