The sample illustrates how to use common compiler options to quickly change application performance.
See Included Samples for other samples included with the compiler.
Source |
Locations | ||||
---|---|---|---|---|---|
init_sin.f90 |
|
The sample is a math program that integrates the absolute value of a sine curve for one cycle of 2 pi radians. The sample is used to illustrate performance differences in automatic optimization because of the relative complexity of the calculations involved.
The following figure shows the method used for calculation. The method successively adds the areas of rectangles with a height centered on the curve. As the number of rectangles increases (and the slice width decreases), the calculated area approaches four (4.0). The figure shows what is being calculated for 24 interior points and the first eight slices of a 25 interior point calculation.
Establish a performance baseline by compiling the source code without enabling optimizations.
Platform |
Example Commands |
---|---|
Linux and Mac OS |
ifort int_sin.f90 -O0 |
Windows |
ifort int_sin.f90 /Od |
The compiled program is located in the same directory as the source. Execute the program as follows:
Platform |
Example Commands |
---|---|
Linux and Mac OS |
./a.out |
Windows |
int_sin.exe |
The computed integral value nears or equals 4.0 for each calculation as the execution time consumed during each of the calculations generally increases with the number of interior points. The following sample output illustrates typical results:
Sample Output |
---|
Number
of |
Computed Integral | CPU Time = <output time> |
Note the time reported in the final line of the output: CPU Time = <output time>. Use this as the number for comparing subsequent runs.
The performance enhancement realized by using some of the optimization options of the compiler can be significant. Other options allow you to enhance operation or performance in different areas.
Compile the source file with the default optimization level (the example commands are equivalent):
Platform |
Example Commands |
---|---|
Linux and Mac OS |
ifort int_sin.f90 or ifort int_sin.f90 -O2 |
Windows |
ifort int_sin.f90 or ifort int_sin.f90 /O2 |
Execute the optimized program.
Platform |
Example Commands |
---|---|
Linux and Mac OS |
./a.out |
Windows |
int_sin.exe |
Compare the number of reported on the final line with the number you noted for the unoptimized program. Compile sources again using the following automatic optimization options. Use one option per compile.
Platform |
Suggested Options |
---|---|
Linux and Mac OS |
-O1 -O3 -fast |
Windows |
/O1 /O3 /fast |
You should notice a difference in executions times (reported as CPU Time), and in some cases executable file size, as you experiment with more, and less, aggressive optimization levels.
While the improvement in execution time (unoptimized to optimized program) in this sample application might not be typical for all programs, you should be able to improve the execution time for programs by compiling your sources using automatic optimization options.