import multiprocessing
def function(x):
return(x * x)
arg_list = [1, 3, 5, 7]
cores = multiprocessing.cpu_count()
pool = multiprocessing.Pool(processes=cores)
for result in pool.imap(function, arg_list):
print(result)
这样定义好了函数和参数列表,就可以轻松进行CPU多核并行运算。
最后
以上就是健康鲜花最近收集整理的关于使用CPU多核进行并行运算的全部内容,更多相关使用CPU多核进行并行运算内容请搜索靠谱客的其他文章。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复