我用14个内核调用pool.apply_async()。pool.apply_async需要很长时间才能完成,如何加快速度?
import multiprocessing
from time import time
import timeit
informative_patients = informative_patients_2500_end[20:]
pool = multiprocessing.Pool(14)
results = []
wLength = [20,30,50]
start = time()
for fn in informative_patients:
result = pool.apply_async(compute_features_test_set, args = (fn,
wLength), callback=results.append)
pool.close()
pool.join()
stop = timeit.default_timer()
print stop - start
的问题是它完成调用用于第一13个数据compute_features_test_set()函数在不到一小时,但它需要一个多小时以完成最后一个。所有14个数据集的数据大小都是相同的。我试着在pool.close()之后放置pool.terminate(),但在这种情况下,它甚至不会启动池并立即终止池,而无需进入for循环。这总是以同样的方式发生,如果我使用更多的内核和更多的数据集,总是最后一个需要很长时间才能完成。我的compute_features_test_set()函数是一个简单的特征提取代码,并且可以正常工作。我在Linux red hat 6,python 2.7和jupyter上工作。计算时间对我来说很重要,我的问题是这里出了什么问题,以及我如何修复它以在合理的时间内完成所有计算?
你有多少**真正的核心**? 'informative_parients'的大小有多大? – stovfl
我想我在我工作的服务器上有32个真正的核心。 informative_parients只有14个患者ID,我在任何患者ID的for循环中称我的特征提取功能。因此,informative_parients是一个由14个字符串组成的数组,每个字符串的长度为8.我使用患者ID为每个患者收集信息,作为我的特征提取功能的输入。 – nightrain