In in order to link libm
you need to add -lm
argument, as this document; MPI under Linux in the Math Department says:
If your code includes mathematical functions (like exp, cos, etc.),
you need to link to the mathematics library libm.so. This is done,
just like for serial compiling, by adding -lm to the end of your
compile command, that is,mpicc -o sample sample.c -lm