简体   繁体   English

Python多处理谷歌计算引擎

[英]python multiprocessing google compute engine

I have a python script which I run on my old quad-core laptop through multiprocessing. 我有一个python脚本,可以通过多处理在旧的四核笔记本电脑上运行。 The simulation cannot be parallelised, I just run different instances of it on the different cores. 模拟不能并行化,我只是在不同的内核上运行模拟的不同实例。

I was considering renting some more powerful cpus on google compute engine. 我正在考虑在Google计算引擎上租用一些更强大的cpus。 Will I be able to use the same python multiprocessing script just with more cores available? 我是否可以仅在具有更多可用内核的情况下使用相同的python多处理脚本?

the script just calls a pool and then apply_async many times 该脚本只是调用一个池,然后多次应用apply_async

Yes it should be possible. 是的,应该有可能。 If you need access to multiple cores on the same instance, as an example the App Engine flexible runtime , which uses Compute Engine as the underlying VM, allows you to configure the number of cores available 如果您需要访问同一实例上的多个核心,例如,使用Compute Engine作为基础虚拟机的App Engine flexible运行时 ,您可以配置可用的核心数量

Multiprocessing works the same way on Google's VMs as on your local box (roughly...). 多重处理在Google VM上的工作方式与在本地机器上相同(大致...)。 In order to use all cores available on a box, do not pass processes argument to multiprocesing.Pool , like: 为了使用盒子上所有可用的核心,请勿将processes参数传递给multiprocesing.Pool ,例如:

pool = multiprocessing.Pool(processes=None)

This will make Python create a Pool with multiprocessing.cpu_count() number of processes, cpu_count usually being a number of cores. 这将使Python使用multiprocessing.cpu_count()个进程创建一个Poolcpu_count 通常是多个内核。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM