New sanity test for cpu_time() intrinsic function

Steve Kargl sgk@troutmask.apl.washington.edu
Tue Nov 15 01:20:00 GMT 2005


On Tue, Nov 15, 2005 at 12:57:09AM +0100, Tobias Schl?ter wrote:
> 
> 
> 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.

Our cpu_time will return -1 on architectures that do not
currently have a method for determining the time.  See
the code for one example.  You probably want

if (r1 < 0.) stop

> 
> 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.
> 

cpu_time may not have sufficient resolution.  Add a subroutine call.

   call foobar(i)

subroutine foobar(i)
  integer i
  j = i
end subroutine

-- 
Steve



More information about the Fortran mailing list