Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/18.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 利用并行计算减少序列计算时间_Python_Python 3.x_Parallel Processing - Fatal编程技术网

Python 利用并行计算减少序列计算时间

Python 利用并行计算减少序列计算时间,python,python-3.x,parallel-processing,Python,Python 3.x,Parallel Processing,我试图减少计算时间,但我不知道怎么做。我认为这叫做并行计算 在我的代码中,我计算了835只股票19个周期的指数移动平均(ema)值。每个股票有3个时间框架,即日、周和月 stock_names = [835 names] ema_periods = [5, 10, 11, 12, 13, 14, 15, 16, 20, 25, 30, 35, 40, 45, 50, 75, 90, 100, 200] ema_day = dict() ema_week = dict() ema_month =

我试图减少计算时间,但我不知道怎么做。我认为这叫做并行计算

在我的代码中,我计算了835只股票19个周期的指数移动平均(ema)值。每个股票有3个时间框架,即日、周和月

stock_names = [835 names]
ema_periods = [5, 10, 11, 12, 13, 14, 15, 16, 20, 25, 30, 35, 40, 45, 50, 75, 90, 100, 200]
ema_day = dict()
ema_week = dict()
ema_month = dict()

elapsed_time = 0

for name in stock_names:
    stock_data_day = get_data(name, 'day', 0, 0)
    stock_data_week = get_data(name, 'week', 0, 0)
    stock_data_month = get_data(name, 'month', 0, 0)

    start = time.time()
    for periods in ema_periods:
        ema_day[periods] = ema(stock_data_day['close'], periods)
        ema_week[periods] = ema(stock_data_week['close'], periods)
        ema_month[periods] = ema(stock_data_month['close'], periods)
    end = time.time()
    elapsed_time = elapsed_time + (end - start)

print('time : ', elapsed_time )
输出:

>>> time :  3.693106174468994
我想得到如何缩短时间的建议。我需要按ema周期划分为19个流程,或按时间段划分为3个流程,或两者兼而有之。我支持使用的图书馆。或者一些例子来阅读和尝试。 因为我必须使用ema来计算一些东西,比如两个ema周期的交叉

谢谢。

你确定
ema(…)
是瓶颈吗。在并行化某些东西之前,您最好知道应该在多个内核上运行哪段代码。这是并行计算的良好开端。