并行化初始边界值问题(有限差分)

Parallellizing Intial-boundary value problem (Finite difference)

我是运行模拟求解平流扩散方程。我希望并行化计算偏导数的代码部分,以加快计算速度。这是我正在做的事情:

p1 = np.zeros((len(r), len(th)-1 ))  #The solution of the matrix

def func(i):
    pti = np.zeros(len(th)-1)
    for j in range (len(pti)):    

        abc = f(p1)  #Some function calculating the derivatives at each point
        pti[j] = p1[i][j] + dt*( abc )  #dt is some small float number

    return pti

#Setting the initial condition of the p1 matrix
for i in range(len(p1[:,0])):
    for j in range(len(p1[0])):


        p1[i][j] = 0.01

#Final loop calculating the integral by finite difference scheme

p = Pool(args.cores)
for k in range (0,args.iterations):  #This is integration in time


    p1=p.map(func,range(len(r)))   


print (p1)

我在这里面临的问题是我的 p1 矩阵在 k 中的每次迭代后都没有更新。最后,当我打印 p1 时,我得到了与初始化相同的矩阵。

此外,此代码的线性版本可以正常工作(但需要太长时间)。

好的,我自己解决了这个问题。显然把行

p = Pool(args.cores)

循环内部

for k in range (0,args.iterations):

成功了。