optimize_test


optimize_test a FORTRAN77 code which demonstrates the use and benefits of the compiler's automatic optimization ability.

Most compilers have an option to "optimize" your code; that is, to spend some extra compilation time looking for ways to adjust your program so that it runs faster, while getting the same results.

By default, compiler optimization is not accessed. In GFORTRAN, you can request optimization by including the "-O#' option where '#' is a value between 0 (no optimization) and 3 (high optimization). Asking for a higher level of optimization may increase the compilation time somewhat, and occasionally, an optimization performed by the compiler might not be suitable for your program (in other words, it might make your program return different or incorrect results.) Thus, it's important to time your code before and after optimization, to see if it helps, and to check your results, to see if it hurts!

The molecular dynamics example program given here runs in about 93 seconds. After optimization at level 1, it runs in 39 seconds. Optimization level 2 or 3 brings the run time down to 14 seconds. These improvements come with not a single change to the source code.

Licensing:

The computer code and data files described and made available on this web page are distributed under the GNU LGPL license.

Languages:

optimize_test is available in a C version and a C++ version and a FORTRAN77 version and a FORTRAN90 version.

Related Data and Programs:

gprof, FORTRAN77 programs which illustrate the use of the GPROF program performance monitor;

md, a FORTRAN77 program which carries out a molecular dynamics simulation, intended as a starting point for implementing a parallel version.

TIMER, FORTRAN77 programs which demonstrate how to compute CPU time or elapsed time.

Source code:

MD is a molecular dynamics program.


Last revised on 30 October 2023.