Fix mpi problem when terminating after finding NaN.
This fixes a bug causing the simulation to hang when only some of the mpi processes encounter a NaN.
This fixes a bug causing the simulation to hang when only some of the mpi processes encounter a NaN.