The difference between the clock () and MPI_Wtime ()

Quick question. to implement the MPI of my code, I get a huge difference in both. I know that MPI_Wtime is the time elapsed by each processor, and clock () gives an approximate idea of ​​the expected time. Anyone want to add some kind of statement?

+4
source share
2 answers

The clock function is completely useless. It measures the processor time, not the real-time / wall time, and, in addition, it has the following serious problems:

  • In most implementations, the resolution is very poor, for example, 1/100 of a second. CLOCKS_PER_SECOND is not permission, just a scale.

  • With typical CLOCKS_PER_SECOND values ​​(for example, for Unix standards this should be 1 million), the clock will overflow for several minutes on 32-bit systems. After overflow, -1 is returned.

  • Most historical implementations do not actually return -1 on overflow, as the C standard requires, but wrap instead. Since clock_t usually a signed type, trying to do arithmetic with wrapped values ​​will result in either meaningless results or undefined behavior.

  • On Windows, it does a completely wrong thing and measures elapsed real time, not processor time.

+3
source

The official definition of clock is that it gives you processor time. On Windows, for historical reasons, hysterical - this will break some applications, if you change them to reflect the CPU time now - on Windows, time is running out.

MPI_Wtime gives, as you say, "current time on this processor", which is completely different. If you do something that sleeps for 1 minute, MPI_Wtime will move 60 seconds ahead, where the clock (except Windows) will practically not change.

+3
source

Source: https://habr.com/ru/post/1488553/


All Articles