Norwegian Service Centre for Climate Modelling -> SGI optimisation -> Optimising a**b in f77 on SGI Origin3800
Optimising a**b in f77 on SGI Origin3800
By Arild Burud
IntroductionThis is an extension to the earlier report "Optimising a modified ccm3.2 climate model" by Arild Burud and Egil Støren
We have further investigated the use of math power functions and the effect of compiler options on this feature in fortran programs.
This brief report summarizes the methods and findings.
Description of testsA small fortran program was written with heavy use of the pow() function, and in such a way that the equation could not be deleted by optimisation. The basic form of the routine is as follows:
program powtest real x1,a x1 = 0.1 a = 1.0 do i1=1,50000000 x1 = x1 + a**2.001 a = a + 0.000000013914 enddo write (6,*) x1,a stop end
The program line "x1 = x1 + a**2.001" was then modified to test different calculations and the effect of compiler optimisation flags.
The purpose was to find the most effective way to program such equations.
In investigating the generated machine code, several strategies are involved by the compiler. Each strategy is dependant of the optimisation level chosen.
Results of testsA rough timing test was performed on these expressions, the results are shown below, as time to run each test:
Primary conclusion is that testing is important in order to achieve highest performance.
Brute force use of the compiler optimisation, with -Ofast, is the best solution, if the program allows it.
Always write power equations with the exponent as integer,
when possible (
If high optimisation is not possible, expand power equations into
multiplications by hand (
Use -lfastm (optimised math library) when the highest accuracy is not necessary.
Send comments to webmaster