Commits

Remi Meier committed 34b85e9

add manual transaction breaks

  • Participants
  • Parent commits 32ea48a

Comments (0)

Files changed (3)

     while True:
         time.sleep(0.2)
         if not args.q:
-            print "Run {}/{}".format(k, args.k)
+            print "Run {}/{}:".format(k, args.k)
 
         test_time = time.time()
         if args.p:
                 test.run(*args.more)
         times.append(time.time() - test_time)
 
+        if not args.q:
+            print "took {} s".format(times[-1])
+            
         if k >= args.k:
             if within_error(args, times):
                 break

common/abstract_threading.py

 
 
 import multiprocessing
-_thread_pool = ThreadPool(2 * multiprocessing.cpu_count())
+_thread_pool = ThreadPool(3 * multiprocessing.cpu_count())
 
 
 

raytrace/raytrace.py

 import time
 
 AMBIENT = 0.1
-GAMMA_CORRECTION = 1/2.2
 
 
-class Vector:
+
+class Vector(object):
     def __init__(self,x,y,z):
         self.x = x
         self.y = y
         return (self.y*b.z-self.z*b.y, self.z*b.x-self.x*b.z, self.x*b.y-self.y*b.x)
 
     def magnitude(self):
-        return sqrt(self.x**2+self.y**2+self.z**2)
+        return sqrt(self.x*self.x+self.y*self.y+self.z*self.z)
 
     def normal(self):
         mag = self.magnitude()
         return Vector(self.x-b.x, self.y-b.y, self.z-b.z)
 
     def __mul__(self, b):
-        assert type(b) == float or type(b) == int
+        #assert type(b) == float or type(b) == int
         return Vector(self.x*b, self.y*b, self.z*b)
 
 
-class Sphere:
+class Sphere(object):
     def __init__(self, center, radius, color):
         self.c = center
         self.r = radius
         return (b - self.c).normal()
 
 
-class Plane:
+class Plane(object):
     def __init__(self, point, normal, color):
         self.n = normal
         self.p = point
             return Intersection(l.o+l.d*d, d, self.n, self)
 
 
-class Ray:
+class Ray(object):
     def __init__(self, origin, direction):
         self.o = origin
         self.d = direction
 
 
-class Intersection:
+class Intersection(object):
     def __init__(self, point, distance, normal, obj):
         self.p = point
         self.d = distance
     return col
 
 
-def gammaCorrection(color,factor):
-    return (int(pow(color.x/255.0,factor)*255),
-            int(pow(color.y/255.0,factor)*255),
-            int(pow(color.z/255.0,factor)*255))
-
 
 tasks = 0
 def task(x, h, cameraPos, objs, lightSource):
+    # force a transaction break here (STM not yet smart enough
+    # to figure out that it should break here)
+    time.sleep(0)
+    
     with atomic:
         for y in range(h):
             ray = Ray(cameraPos,
 
     # force a transaction break. updating a global var should
     # be done in a separate transaction:
-    time.sleep(0.0)
+    time.sleep(0)
     
     global tasks
     with atomic:
         tasks -= 1
+    time.sleep(0)
 
 futures = []
 def future_dispatcher(ths, *args):
+    global tasks
+    
     while tasks >= ths:
-        time.sleep(0.0)
+        time.sleep(0)
 
-    global tasks
     with atomic:
         tasks += 1
+    
     futures.append(Future(task, *args))
+    time.sleep(0)
 
 
 
 
-def run(ths=2, w=600, h=600):
+def run(ths=8, w=1024, h=1024):
     ths = int(ths)
     w = int(w)
     h = int(h)
     for f in futures:
         f()
     del futures[:]
-
+    assert tasks == 0
 
 
 if __name__ == '__main__':