Intel® Fortran Compiler Classic and Intel® Fortran Compiler Developer Guide and Reference

ID 767251
Date 9/08/2022
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

PXFTIMES

POSIX Subroutine: Returns process times.

Module

USE IFPOSIX

CALL PXFTIMES (jtms,itime,ierror)

jtms

(Output) INTEGER(4). A handle of structure tms.

itime

(Output) INTEGER(4). The returned time since system startup.

ierror

(Output) INTEGER(4). The error status.

If successful, ierror is set to zero; otherwise, an error code.

The PXFTIMES subroutine fills the fields of structure tms associated with handle jtms with components of time that was spent by the current process. The structure fields are:

  • tms_utime - User CPU time

  • tms_stime - System CPU time

  • tms_cutime - User time of child process

  • tms_cstime - System time of child process

All members are measured in system clocks. The values can be converted to seconds by dividing by value ival returned from the following call:

 PXFSYSCONF(IPXFCONST('_SC_CLK_TCK'), ival, ierror)

User time is the time charged for the execution of user instructions of the calling process. System time is the time charged for execution by the system on behalf of the calling process.

NOTE:

To get a handle for an instance of the tms structure, use PXFSTRUCTCREATE with the string 'tms' for the structure name.

Example

program test_uname
  use ifposix
  implicit none
  integer(jhandle_size) jtms1, jtms2
  integer(4) ierror,i
  integer(4),parameter :: n=10000000
  integer(SIZEOF_CLOCK_T) itime,time1,time2, user_time1,user_time2
  integer(SIZEOF_CLOCK_T) system_time1,system_time2
  integer(4) clocks_per_sec, iname
  real(8) s, PI
  real(8) seconds_user, seconds_system

  print *,"Create a first instance for structure 'tms'"
  call PXFSTRUCTCREATE("tms",jtms1,ierror)
  if(ierror.NE.0) STOP 'Error: cannot create structure for handle jtms1'
  print *,"Create a second instance for structure 'tms'"
  call PXFSTRUCTCREATE("tms",jtms2,ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     STOP 'Error: cannot create structure for handle jtms2'
  end if

  print *, 'Do some calculations'
  call PXFTIMES(jtms1, itime,ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     call PXFSTRUCTFREE(jtms2,ierror)
     STOP 'Error: the first call of PXFTIMES fails'
  end if
  call PXFTIME(time1, ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     call PXFSTRUCTFREE(jtms2,ierror)
     STOP 'Error: the first call of PXFTIME fails'
  end if

  s = 0._8
  PI = atan(1._8)*4
  do i=0, n
    s = s + cos(i*PI/n)*sin(i*PI/n)
  end do
  print *," s=",s

  call PXFTIMES(jtms2, itime,ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     call PXFSTRUCTFREE(jtms2,ierror)
     STOP 'Error: the second call of PXFTIMES fails'
  end if
  call PXFTIME(time2, ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     call PXFSTRUCTFREE(jtms2,ierror)
     STOP 'Error: the second call of PXFTIME fails'
  end if
!DIR$ IF DEFINED(_M_INNN)
     call PXFINT8GET(jtms1,"tms_utime",user_time1,ierror)
     call PXFINT8GET(jtms1,"tms_stime",system_time1,ierror)
     call PXFINT8GET(jtms2,"tms_utime",user_time2,ierror)
     call PXFINT8GET(jtms2,"tms_stime",system_time2,ierror)
!DIR$ ELSE
     call PXFINTGET(jtms1,"tms_utime",user_time1,ierror)
     call PXFINTGET(jtms1,"tms_stime",system_time1,ierror)
     call PXFINTGET(jtms2,"tms_utime",user_time2,ierror)
     call PXFINTGET(jtms2,"tms_stime",system_time2,ierror)
!DIR$ ENDIF

  iname = IPXFCONST("_SC_CLK_TCK")
  call PXFSYSCONF(iname,clocks_per_sec, ierror)
  if(ierror.NE.0) then
     call PXFSTRUCTFREE(jtms1,ierror)
     call PXFSTRUCTFREE(jtms2,ierror)
     STOP 'Error: the call of PXFSYSCONF fails'
  end if

  seconds_user = (user_time2 - user_time1)/DBLE(clocks_per_sec)
  seconds_system = (system_time2 - system_time1)/DBLE(clocks_per_sec)
  print *," The processor time of calculations:"
  print *," User code execution(in seconds):", seconds_user
  print *," Kernal code execution(in seconds):", seconds_system
  print *," Total processor time(in seconds):", seconds_user + seconds_system
  print *," Elapsed wall clock time(in seconds):", time2 - time1

  print *,"Free memory for instance of structure associated with jtms"
  call PXFSTRUCTFREE(jtms1,ierror)
  call PXFSTRUCTFREE(jtms2,ierror)
end program

See Also