Your `MPI_Reduce` call doesn't have a valid communicator specified. I think you left it out entirely. The place where you have `rank` should be the same value everywhere you call it, and it should be a communicator. From the look of your code, it should be `MPI_COMM_WORLD` since every rank is doing the operation.