Document number: 307056-001
Overview
Configuring the C++ Compiler
Before You Start
The Verification Source
File
Confirming Proper
Installation
Invoking the Compiler (Command Line)
Compiling with No
Optimization Options
Running/Verifying the
Compiled Program
Compiling with Optimization
Running/Comparing
Performance
Invoking the Compiler (Eclipse IDE)
Compiling with No
Optimization Options
Running/Verifying the
Compiled Program
Compiling with Optimization
Running/Comparing
Performance
Using the Compiler on Your Own
Useful Links
Disclaimer and Legal Information
The Intel® C++ Compiler 9.0 for Linux* systems uses either the command line or (for IA-32 only) an optional Eclipse-based integrated development environment (IDE) on a Linux* host system to compile C/C++ source files to run on Linux* platforms. Refer to the Intel(R) Software Development Products web site for more information about this product, and other Intel software development products.
Note: The default installation path for the IA-32 C++ compiler is
/opt/intel/cc/9.0. For the remainder of this guide,
the path /opt/intel/cc/9.0 will be indicated as <install-dir>.
(install.sh).
You need to also run the compiler environment script file
(iccvars.sh)
that
sets the environment variables. It is strongly recommended that you add this script file
into your login script (.login
for C shell or
.profile
for other shells). Once the variables are set
in the login script, there is no need to run the environment script
files for each session. The installation program also creates compiler configuration files named
<install-dir>/bin/icc.cfg
(C compiler) and
<install-dir>/bin/icpc.cfg
(C++ compiler) that contain common settings for
all compilations. You can edit these files to add additional default options.
Note: Once installed, you invoke the C compiler using icc on the command line, or you can invoke the C++ compiler using icpc on the command line.
Refer to the Installation Guide to confirm that the Intel C++ Compiler 9.0 for Linux has been properly configured.
Once you complete installation of the Intel C++ Compiler, it is useful to
perform a basic verification task that confirms proper installation,
configuration, and operation of the compiler. A verification source file
is provided at
<install-dir>/doc/samples/int_sin.c
as part of the compiler installation.
The verification source file is a math program that integrates the absolute value of a sine curve for one cycle of 2 pi radians. The following figure shows the method used for calculation. This 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 below shows what is being calculated for 24 interior points and the first eight slices of a 25 interior point calculation.
The program checks that Intel libraries have been installed because it includes the Intel math library in addition to stdio, stdlib, and time libraries. The timing function in the program returns the number of measured application clocks from the beginning to the end of program execution. This time measure is inexact and will vary somewhat depending on the processor and its workload.
You can confirm proper installation of the compiler by compiling the verification source, running the verification output file, and observing that the program output converges to the known correct value of 4. Perform the following steps to verify your installation:
<install-dir>/doc/samples
directory. Confirm that you
have write permission to the directory, change to
the directory, and run the compiler on the verification source file, as
follows:<install-dir>/doc/samples
directory with a file name
of a.out. The program requires no argument
. Execute the program as follows:
Number of | Computed Integral |
Interior Points | |
-------------------------------------
4 | 3.141593e+000 |
-------------------------------------
8 | 3.792238e+000 |
-------------------------------------
16 | 3.948463e+000 |
-------------------------------------
32 | 3.987141e+000 |
-------------------------------------
64 | 3.996787e+000 |
-------------------------------------
128 | 3.999197e+000 |
-------------------------------------
256 | 3.999799e+000 |
-------------------------------------
512 | 3.999950e+000 |
-------------------------------------
1024 | 3.999987e+000 |
-------------------------------------
2048 | 3.999997e+000 |
-------------------------------------
4096 | 3.999999e+000 |
-------------------------------------
8192 | 4.000000e+000 |
-------------------------------------
16384 | 4.000000e+000 |
-------------------------------------
32768 | 4.000000e+000 |
-------------------------------------
65536 | 4.000000e+000 |
-------------------------------------
131072 | 4.000000e+000 |
-------------------------------------
262144 | 4.000000e+000 |
-------------------------------------
524288 | 4.000000e+000 |
-------------------------------------
1048576 | 4.000000e+000 |
-------------------------------------
2097152 | 4.000000e+000 |
-------------------------------------
4194304 | 4.000000e+000 |
-------------------------------------
8388608 | 4.000000e+000 |
-------------------------------------
16777216 | 4.000000e+000 |
-------------------------------------
33554432 | 4.000000e+000 |
-------------------------------------
67108864 | 4.000000e+000 |
Application Clocks = 5.515000e+003
The Intel® C++ Compiler 9.0 for Linux* can be invoked from the Linux command line using icc (for C source files) or icpc (for C/C++ source files). Our example code is in ANSI C, so we will be using the icc invocation of the compiler. We will use the int_sin.c verification source file in order to get started using the compiler and become familiar with some of its features and options. If you will be using the IDE interface instead of the command line for most of your work, you can skip this section and go to the Invoking the Compiler (Eclipse IDE) section.
The int_sin.c verification source file is
located in the
<install-dir>/doc/
samples directory. Make sure you have write
privileges in this directory. Before starting this section,
open a shell window and change directory as follows:
prompt> cd
<install-dir>/doc/samples
We can establish a performance baseline by invoking the Intel C++ compiler without any optimization options. Invoke the Intel C compiler on the source as follows:
prompt> icc int_sin.c -O0
Alternatively, you could use the -g debug option, because that changes the default optimization from -O2 to -O0.
The compiled program is in the same directory as the source, with a standard
file name of a.out. Execute the program as follows:
prompt> ./a.out
The computed integral value nears or equals 4.0 for each calculation as the execution time (number of Application Clocks) consumed during each of the calculations generally increases with the number of interior points. The following example output is similar to the output you should see:
Number of | Computed Integral |
Interior Points | |
-------------------------------------
4 | 3.141593e+000 |
-------------------------------------
8 | 3.792238e+000 |
-------------------------------------
16 | 3.948463e+000 |
-------------------------------------
32 | 3.987141e+000 |
-------------------------------------
64 | 3.996787e+000 |
-------------------------------------
128 | 3.999197e+000 |
-------------------------------------
256 | 3.999799e+000 |
-------------------------------------
512 | 3.999950e+000 |
-------------------------------------
1024 | 3.999987e+000 |
-------------------------------------
2048 | 3.999997e+000 |
-------------------------------------
4096 | 3.999999e+000 |
-------------------------------------
8192 | 4.000000e+000 |
-------------------------------------
16384 | 4.000000e+000 |
-------------------------------------
32768 | 4.000000e+000 |
-------------------------------------
65536 | 4.000000e+000 |
-------------------------------------
131072 | 4.000000e+000 |
-------------------------------------
262144 | 4.000000e+000 |
-------------------------------------
524288 | 4.000000e+000 |
-------------------------------------
1048576 | 4.000000e+000 |
-------------------------------------
2097152 | 4.000000e+000 |
-------------------------------------
4194304 | 4.000000e+000 |
-------------------------------------
8388608 | 4.000000e+000 |
-------------------------------------
16777216 | 4.000000e+000 |
-------------------------------------
33554432 | 4.000000e+000 |
-------------------------------------
67108864 | 4.000000e+000 |
Application Clocks = 1.193700e+004
The performance enhancement realized by using some of the optimization options of the Intel C++ compiler can be quite significant. Other options allow you to enhance operation or performance in different areas. Invoke the compiler (with the default optimization) as follows:
prompt> icc int_sin.c
By default the compiler performs level 2 optimizations (-O2), which is intended to improve code execution speed.
Execute the optimized version of the compiled int_sin program as follows:
prompt> ./a.out
Compare the number of "Application Clocks" with the number you noted for the unoptimized program. Although the actual time differences you see might depend on the architecture of your target system, the following output is typical for an Intel® IA-32 system.
Number of | Computed Integral |
Interior Points | |
-------------------------------------
4 | 3.141593e+000 |
-------------------------------------
8 | 3.792238e+000 |
-------------------------------------
16 | 3.948463e+000 |
-------------------------------------
32 | 3.987141e+000 |
-------------------------------------
64 | 3.996787e+000 |
-------------------------------------
128 | 3.999197e+000 |
-------------------------------------
256 | 3.999799e+000 |
-------------------------------------
512 | 3.999950e+000 |
-------------------------------------
1024 | 3.999987e+000 |
-------------------------------------
2048 | 3.999997e+000 |
-------------------------------------
4096 | 3.999999e+000 |
-------------------------------------
8192 | 4.000000e+000 |
-------------------------------------
16384 | 4.000000e+000 |
-------------------------------------
32768 | 4.000000e+000 |
-------------------------------------
65536 | 4.000000e+000 |
-------------------------------------
131072 | 4.000000e+000 |
-------------------------------------
262144 | 4.000000e+000 |
-------------------------------------
524288 | 4.000000e+000 |
-------------------------------------
1048576 | 4.000000e+000 |
-------------------------------------
2097152 | 4.000000e+000 |
-------------------------------------
4194304 | 4.000000e+000 |
-------------------------------------
8388608 | 4.000000e+000 |
-------------------------------------
16777216 | 4.000000e+000 |
-------------------------------------
33554432 | 4.000000e+000 |
-------------------------------------
67108864 | 4.000000e+000 |
Application Clocks = 5.515000e+003
Note: While the large improvement in execution time (unoptimized to optimized program) in this example might not be typical for all programs, you should be able to improve the execution time for programs running on Intel processors by choosing to optimize your compiled output. Note also that the Intel C++ compiler optimizes programs at an -O2 level by default.
The Intel® C++ Compiler 9.0 for Linux* can be invoked from the Eclipse integrated development environment (IDE). Our example code is in ANSI C, so we will be using the icc invocation of the compiler within the IDE. We will use the int_sin.c verification source file in order to get started using the compiler and become familiar with some of its features and options. If you will be using the command line interface instead of the IDE for most of your work, you can follow the steps in the Invoking the Compiler (Command Line) section instead of those in this section. The following steps get you started:
We can establish a performance baseline by invoking the Intel C++ compiler with strict ANSI C compatibility and without any optimization options. This baseline is created by default in the Debug configuration. Perform the following steps:
Select the int_sin project in the Navigator
view, and then select Project > Properties and the C/C++ Build
property to display the
following screen:
Note: The Debug configuration is initially selected, which by default invokes the compiler and linker with the -O0 and -prefetch- options.
Perform the following steps:
Now we can recompile the program with optimization. Perform the following steps:
Perform the following steps:
You can vary the optimization settings and other options to judge their effects on program execution speed, on compilation time, and on compiled code size.
The procedures in this Getting Started guide show you how to compile, apply/remove optimization, provide arguments, and monitor the output of the example program. If you have an existing C/C++ source program, there should be no problem in substituting your source file for the example and running it.
The examples provided in this Getting Started guide are only an introduction to the capabilities of the Intel C++ compiler.
A Documentation Index file is available that provides links to all of the documentation included with the product. Refer to the doc_index.htm file.
Detailed information on the Intel C++ Compiler for Linux Systems is presented in the Intel® C++ Compiler documentation. This document is provided in an online Help format.
If you would like more in-depth training on Intel compilers, a Web-based
training tutorial on using Intel compilers for software development is included
with this product. Refer to
Enhancing Performance with Intel
Compilers located at:
<install-dir>/doc/training/optimize/index.htm
Refer to the product Release Notes document for information about Technical Support and any Limitations that apply to the product.
You can find out about other Intel software development products through the
Intel web site at:
http://www.intel.com/software/products/.
The information in this document is subject to change without notice and Intel Corporation assumes no responsibility or liability for any errors or inaccuracies that may appear in this document or any software that may be provided in association with this document. This document and the software described in it are furnished under license and may only be used or copied in accordance with the terms of the license. No license, express or implied, by estoppel or otherwise, to any intellectual property rights is granted by this document. The information in this document is provided in connection with Intel products and should not be construed as a commitment by Intel Corporation.
EXCEPT AS PROVIDED IN INTEL'S TERMS AND CONDITIONS OF SALE FOR SUCH PRODUCTS, INTEL ASSUMES NO LIABILITY WHATSOEVER, AND INTEL DISCLAIMS ANY EXPRESS OR IMPLIED WARRANTY, RELATING TO SALE AND/OR USE OF INTEL PRODUCTS INCLUDING LIABILITY OR WARRANTIES RELATING TO FITNESS FOR A PARTICULAR PURPOSE, MERCHANTABILITY, OR INFRINGEMENT OF ANY PATENT, COPYRIGHT OR OTHER INTELLECTUAL PROPERTY RIGHT. Intel products are not intended for use in medical, life saving, life sustaining, critical control or safety systems, or in nuclear facility applications.
Designers must not rely on the absence or characteristics of any features or instructions marked "reserved" or "undefined." Intel reserves these for future definition and shall have no responsibility whatsoever for conflicts or incompatibilities arising from future changes to them.
The software described in this document may contain software defects which may cause the product to deviate from published specifications. Current characterized software defects are available on request.
Intel, the Intel logo, Intel SpeedStep, Intel NetBurst, Intel NetStructure, MMX, Intel386, Intel486, Celeron, Intel Centrino, Intel Xeon, Intel XScale, Itanium, Pentium, Pentium II Xeon, Pentium III Xeon, Pentium M, and VTune are trademarks or registered trademarks of Intel Corporation or its subsidiaries in the United States and other countries.
* Other names and brands may be claimed as the property of others.
Copyright © 2005, Intel Corporation.