我正在做梯度下降(准确地说是 100 次迭代)。每个数据点可以并行分析,有50个数据点。由于我有 4 个内核,因此我使用multiprocessing.Pool
. 该程序的核心如下所示:
# Read the sgf files (total 50)
(intermediateBoards, finalizedBoards) = read_sgf_files()
# Create a pool of processes to analyze game boards in parallel with as
# many processes as number of cores
pool = Pool(processes=cpu_count())
# Initialize the parameter object
param = Param()
# maxItr = 100 iterations of gradient descent
for itr in range(maxItr):
args = []
# Prepare argument vector for each file
for i in range(len(intermediateBoards)):
args.append((intermediateBoards[i], finalizedBoards[i], param))
# 4 processes analyze 50 data points in parallel in each iteration of
# gradient descent
result = pool.map_async(train_go_crf_mcmc, args)
现在,我没有包含函数的定义train_go_crf
,但函数的第一行是打印语句。所以,当我执行这个函数时,打印语句应该被执行 100*50 次。但这不会发生。更重要的是,我得到不同数量的控制台输出不同的次数。
怎么了?