Many scientific computing programs, including those using MPI, are coded in Fortran. PMPI wrappers coded in C can be used with these Fortran codes, but it’s a bit complicated because Fortran is case-sensitive and sometimes function names contain underscores not present in the C-equivalent. So a program might use mpi_send or __mpi_send, neither of which would be caught by a C-wrapper of MPI_Send. Luckily, there is a tool for generating all the needed permutations called wrap.py.
wrap.py works by using a meta-language used to build appropriate C-functions for PMPI wrappers.
To wrap MPI_Send as we did in the last PMPI tutorial, you create a file like this:
#include <mpi.h>
{{fn func MPI_Send}}{
double start, end;
start = MPI_Wtime();
{{callfn}}
end = MPI_Wtime();
printf("MPI_Send took %f seconds.\n", end - start);
}{{endfn}}
In other words, we want to wrap the function MPI_Send. We’re going to call the functions MPI_Wtime and printf with the normal syntax for a C program. And we’re going to call the PMPI_Send in between the MPI_Wtime calls. If I also wanted to wrap MPI_Recv, I just change the first line of the block to {{fn func MPI_Send MPI_Recv}} You can also wrap all MPI functions EXCEPT for the functions specified.
To generate the C wrapper, do this:
$ ./wrap.py -g -f -o testwrap.c testwrap.w
Then compile and create a shared library in the usual way:
$ mpicc -c testwrap.c -fPIC
$ gcc -shared -o libwrapmpi.so testwrap.o
This will create a wrapper library that will work for Fortran MPI programs as well as C MPI programs.