PHYS 580   COMPUTATIONAL PHYSICS  SPRING 2005

Redirection of input and output

It is often useful to "redirect" output from a program to a file rather than to a screen

executable > outputfile

Note that overwrites outputfile.  To concatenate (add to the end) of an existing file,

executable >> outputfile

 This will give an error if outputfile does not already exist. Note: While useful, the prompts are all written  to outputfile  so you have to remember what to input and in what order! 

Equally useful is to write an input script inputfile  which can be easily edited (especially if you have many numbers to input and only change one at a time):

executable < inputfile

These can be combined

executable < inputfile > outputfile

 

TIMING

For simple timing of program use the   time command

time executable < inputfile > outputfile

You should get back something that looks like

9.0u  6.7s  0:30  18%

which means that the program spent 9.0 seconds on behalf of the user, 6.7 second on behalf of the system, and a total of 30 seconds elapsed time (wall clock time), and only 18% of the CPU was used for the program.

INBUILT TIMING 

Different implementations of fortran have different inbuilt timing calls. For example, on GNU-based fortran such as gfortran, the call cpu_time ( time )  call gives times. Here is an example of its use. I find it works under gfortran on linux machines, and under f95 (but not f77) on rohan.

Other examples: arrayspeed.f     arrayskip.f    (useful for demonstrating locality in accessing arrays)

 ADVANCED TIMING

There exist advanced tools to see how much time different parts of your code uses. A common tool on Unix machines such as rohan and sciences (but is compiler dependent)  is prof or gprof

To use prof you must compile with the switch (-p for f77):

f77 o spe.x p speedeigen.f eiglib.f ranlib.f

You then run spe.x as usual; in addition to any output files, you will find a file mon.out

Afterwords, then do

prof spe.x

which will provide a simple timing profile that looks something like this:

%Time Seconds Cumsecs  #Calls   msec/call  Name

  59.8    6.68    6.68       1   6680.      tqli_

  38.9    4.34   11.02       1   4340.      tred2_

   0.4    0.04   11.06  223019      0.0002  pythag_

   0.3    0.03   11.09  125250      0.0002  gaussvar_

   0.3    0.03   11.12  375750      0.0001  ran3_

A generalization of prof is gprof: which uses the flag (in Intel ifort) -pg

ifort o spe.x pg speedeigen.f eiglib.f ranlib.f

Running spe.x will produce a file gmon.out

Afterwords,  do

gprof spe.x

to produce a report similar to the above.

Sample codes:

eigensolvers:

(Numerical Recipes)  speedeigen.f     eiglib.f  ranlib.f

(LAPACK)  speedeigenlapack.f  lapackeig.f  ranlib.f

(Numerical recipes in C)  speedeigen.c  tred2.c tqli.c  nrutil.h  ranlib.c

Matrix-multiplication:  speedmult.f   ranlib.f

For some additional information on performance tools, go to (note some of these apply only to Livermore computers, but others are more general) http://www.llnl.gov/computing/tutorials/performance_tools/

Another performance tool, which is very powerful but has a steep learning curve, is TAU: http://www.cs.uoregon.edu/research/tau/home.php

 

 

-

Last modified Oct 19, 2006