[pypy-commit] benchmarks default: some fixes
Raemi
noreply at buildbot.pypy.org
Thu Apr 10 15:42:23 CEST 2014
Author: Remi Meier <remi.meier at inf.ethz.ch>
Branch:
Changeset: r249:034f0a5a1032
Date: 2014-04-10 15:43 +0200
http://bitbucket.org/pypy/benchmarks/changeset/034f0a5a1032/
Log: some fixes
diff --git a/multithread/btree/btree.py b/multithread/btree/btree.py
--- a/multithread/btree/btree.py
+++ b/multithread/btree/btree.py
@@ -1,6 +1,6 @@
# https://github.com/MartinThoma/algorithms/tree/master/datastructures
-from common.abstract_threading import atomic, Future
+from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool
import time, threading
import random
@@ -330,6 +330,7 @@
threads = int(threads)
operations = int(operations)
+ set_thread_pool(ThreadPool(threads))
thread_local.rnd = random
tree = BTree(20)
diff --git a/multithread/common/abstract_threading.py b/multithread/common/abstract_threading.py
--- a/multithread/common/abstract_threading.py
+++ b/multithread/common/abstract_threading.py
@@ -28,9 +28,10 @@
class ThreadPool(object):
- def __init__(self):
+ def __init__(self, n_workers=None):
self.input_queue = Queue()
- n_workers = getsegmentlimit()
+ if n_workers is None:
+ n_workers = getsegmentlimit()
self.workers = [Worker(self.input_queue) for i in range(n_workers)]
def add_task(self, func, *args, **kwds):
@@ -46,6 +47,9 @@
_thread_pool = ThreadPool()
atexit.register(_thread_pool.shutdown)
+def set_thread_pool(th):
+ global _thread_pool
+ _thread_pool = th
class Future(object):
diff --git a/multithread/raytrace/raytrace.py b/multithread/raytrace/raytrace.py
--- a/multithread/raytrace/raytrace.py
+++ b/multithread/raytrace/raytrace.py
@@ -2,7 +2,7 @@
# Date: 14.03.2013
from math import sqrt, pow, pi
-from common.abstract_threading import atomic, Future
+from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool
import time
AMBIENT = 0.1
@@ -133,6 +133,8 @@
(Vector(x/50.0-5,y/50.0-5,0)-cameraPos).normal())
trace(ray, objs, lightSource, 10)
time.sleep(0) # XXX
+ return x
+
futures = []
def future_dispatcher(ths, *args):
@@ -146,6 +148,7 @@
w = int(w)
h = int(h)
+ set_thread_pool(ThreadPool(ths))
objs = []
objs.append(Sphere( Vector(-2,0,-10), 2, Vector(0,255,0)))
objs.append(Sphere( Vector(2,0,-10), 3.5, Vector(255,0,0)))
@@ -154,12 +157,12 @@
lightSource = Vector(0,10,0)
cameraPos = Vector(0,0,20)
-
+
for x in range(w):
future_dispatcher(ths, x, h, cameraPos, objs, lightSource)
for f in futures:
- f()
+ print f()
del futures[:]
diff --git a/multithread/skiplist/skiplist.py b/multithread/skiplist/skiplist.py
--- a/multithread/skiplist/skiplist.py
+++ b/multithread/skiplist/skiplist.py
@@ -1,6 +1,6 @@
# https://github.com/kunigami/blog-examples/tree/master/2012-09-23-skip-list
-from common.abstract_threading import atomic, Future
+from common.abstract_threading import atomic, Future, set_thread_pool, ThreadPool
import time, threading
import random
@@ -87,7 +87,6 @@
OPS = [SkipList.find] * 98 + [SkipList.insert, SkipList.remove]
-
def task(id, slist, ops):
print "start task with %s ops" % ops
r = random.Random()
@@ -114,6 +113,7 @@
threads = int(threads)
operations = int(operations)
+ set_thread_pool(ThreadPool(threads))
thread_local.rnd = random
slist = SkipList()
More information about the pypy-commit
mailing list