| Clemson Home > CCIT Home | Skip Navigation | A-Z Index Calendar CU Safety Map Webcams Phonebook |
Compiling your code
The next step in using palmetto is to compile your code. As mentioned before, you have several compiler options. In this section we will give an overview of their features and some examples of how to use them.
General use
The compilers are all used in the form
<compiler name> [options] <filename.suffix>
where
| Component | Description |
|---|---|
| compiler name | is the command name associated with the compiler. |
| options | are optional parameters that allow you to direct the compiler toward various general or special features of the compiler, computer architecture, or library routines you are calling. |
| filename.suffix | is the file which contains your code. "suffix" will depend on the particular language and compiler version that you are using and will be covered in more detail with the specific compiler description. |
Common compiler options
Most compilers contain a set of standard compiler options. We will describe those here. Distribution specific options (or situations where the option values may vary) will be described in the respective compiler sections.
The following options appear with all compilers. They are specified as
-option value
| Option | Description |
|---|---|
| -o outfile | Place the executable in outfile. (Default: -o a.out) |
| -l library | Search the library (or list of libraries) for routines that are called. The listing order is important as it dictates the order of the search for routines. The option value is specified as library where liblibrary.a is the name of the library file as shown in /lib, /usr/lib, etc. (Default: -l f (the standard fortran library) |
| -g | Produce symbolic information in the executable or binaries. This is used primarily with debugging tools and may cause a drop in optimization. (Default: no symbolic information) |
| -L directory | Look in this directory for routines that are called before looking in the usual places or in the libraries specified on the -l option. (Default: none) |
| -O optlevel | Set the compiler optimization level to optlevel. (Default: vendor specific, see compiler sections) |
Standard compilers
We will call those compilers that come with the installation as "the standard compilers". They include
fort77 - This is the interface to the Fortran 77 compiler. A simple compilation is performed with
fort77 -o pade pade.f
where the source code is found in "pade.f" (with extension .f). The executable is placed in file "pade". See man fort77 for more information.
c99 - This is the interface to the C 99 compiler. A simple compilation is performed with
c99 -o transit transit.c
where the source code is found in "transit.c" (with extension .c). The executable is placed in file "transit". See man c99 for more information.
GNU (GNU's not Unix) is an operating system composed of entirely free software. It is Unix-like but it is free and contains no Unix code. (See GNU - Wikipedia, the free encyclopedia for history and information.) The basic components include the GNU Compiler Collection (GCC), the GNU Binary Utilities (binutils), the bash shell, the GNU C library (glibc), and GNU Core Utilities (coreutils). The GNU compilers are used widely and therefore we make them available to you on palmetto.
The GNU compilers include a large number of options (and suboptions of those options) which we cannot cover here. The GNU Option Summary - Using the GNU Compiler Collection (GCC) gives a good overview by category for the C and C++ compilers. The Using and Porting GNU Fortran gives a good overview by category for Fortran. We include several options here to get you started.
Please note that there are several versions of the GNU compilers available on palmetto. (Enter module avail gcc for a list.) When using the AMD processors, be sure to include version 4.3.2 of the compilers by specifying
module add gcc/4.3.2
before your compilation.
The GNU compilers are invoked with
g77 - the GNU project Fortran 77 compiler.
g77 -o pade pade.f
gfortran - the GNU Fortran 95 compiler.
gfortran -o atmdyno atmdyno.f95
gcc - the GNU project C and C++ compiler.
gcc -o transit transit.c
gcc -o hydro hydro.cpp
gcc -march=barcelona -o hydro hydro.cpp (if using the AMD processors)
A simple, starting compilation would be
gcc -o transit -O<n> transit.c
where the O<n> can include the optimization levels
Level Description -O1 The compiler tries to reduce code size and execution time, without performing any optimizations that take a great deal of compilation time. -O2 The compiler performs nearly all supported optimizations that do not involve a space-speed trade-off. The compiler does not perform loop unrolling or function inlining when you specify -O2. -O3 The compiler turns on all optimizations specified by -O2 and also turns on the -finline-functions, -funswitch-loops and -fgcse-after-reload options. -Os The compiler enables all -O2 optimizations that do not typically increase code size. It also performs further optimizations designed to reduce code size.
As the name implies, the Intel compilers have been built to accelerate software performance on Intel processors. A review of
module avail
will show the version(s) of Intel compilers available to you. The compilers are invoked with
ifort - preprocess, compile, assemble, and link Fortran programs on systems using IA-32 architecture, systems using Intel 64 architecture, and systems using IA-64 architecture. A simple, starting compilation is performed withifort -O2 -ipo -ftz -fp-model precise -o pade pade.f
where the source code is in "pade.f" (extensions can be .f, .for, .ftn, .f90, or .fpp depending on Fortran version and compiling phase) and the executable will go to "pade". The options are
Option Description -O2 Default optimization: enables optimizations for speed, including global code scheduling, software pipelining, predication, and speculation, inlining of intrinsics, intra-file interprocedural analysis, and other capabilities. -ipo Enables multifile interprocedural analysis. -ftz Flushes denormal results to zero when the application is in the gradual underflow mode. -fp-model precise Enables value-safe optimizations on floating-point data and rounds intermediate results to source-defined precision. Similarly, the next step is
ifort -fast -o pade pade.f
where -fast includes
Component Description -ipo Enables multifile interprocedural analysis. -O3 Enables -O2 optimizations plus more aggressive optimizations, such as prefetching, scalar replacement, and loop transformations. Enables optimizations for maximum speed, but does not guarantee higher performance unless loop and memory access transformations take place. -static Causes library routines to be linked statically. See man ifort for detailed explanations of these options.
icc - preprocess, compile, assemble, and link C and C++ programs on IA-32 architectures, Intel 64 architectures, and IA-64 architectures. A simple, starting compilation is performed withicc -O2 -ipo -ftz -fp-model precise -o fourier fourier.c
where the source code is in "fourier.c" (with extension of .c, .C, .cc, .cpp, .cxx, or .i depending on C version and compiling phase) and the executable will go to "fourier". The options are
Option Description -O2 Default optimization: optimize for code speed. This is the generally recommended optimization level. -ipo Enables multifile interprocedural analysis. -ftz Flushes denormal results to zero. The option only causes denormals generated at runtime to be flushed to zero. -fp-model precise Enables value-safe optimizations on floating-point data. The next step for compilation would be to try
icc -fast -o fourier -o fourier.c
where -fast includes
Component Description -ipo Enables multifile interprocedural analysis. -O3 Enable -O2 optimizations and in addition, enable more aggressive optimizations such as loop and memory access transformation, and prefetching. The -O3 option optimizes for maximum speed, but may not improve performance for some programs and may slow down code in some cases compared to -O2 optimizations. -O3 is recommended for applications that have loops with heavy use of floating point calculations and process large data sets. -static Causes library routines to be linked statically. See man icc for detailed explanations of these options.
MPI compilers
The MPI compilers are used to compile code that has been implemented with calls to the message passing procedures and subroutines for parallelism within the MPI specifications. There are four MPI compilers: mpicc, mpiCC (C++), mpif77, and mpif90. All are called simply as in
mpicc -o transport transport.c
where the source code is in "transport.c" and the executable will go "transport". For more information see the associated man pages.
Resources
Option Summary - Using the GNU Compiler Collection (GCC)
Using and Porting GNU Fortran
Inside the Intel® Compiler
Quick-Reference Guide to Optimization with Intel® Compilers
Intel® C++ Compiler Documentation
Intel® Fortran Compiler Documentation
- Login to post comments
