为 Python 程序分配多个内核 [英] Assigning Multiple Cores to a Python Program

查看:23
本文介绍了为 Python 程序分配多个内核的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我注意到,当我运行高度依赖 CPU 的 Python 程序时,它只使用一个内核.程序运行时可以分配多个内核吗?

I notice when I run my heavily CPU dependant python programs, it only uses a single core. Is it possible to assign multiple cores to the program when I run it?

推荐答案

您必须为多核显式编程.有关 Python 中的许多并行处理解决方案,请参阅本页上的对称多处理选项.并行 Python 是一个不错的选择,如果您不想比较选项,请查看示例 此处.

You have to program explicitly for multiple cores. See the Symmetric Multiprocessing options on this page for the many parallel processing solutions in Python. Parallel Python is a good choice if you can't be bothered to compare the options, look at the examples here.

不过,有些问题无法利用多核.想想如何在三个朋友的帮助下更快地跑上楼梯.不会发生!

Some problems can't take advantage of multiple cores though. Think about how you could possibly run up the stairs faster with the help of three friends. Not going to happen!

这篇关于为 Python 程序分配多个内核的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆