我有简单的 map-reduce 类型算法,我想在 python 中实现并利用多个核心。
我在某处读到,在 2.6 中使用本机线程模块的线程不使用多个内核。真的吗?
我什至使用 stackless python 实现了它,但是我遇到了奇怪的错误 [更新:快速搜索表明 stackless 不允许多个内核那么他们还有其他选择吗?
def Propagate(start,end):
print "running Thread with range: ",start,end
def maxVote(nLabels):
count = {}
maxList = []
maxCount = 0
for nLabel in nLabels:
if nLabel in count:
count[nLabel] += 1
else:
count[nLabel] = 1
#Check if the count is max
if count[nLabel] > maxCount:
maxCount = count[nLabel];
maxList = [nLabel,]
elif count[nLabel]==maxCount:
maxList.append(nLabel)
return random.choice(maxList)
for num in range(start,end):
node=MapList[num]
nLabels = [Label[k] for k in Adj[node]]
if (nLabels!=[]):
Label[node] = maxVote(nLabels)
else:
Label[node]=node
但是在上面的代码中,分配给标签的值,即字典中的更改丢失了。
上述传播函数用作 MicroThreads(即 TaskLets)的可调用函数