Fixed gradient in MPI version