我的Python代码崩溃,出现以下错误:
Segmentation fault (core dumped)
我使用multiprocessing
对我稍后使用scipy.optimize.leastq
最小化的函数进行并列化我的代码如下:
import multiprocessing as mp
def myfunction(argss):
x, data1, data2 = argss
# evaluating the function at x with data1, data2 as arguments
def para_function(x, data1, data2, Npr)
step = int(Ndata/Npr)
argss = [(x, data1[i*step:(i+1)*step], data2[i*pas:(i+1)*step]) for i in range(Npr-1)]
argss.append((x, data1[(Npr-1)*step:], data2[(Npr-1)*step:]))
pool = mp.Pool(Npr)
results = pool.map(myfunction, argss)
pool.close()
pool.join()
# traiting results and returning the function value
然后我使用para_function()
最小化leastsq
。问题是我只在最小化的第三次迭代中得到错误!这意味着para_function
的前两个调用进展顺利,我只在第三次调用时遇到崩溃。我还发现错误发生在mp.Pool()
之前(当然是para_function()
的第三次调用),并且只有大量进程(Npr=40
)。
然后程序是:
from scipy.optimize import leastsq
x0 = np.zeros(N) #The initial guess with N is number of optimization parameters
x = leastsq(para_function, x0, args=(Data1, Data2))