This is the mail archive of the fortran@gcc.gnu.org mailing list for the GNU Fortran project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: New sanity test for cpu_time() intrinsic function


Hi Uttam,

Uttam Pawar wrote:
> 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.

Since we're testing our implementation, it should be an error.

>    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

As the loop will probably (well, hopefully) be optimized away, you might as
well do without the loop, and just call cpu_time a second time.

- Tobi


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]