我目前正在使用Python的多进程来进行一些简单的并行编程。我使用了一个async装饰器。
def async(decorated):
module = getmodule(decorated)
decorated.__name__ += '_original'
setattr(module, decorated.__name__, decorated)
def send(*args, **opts):
return async.pool.apply_async(decorated, args, opts)
return send
然后
@async
def evalfunc(uid, start, end):
veckernel(Posx, Posy, Posz, Quant, Delta)
return (uid, GridVal)
def runit(outdir):
async.pool = Pool(8)
results = []
for uid in range(8):
result = evalfunc(uid,Chunks[uid], Chunks[uid+1])
results.append(result)
如果我在一台有8个处理器或8个核心的机器上运行它,它基本上只使用了两个核心。为什么会这样?有没有像使用pthread时那样进行适当的核心绑定的方法?
谢谢, 马克