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

纵饮孤独 提交于 2019-12-11 13:27:13

问题


MPI runs my program with multiple processes.

I'd one of these processes to sleep for a while so that it's using minimal CPU.

std::this_thread::sleep_for() looks like what I want, but that thread bit looks a little sketchy in this context.

Is it okay to do this?


回答1:


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. Are you running more MPI processes than you have hardware threads available to execute them? 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.



来源:https://stackoverflow.com/questions/37062120/can-i-use-stdthis-threadsleep-for-with-an-mpi-process

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!