python pool.map需要几个小时才能运行而不响应

时间:2016-09-01 15:45:00

标签: python-2.7

我使用多处理库的pool.map使用jupyter notebook运行以下代码。但是,在没有任何响应的情有没有人遇到过同样的问题?或者知道如何解决它?谢谢!

import multiprocessing as mp
import math 
import numpy as np
def simulate_geometric_brownian_motion(p): 
    M, I = p 
    S0 = 100
    r = 0.05
    sigma = 0.2
    T = 1.0
    dt = T / M 
    paths = np.zeros((M+1, I)) 
    paths[0] = S0
    for t in range(1, M + 1):
        paths[t] = paths[t-1] * np.exp((r - 0.5 * sigma ** 2) * dt + sigma * math.sqrt(dt) * np.random.standard_normal(I))
    return paths

I = 10000
M = 50 
t = 20
from time import time
times = [] 
for w in range(1, 7):
    t0 = time() 
    pool = mp.Pool(processes=w) 
    result = pool.map(simulate_geometric_brownian_motion, t * [(M, I),])
    times.append(time() - t0) 

0 个答案:

没有答案