简体   繁体   English

我可以在 MPI 进程中使用 `std::this_thread::sleep_for()` 吗?

[英]Can I use `std::this_thread::sleep_for()` with an MPI process?

MPI runs my program with multiple processes. MPI 使用多个进程运行我的程序。

I'd one of these processes to sleep for a while so that it's using minimal CPU.我让这些进程之一休眠一段时间,以便它使用最少的 CPU。

std::this_thread::sleep_for() looks like what I want, but that thread bit looks a little sketchy in this context. std::this_thread::sleep_for()看起来像我想要的,但在这种情况下,该thread看起来有点粗略。

Is it okay to do this?这样做可以吗?

This is perfectly OK to do - nothing should crash or hang as a result of it.这是完全可以的 - 不会因此而崩溃或挂起。

However, your "so that it's using minimal CPU" is a little worrying.但是,您的“以便它使用最少的 CPU”有点令人担忧。 Are you running more MPI processes than you have hardware threads available to execute them?您运行的 MPI 进程是否多于可用于执行它们的硬件线程? That sort of oversubscription is generally terrible for performance, and should be avoided.这种超额订阅通常对性能来说很糟糕,应该避免。 Best performance is often seen with one fewer process per hardware node than the number of hardware threads it offers, to allow system processes someplace to run without pre-empting the application.最好的性能通常是每个硬件节点的进程比它提供的硬件线程数少一个,以允许系统进程在某个地方运行而无需抢占应用程序。

The case where this could be well-justified (on which I just published a paper ) is if you have a section of your program where you have less parallelism than you have processes.这可能是合理的(我刚刚发表了一篇论文)的情况是,如果您的程序部分中的并行性比进程少。 If you're running on Intel CPUs with Turbo Boost, then having the idle processes actually sleep can allow the core(s) running the working process(es) to run at a higher clock speed.如果您在带有 Turbo Boost 的 Intel CPU 上运行,那么让空闲进程实际上处于睡眠状态可以让运行工作进程的内核以更高的时钟速度运行。

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

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