There is no principal difference between omp_get_wtime()
and MPI_WTIME
. Both are sub-second precision wall-clock timers that return the time elapsed since some point in the past. Both are also used the same way by calling them repeatedly and subtracting the values, e.g.:
double tmr = omp_get_wtime();
...
// routine to be timed
...
tmr = omp_get_wtime() - tmr;
// tmr now holds the elapsed time in seconds
or:
double tmr = MPI_Wtime();
...
// routine to be timed
...
tmr = MPI_Wtime() - tmr;
// tmr now holds the elapsed time in seconds
Both functions are local, e.g. they measure the time on the node where the calling code executes. MPI_WTIME
is allowed to be synchronised across all nodes, but few implementations do so. They should be pretty equal in all other respects and provide similar precision (and on most platforms both are usually implemented using the same OS-specific timer routines). There is absolutely no guarantee that both timers have the same reference point in the past, therefore one should not mix them, e.g. the following is not valid code:
double tmr = MPI_Wtime();
...
tmr = omp_get_wtime() - tmr;
// tmr now holds the elapsed time in seconds + possibly a constant difference
I would preferably use MPI_WTIME
for omp_get_wtime()
depends on having OpenMP enabled. If you allow for your program to compile both as pure MPI and as hybrid MPI+OpenMP, then it is a good idea to not have many (or any) calls to the OpenMP runtime library or you would have to provide stub implementations for the case when OpenMP is not enabled. Of course, a stub omp_get_wtime()
implementation for hybrid codes takes one preprocessor macro:
#define omp_get_wtime MPI_Wtime