python用for循环执行并发,在Python 3.2中并行执行for循环

在Python 3.2环境下,对于一个从0到100的范围,想要并行执行for循环进行计算。尝试使用multiprocessing库,但遇到了PicklingError。解决方案是使用joblib库,它为简单的并行循环设计,可以更方便地实现多进程。例如,通过定义worker函数并结合delayed和Parallel,可以将for循环的内容并行化处理。
摘要由CSDN通过智能技术生成

I'm quite new to Python (using Python 3.2) and I have a question concerning parallelisation. I have a for-loop that I wish to execute in parallel using "multiprocessing" in Python 3.2:

def computation:

global output

for x in range(i,j):

localResult = ... #perform some computation as a function of i and j

output.append(localResult)

In total, I want to perform this computation for a range of i=0 to j=100. Thus I want to create a number of processes that each call the function "computation" with a subdomain of the total range. Any ideas of how do to this? Is there a better way than using multiprocessing?

More specific, I want to perform a domain decomposition and I have the following code:

from multiprocessing import Pool

class testModule:

def __init__(self):

self

def com

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值