MPI_WTIME(3)

πŸ’– NAME πŸ’–

MPI_Wtime β€” returns an elapsed time on the calling processor. that's it, that's the whole function, it's a stopwatch bestie 🫢 this page lives in the Open MPI manual set, so if you typed man MPI_Wtime and landed here, you're exactly where you're supposed to be.


✨ SYNTAX ✨

C Syntax

#include <mpi.h>

double MPI_Wtime()

Fortran Syntax

USE MPI
! or the older form: INCLUDE 'mpif.h'
DOUBLE PRECISION MPI_WTIME()

Fortran 2008 Syntax

USE mpi_f08
DOUBLE PRECISION MPI_WTIME()

πŸŽ€ RETURN VALUE πŸŽ€

Time in seconds since an arbitrary time in the past. yeah. arbitrary. it's not midnight, it's not the epoch, it's just some moment, and you only ever use it by subtracting two of them πŸ™ˆ


🌸 DESCRIPTION 🌸

MPI_Wtime hands you back a floating-point number of seconds β€” elapsed wall-clock time since some time in the past. like a stopwatch that started at a mystery moment and never told you which one πŸ•°οΈ

That "time in the past" is guaranteed not to change during the life of the process</>, so your deltas stay honest. But converting giant piles of seconds into other units (minutes, hours, "how long is this build gonna take", whatever) is on you β€” the function is not doing that math, bestie.

The whole point of this function is that it's:

  • portable β€” it returns seconds, not "ticks", so your numbers mean something everywhere
  • high resolution, no cap
  • and it carries no unnecessary baggage. iconic behavior honestly πŸ’…

you'd use it like this:

{
   double starttime, endtime;
   starttime = MPI_Wtime();
    ....  stuff to be timed  ...
   endtime   = MPI_Wtime();
   printf("That took %f seconds\n",endtime-starttime);
}

the times you get back are local to the node that called them. there is no requirement that different nodes return the "same" time. so yes, node A and node B can just. disagree. and that's legal 😭 don't do math across nodes assuming they match, okay?


πŸ‘‘ NOTES πŸ‘‘

The boolean variable MPI_WTIME_IS_GLOBAL β€” a predefined attribute key that's supposed to tell you whether clocks are synchronized β€” does not have a valid value in Open MPI, because the clocks are not guaranteed to be synchronized. so like. don't trust it. it's giving empty promise πŸ’€

This function is meant to be a high-resolution, elapsed (or wall) clock. to figure out the resolution of MPI_Wtime, go see MPI_Wtick.

On POSIX platforms, this function may use a timer that's cheaper to invoke than the gettimeofday() system call β€” but it'll fall back to gettimeofday() if a cheap high-resolution timer isn't available. you can consult the ompi_info(1) command to see whether Open MPI supports a native high-resolution timer on your platform. look for the value of β€œMPI_Wtime support” (or β€œoptions:mpi-wtime” when you're looking at the parsable output). if that value is β€œnative”, then a method that's likely cheaper than gettimeofday() is what's grabbing the time when MPI_Wtime gets invoked πŸ”₯

for example, on platforms that support it, the clock_gettime() function will be used to get a monotonic clock value with whatever precision that platform supports (e.g., nanoseconds ✨).

also worth knowing: the MCA parameter opal_timer_require_monotonic can influence this behavior. it defaults to true, but if you set it to false, Open MPI may use a finer-grained timing mechanism (e.g., the RDTSC/RDTSCP clock ticks on x86_64 platforms) β€” but that is not guaranteed to be monotonic in some cases, for example if the MPI process is not bound to a single processor core. ask yourself if you really want that tradeoff, bestie πŸ‘€

⚠️ This function does not return an error value. Consequently, the result of calling it before MPI_Init or after MPI_Finalize is undefined. like, undefined undefined. no error, no warning, just vibes. don't do it πŸ™ˆ

See also:

  • MPI_Wtick

2003-2026, The Open MPI Community


and that's the whole page, bestie β€” you now know more about wall-clock timing than like 90% of people πŸ¦‹ this was the MPI_WTIME(3) page, part of the Open MPI manual, dated Sep 10, 2026. go time something. slay. periodt πŸ’…βœ¨

πŸ“¦ where this page comes from