[MPi-C++]
I made an application that under a specific condition it should close the application in all processes. I tried to made it using root process but I want to send message to all other processes to terminate also. How can I make this???
[MPi-C++]
I made an application that under a specific condition it should close the application in all processes. I tried to made it using root process but I want to send message to all other processes to terminate also. How can I make this???
There is no way to quit an MPI application cleanly on all processes without communication. That means, if you have a condition that occurs only on a subset of the processes of your MPI application (e.g. you have an error on one of processes), the only way to unilaterally quit the application is to call MPI_Abort
. This will result in all MPI processes coming to an abrupt end, no matter where in the code each rank was at that moment. Since MPI_Abort
is not a collective routine, it is not possible to perform any cleanup on any of the other ranks.
If you wish to have a clean exit, you need to regularly communicate between all ranks whether everything is still working on all ranks, or if it is time to quit. For example, you could regularly call MPI_Allreduce
with MPI_SUM
as the operation. If your exit condition is fulfilled on a process, make it send 1
as the data, otherwise make it send 0
. Now you only need to check after the MPI_Allreduce
if the sum is larger than 0
, and if it is, quit your application in an orderly fashion.