c++cprocessmpi

how to sleep in MPI


I'm building a C program using MPI, simulating some traffic lights. I need for each process to wait for a few seconds then send a message to the other traffic light (process) to change. If I use Sleep(), the program crashes. Is there a safe way to make a process sleep for a given number of seconds?


Solution

  • You can simulate your own sleep() function by using MPI_WTIME() and manually waiting for the amount of time you need. Depending on how you're executing (number of cores, nodes, etc.) this might not have any performance hit and gives you the added benefit of being able to do something else while you're waiting for the next light cycle.