Find the answer to your Linux question:
Results 1 to 4 of 4
Hello, I have a fortran code, which I run on a multi-user Linux server. Since there are multiple users working on this server, I want to know, How much cpu ...
  1. #1
    Just Joined!
    Join Date
    Dec 2011
    Posts
    1

    Question How to compute CPU time for a particular process?

    Hello,

    I have a fortran code, which I run on a multi-user Linux server. Since there are multiple users working on this server, I want to know, How much cpu time does my application takes to complete? Although I am able to calculate CPU clock time, I also need to know the total CPU time required for entire simulation to get completed. Is there any command or code, with help of which this can be achieved?

    Thanks

    Regards
    Rakesh Patil

  2. #2
    Linux Newbie
    Join Date
    Dec 2009
    Posts
    241
    Hi rakeshp,

    Don't know if it helps you.
    When I wanna know the process time of a process I use the bash command "ps -ef" it will list all processes with their start time, used cpu time, PID, Parent PID and so on.

    Don't know if there's a fortran code for it.

  3. #3
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    See man time. The time command runs commands for you and produces 3 times, like so (with bash):
    Code:
    time burn 10
    producing:
    Code:
    real	0m10.727s
    user	0m9.877s
    sys	0m0.000s
    The burn is a (local) example, you can use almost any command in its place. So if you compile your Fortran code and have the final executable on file a.out, then you would use:
    Code:
    time ./a.out
    If you are using a csh family shell, the name, time, is the same , but output differs in format:
    Code:
    time burn 10
    9.868u 0.004s 0:10.53 93.6%	0+0k 0+0io 0pf+0w
    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

  4. #4
    drl
    drl is offline
    Linux Engineer drl's Avatar
    Join Date
    Apr 2006
    Location
    Saint Paul, MN, USA / CentOS, Debian, Solaris, SuSE
    Posts
    1,117
    Hi.

    If you wanted to time sections of your code in modern Fortran, say Fortran-90, you could use some standard library routines, such as cpu_time on file one.f90:
    Code:
         program main
           real :: my_sum, t1, t2, harvest(1000000)
           write(6,*) " Hello, world from fortran."
           call cpu_time(t1)
           call random_number(harvest)
           my_sum = sum ( harvest )
           call cpu_time(t2)
           call a( t2-t1 )
         end
         subroutine a ( t )
           real :: t
           write(6,*) " The time taken for code is ", t
           write(6,fmt="(a,f6.2)") "  The time taken for code is ", t
           return
         end
    then using:
    Code:
    gfortran one.f90
    ./a.out
    produces:
    Code:
      Hello, world from fortran.
      The time taken for code is   3.60019989E-02
      The time taken for code is   0.04
    This was done in the context:
    Code:
    OS, ker|rel, machine: Linux, 2.6.26-2-amd64, x86_64
    Distribution        : Debian GNU/Linux 5.0.8 (lenny) 
    gfortran GNU Fortran (Debian 4.3.2-1.1) 4.3.2
    Example adapted from Modern Fortran Explained, Metcalf, et al, Oxford 2011, page 181.

    Best wishes ... cheers, drl
    Welcome - get the most out of the forum by reading forum basics and guidelines: click here.
    90% of questions can be answered by using man pages, Quick Search, Advanced Search, Google search, Wikipedia.
    We look forward to helping you with the challenge of the other 10%.
    ( Mn, 2.6.n, AMD-64 3000+, ASUS A8V Deluxe, 1 GB, SATA + IDE, Matrox G400 AGP )

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...