New sanity test for cpu_time() intrinsic function

Uttam Pawar uttamp@us.ibm.com
Mon Nov 14 23:41:00 GMT 2005


Hi,

I've written following sanity test for cpu_time intrinsic, does it look ok?

$ cat test_cpu_time.f90
program test_cpu_time
   real r1, r2
   integer n

   n=0
   call cpu_time(r1)
   ! if (r1 .lt. 0) then according to f95 standard, it mean processor cannot return
   ! meaningful value. This is not an error but a valid case which can be ignored, I think.

   if (r1 .eq. 0) then
        do i=1,1000000      ! this loop is meaningless, as the loop will take
                            ! different amount of time depending upon processor
                            ! and the environment.
           n = n +1
        end do
        call cpu_time(r2)   ! The real test is that, the time r2 should be atleast
                            ! same as r1 or greater but can not be smaller than r1.
        if (r2.lt.r1) call abort()
   endif
end program test_cpu_time


Thanks for the feedback.

- Uttam



More information about the Fortran mailing list