diff --git a/devito/mpi/distributed.py b/devito/mpi/distributed.py index e5e1475fbc..5d488d35b7 100644 --- a/devito/mpi/distributed.py +++ b/devito/mpi/distributed.py @@ -367,11 +367,11 @@ def neighborhood(self): # Set up diagonal neighbours for i in product([LEFT, CENTER, RIGHT], repeat=self.ndim): neighbor = [c + s.val for c, s in zip(self.mycoords, i)] - try: - ret[i] = self.comm.Get_cart_rank(neighbor) - except: - # Fallback for MPI ranks at the grid boundary + + if any(c < 0 or c >= s for c, s in zip(neighbor, self.topology)): ret[i] = MPI.PROC_NULL + else: + ret[i] = self.comm.Get_cart_rank(neighbor) return ret