Difference between clock() and MPI_Wtime()
Asked Answered
A

2

6

Quick Question . for MPI implementation of my code ,i am getting a huge difference in both. I know MPI_Wtime is the real time elapsed by each processor and clock() gives a rough idea of the expected time . Do anyone wants to add some assertion ?

Anaglyph answered 27/6, 2013 at 17:32 Comment(0)
H
5

The clock function is utterly useless. It measures cpu time, not real time/wall time, and moreover it has the following serious issues:

  1. On most implementations, the resolution is extremely bad, for example, 1/100 of a second. CLOCKS_PER_SECOND is not the resolution, just the scale.

  2. With typical values of CLOCKS_PER_SECOND (Unix standards require it to be 1 million, for example), clock will overflow in a matter of minutes on 32-bit systems. After overflow, it returns -1.

  3. Most historical implementations don't actually return -1 on overflow, as the C standard requires, but instead wrap. As clock_t is usually a signed type, attempting to perform arithmetic with the wrapped values will produce either meaningless results or undefined behavior.

  4. On Windows it does the completely wrong thing and measures elapsed real time, rather than cpu time.

Heinz answered 27/6, 2013 at 17:54 Comment(5)
Thanks for the answer .I need to measure the overall time of the MPI program(surely it will be different form each MPI_Wtime()) . Profiling doesn't seems good to me as it is not taking significant time also it is detecting some other functions coming from the MPI implementation .Any idea how i can do this ?Anaglyph
I think , at the last i can make call to MPI_Barrier(MPI_COMM_WORLD) and after this i can note any of MPI_Wtime() as the overall execution time (this will work as rate determining step) or literally speaking it will be maximum from all MPI_Wtime() .Please verify me !Anaglyph
I'm not familiar with MPI, but a quick check of the documentation reveals that MPI_Wtime returns real time, not cpu time. The phrase "on the calling processor" is rather misleading; it doesn't seem to have anything to do with cpu time, but rather allows for the possibility that different cores may have slightly different ideas of what the current real time is. This discrepancy should not exist on high-quality systems, however.Heinz
Here is the document I was looking at: mcs.anl.gov/research/projects/mpi/www/www3/MPI_Wtime.htmlHeinz
Thanks for taking interest . I did same as mentioned before and i almost got the same time (which i would say , real aggregate time) from all process and since i am also interested to know the waiting time (if it is their due to time sharing : in reality there is only 1 process gets executed ,only they changes very frequently ) , it served my purpose .Anaglyph
K
3

The official definition of clock is that it gives you CPU-time. In Windows, for hysterical historical reasons - it would break some apps if you change it to reflect CPU-time now - on Windows, the time is just elapsed time.

MPI_Wtime gives, as you say, the "current time on this processor", which is quite different. If you do something that sleeps for 1 minute, MPI_Wtime will move 60 seconds forward, where clock (except for Windows) would be pretty much unchanged.

Kenakenaf answered 27/6, 2013 at 17:57 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.