Provided that an MPI implementation meets the requirements above, it is possible for the implementor of the profiling system to intercept the MPI calls that are made by the user program. The profiling system implementor can then collect any required information before calling the underlying MPI implementation (through its name shifted entry points) to achieve the desired effects.
Example
A wrapper to accumulate the total amount of data sent by the
MPI_SEND function, along with the total elapsed time spent in
the function.
static int totalBytes = 0; static double totalTime = 0.0; int MPI_Send(const void* buffer, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) { double tstart = MPI_Wtime(); /* Pass on all arguments */ int size; int result = PMPI_Send(buffer, count, datatype, dest, tag, comm); totalTime += MPI_Wtime() - tstart; /* Compute time */ MPI_Type_size(datatype, &size); /* and size */ totalBytes += count*size; return result; }