问题
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