简体   繁体   中英

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

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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