This is very easy with the MPICH implementation of MPI. Simply replace -lmpi with -llmpi -lpmpi -lm in the link line for your program, and relink your program. You do not need to recompile.
On some systems, you can get a real-time animation by using the libraries -lampi -lmpe -lm -lX11 -lpmpi.
Alternately, you can use the -mpilog or -mpianim options to the mpicc or mpif77 commands.