From 4beb9eb16b7da82bd32bf1086d8c336036bb19de Mon Sep 17 00:00:00 2001 From: sccolbert Date: Sun, 8 Nov 2009 05:39:02 +0100 Subject: [PATCH] added better logic to the thread dispatcher. --- scikits/image/io/_plugins/util.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/scikits/image/io/_plugins/util.py b/scikits/image/io/_plugins/util.py index 6d976deb..6ef1af48 100644 --- a/scikits/image/io/_plugins/util.py +++ b/scikits/image/io/_plugins/util.py @@ -193,12 +193,11 @@ class ThreadDispatch(object): self.cores = CPU_COUNT self.threads = [] self.chunks = [] - if self.cores == 2: - self.chunks.append((img[:, :(width/2), :], - stateimg[:, :(width/2), :])) - self.chunks.append((img[:, (width/2):, :], - stateimg[:, (width/2):, :])) - elif self.cores == 4: + + if self.cores == 1: + self.chunks.append((img, stateimg)) + + elif self.cores >= 4: self.chunks.append((img[:(height/2), :(width/2), :], stateimg[:(height/2), :(width/2), :])) self.chunks.append((img[:(height/2), (width/2):, :], @@ -207,8 +206,13 @@ class ThreadDispatch(object): stateimg[(height/2):, :(width/2), :])) self.chunks.append((img[(height/2):, (width/2):, :], stateimg[(height/2):, (width/2):, :])) + + # if they dont have 1, or 4 or more, 2 is good. else: - raise ValueError('Cant handle your weird machine') + self.chunks.append((img[:, :(width/2), :], + stateimg[:, :(width/2), :])) + self.chunks.append((img[:, (width/2):, :], + stateimg[:, (width/2):, :])) for i in range(self.cores): self.threads.append(ImgThread(func, self.chunks[i][0],