Index: Pi-GPU.py
===================================================================
--- Pi-GPU.py	(revision 70)
+++ Pi-GPU.py	(revision 71)
@@ -44,7 +44,7 @@
   threads=1
   for factor in matrix.transpose().ravel():
     threads=threads*factor
-    if threads*threads>jobs:
+    if threads*threads>jobs or threads>512:
       break
   return(long(threads))
 
@@ -233,8 +233,8 @@
 
 __kernel void MainLoopGlobal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(get_global_id(0)+1);
-   uint w=seed_w/(get_global_id(0)+1);
+   uint z=seed_z+get_global_id(0);
+   uint w=seed_w+get_global_id(0);
 
    ulong total=0;
 
@@ -244,18 +244,18 @@
       float y=MWCfp ;
 
       // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
+      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
       total+=inside;
    }
+   barrier(CLK_GLOBAL_MEM_FENCE);
    s[get_global_id(0)]=total;
-   barrier(CLK_GLOBAL_MEM_FENCE);
       
 }
 
 __kernel void MainLoopLocal(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(get_local_id(0)+1);
-   uint w=seed_w/(get_local_id(0)+1);
+   uint z=seed_z+get_local_id(0);
+   uint w=seed_w+get_local_id(0);
 
    ulong total=0;
 
@@ -265,39 +265,40 @@
       float y=MWCfp ;
 
       // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
+      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
       total+=inside;
    }
+   barrier(CLK_LOCAL_MEM_FENCE);
    s[get_local_id(0)]=total;
-   barrier(CLK_LOCAL_MEM_FENCE);
       
 }
 
 __kernel void MainLoopHybrid(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
-   uint w=seed_w/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
+   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 ;
+      float y=MWCfp ;
 
       // Matching test
-      ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
+      ulong inside=((x*x+y*y) <= 1.0f) ? 1:0;
       total+=inside;
    }
-   barrier(CLK_LOCAL_MEM_FENCE);
-   s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
+   barrier(CLK_GLOBAL_MEM_FENCE || CLK_GLOBAL_MEM_FENCE);
+   // s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
+   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)+1);
-   uint w=seed_w/(get_global_id(0)+1);
+   uint z=seed_z+get_global_id(0);
+   uint w=seed_w+get_global_id(0);
 
    ulong total=0;
 
@@ -310,15 +311,15 @@
       ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
       total+=inside;
    }
+   barrier(CLK_GLOBAL_MEM_FENCE);
    s[get_global_id(0)]=total;
-   barrier(CLK_GLOBAL_MEM_FENCE);
       
 }
 
 __kernel void MainLoopLocal64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(get_local_id(0)+1);
-   uint w=seed_w/(get_local_id(0)+1);
+   uint z=seed_z+get_local_id(0);
+   uint w=seed_w+get_local_id(0);
 
    ulong total=0;
 
@@ -331,15 +332,15 @@
       ulong inside=((x*x+y*y) < 1.0f) ? 1:0;
       total+=inside;
    }
+   barrier(CLK_LOCAL_MEM_FENCE);
    s[get_local_id(0)]=total;
-   barrier(CLK_LOCAL_MEM_FENCE);
       
 }
 
 __kernel void MainLoopHybrid64(__global ulong *s,ulong iterations,uint seed_w,uint seed_z)
 {
-   uint z=seed_z/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
-   uint w=seed_w/(get_group_id(0)*get_num_groups(0)+get_local_id(0)+1);
+   uint z=seed_z+get_global_id(0);
+   uint w=seed_w+get_global_id(0);
 
    ulong total=0;
 
@@ -353,7 +354,7 @@
       total+=inside;
    }
    barrier(CLK_LOCAL_MEM_FENCE);
-   s[get_group_id(0)*get_num_groups(0)+get_local_id(0)]=total;
+   s[get_global_id(0)]=total;
       
 }
 """
@@ -584,6 +585,7 @@
 
     elapsed = 1e-9*(CLLaunch.profile.end - CLLaunch.profile.start)
 
+    print circle,numpy.mean(circle),numpy.median(circle),numpy.std(circle)
     MyDuration[i]=elapsed
     AllPi=4./numpy.float32(iterationsCL)*circle.astype(numpy.float32)
     MyPi[i]=numpy.median(AllPi)
