page 1  (22 pages)
2to next section

You and Your Compiler Keith H. Bierman February 20, 1991 Page 1/22

You and Your Compiler

(the handout)

1.0 Preface

Compilers are like dentists ? everyone needs them, but the experience is seldom completely pleasant! First one must get the compiler to accept your source ? then debug the results ? then make it go fast.

For the purposes of this handout

we will concentrate on the last activity, making your code execute quickly. One should be very careful to get the right answers first ? getting the wrong answer quickly is easy (via. simply print 42), but not challenging enough.

The examples in the following sections happen to be Fortran programs and program fragments (Fortran codes are often old enough to be correct :>), the techniques highlighted are not language specific and the lessons apply to SunC, Pascal and Modula.

2.0 The algorithm

For many applications (especially small ones) it is sufficient to simply turn on the optimizer and all is wonderful; the answers are correct, the compilation speed is acceptable, and the execution speed is just fine.

For large applications more work is typically necessary. Basically we apply the scientific method iteratively:

1. Break the code into separate files?.

2. Make sure you are getting the right answers.

3. Compile and link with profiling enabled.

4. Execute for some typical dataset.

5. Generate profile report.

6. Turn up optimization on the most expensive routines.

7. Go to step #2 until happiness is maximized.

?. Actually, we may wind up packing key modules into a single file. See the discussion below.