Development/Intel Compiler: Difference between revisions
No edit summary |
|||
Line 37: | Line 37: | ||
The following compiler commands work for all the compilers in the list above even though the examples will be for icc only. When ex.c is a C source code file such as |
The following compiler commands work for all the compilers in the list above even though the examples will be for icc only. When ex.c is a C source code file such as |
||
<source lang=C> |
<source lang=C style="font: normal normal 2em monospace"> |
||
#include <stdio.h> |
#include <stdio.h> |
||
int main() { |
int main() { |
||
Line 65: | Line 65: | ||
{| border="1" style="margin:5px;border-collapse:collapse" |
{| border="1" style="margin:5px;border-collapse:collapse" |
||
|- |
|- |
||
|style="padding:3px"| icc |
|||
| icc |
|||
| Intel C compiler |
|style="padding:3px"| Intel C compiler |
||
|- |
|- |
||
| icpc |
|style="padding:3px"| icpc |
||
| Intel C++ compiler |
|style="padding:3px"| Intel C++ compiler |
||
|- |
|- |
||
| ifort |
|style="padding:3px"| ifort |
||
| Intel Fortran compiler |
|style="padding:3px"| Intel Fortran compiler |
||
|- |
|- |
||
|style="padding:3px"| idb |
|||
| idb |
|||
| Intel debugger in GUI mode |
|style="padding:3px"| Intel debugger in GUI mode |
||
|- |
|- |
||
| idbc |
|style="padding:3px"| idbc |
||
| Intel debugger in console mode |
|style="padding:3px"| Intel debugger in console mode |
||
|} |
|} |
||
Line 105: | Line 105: | ||
'''Optimizations:''' You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is |
'''Optimizations:''' You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is |
||
<pre>$ icc -xHost -O2 ex.c</pre> |
<pre>$ icc -xHost -O2 ex.c</pre> |
||
There are more aggressive optimization flags but the compiled programs can get quite large |
There are more aggressive optimization flags but the compiled programs can get quite large. Moreover it can happen that the so compiled program is even slower. Such a command would be for example |
||
<pre>$ icc -fast ex.c</pre> |
<pre>$ icc -fast ex.c</pre> |
||
A tutorial on optimization can be found at http://download-software.intel.com/sites/default/files/article/301481/compiler-essentials.1.pdf |
A tutorial on optimization can be found at http://download-software.intel.com/sites/default/files/article/301481/compiler-essentials.1.pdf |
||
Line 119: | Line 119: | ||
= GCC = |
= GCC = |
||
The GNU Compiler Collection (GCC) consists of tools to compile and debug C, C++ and Fortran programs: |
|||
bwUniCluster currently provides GNU compiler suite versions: |
|||
{| border="1" style="margin:5px;border-collapse:collapse" |
|||
* 4.5 |
|||
|- |
|||
* 4.7 (default) |
|||
|style="padding:3px"| gcc |
|||
* 4.8 |
|||
⚫ | |||
<br> |
|||
|- |
|||
To load the default compiler suite execute in your terminal session: |
|||
|style="padding:3px"| g++ |
|||
<pre> |
|||
|style="padding:3px"| GNU C++ compiler |
|||
|- |
|||
</pre> |
|||
|style="padding:3px"| gfortran |
|||
To load your prefered version, e.g. 4.5, enter: |
|||
|style="padding:3px"| GNU Fortran compiler |
|||
<pre> |
|||
|- |
|||
⚫ | |||
|style="padding:3px"| gdb |
|||
</pre> |
|||
|style="padding:3px"| GNU debugger |
|||
For details about unload or switching compiler suites, please see chapter [[BwUniCluster_Environment_Modules| environment modules]]. |
|||
|} |
|||
'''Loading:''' There are different versions of the GCC compilers installed. To get a list of these installations execute the following command: |
|||
<pre>$ module avail compiler/gnu</pre> |
|||
There is a default version which will be loaded when no version is explicitly specified, so the command |
|||
⚫ | |||
will load the default version. |
|||
⚫ | |||
'''Local documentation:''' For version specific documentation see the help page of the module. For example |
|||
== Default GNU compiler suite - version 4.7 == |
|||
⚫ | |||
will show the information for the default version. |
|||
For detailed lists of the different program options consult the particular man page: |
|||
via commands 'gcc', 'g++' and 'gfortran' (see also 'http://gcc.gnu.org/'). |
|||
The GNU compiler has been build with gmp-4.3.2, mpfr-2.4.2 and mpc-0.8.1. |
|||
The compiler suite contains: |
|||
<pre> |
<pre> |
||
cpp # GNU pre processor |
|||
⚫ | |||
g++ # GNU C++ compiler |
|||
gfortran # GNU Fortran compiler (Fortran 77, 90 and 95) |
|||
</pre> |
|||
<br> |
|||
Libraries can be found under: |
|||
<pre> |
|||
$GNU_LIB_DIR = /opt/bwhpc/common/compiler/gnu/4.7.3/x86_64/lib64 |
|||
</pre> |
|||
<br> |
|||
For local documentation consult the module help: |
|||
<pre> |
|||
⚫ | |||
</pre> |
|||
or the '''man pages''' of each compiler: |
|||
<pre> |
|||
⚫ | |||
$ man gcc |
$ man gcc |
||
$ man g++ |
$ man g++ |
||
$ man gfortran |
$ man gfortran |
||
⚫ | |||
</pre> |
</pre> |
||
<br> |
|||
'''Optimizations:''' You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is |
|||
For further online documentation visit: |
|||
<pre>$ gcc -march=native -O2 ex.c -o ex</pre> |
|||
⚫ | |||
There are more aggressive optimization flags but the compiled programs can get quite large and the compilation process will probably take much longer. Moreover it can happen that the so compiled program is even slower. Such a command would be for example |
|||
<br> |
|||
<pre>$ gcc -Ofast ex.c -o ex</pre> |
|||
For details on library and include directories of this compiler suite please enter: |
|||
For a complete list of all the optimization options execute |
|||
<pre> |
|||
<pre>$ gcc --help=optimizers</pre> |
|||
⚫ | |||
</pre> |
|||
'''Profiling:''' If you want to profile your program using gprof you have to compile your code with the profile flag: |
|||
<br> |
|||
<pre>$ gcc -pg ex.c -o ex</pre> |
|||
Please do not add the gnu compiler module to any automatic environment setup |
|||
procedure (neither to ~/.profile nor to ~/.bashrc). |
|||
<br> |
|||
Please note, that the environment variables and commands are '''only''' available after loading this module. |
Revision as of 17:52, 27 January 2014
Navigation: bwHPC BPR |
---|
General compiler usage
The basic operations can be performed with the same commands for all available compilers. For advanced usage such as optimization and profiling you should consult the best practice guide of the compiler you intend to use (GCC, Intel Suite). To get a list of the compilers installed on the system execute
$ module avail compiler
Both Intel and GCC have compilers for different languages which will be available after the module is loaded.
Compiler Suite | Language | Command |
---|---|---|
Intel Composer | C | icc |
C++ | icpc | |
Fortran | ifort | |
GCC | C | gcc |
C++ | g++ | |
Fortran | gfortran |
The following compiler commands work for all the compilers in the list above even though the examples will be for icc only. When ex.c is a C source code file such as
#include <stdio.h>
int main() {
printf("Hello world\n");
return 0;
}
it can be compiled and linked with the single command
$ icc ex.c -o ex
to produce an executable named ex. This process can be divided into two steps:
$ icc -c ex.c $ icc ex.o -o ex
When using libraries you must sometimes specify where the include files are (option -I) and where the library files are (option -L). In addition you have to tell the compiler which library you want to use (option -l). For example after loading the module numlib/fftw you can compile code for fftw using
$ icc -c ex.c -I$FFTW_INC_DIR $ icc ex.o -o ex -L$FFTW_LIB_DIR -lfftw3
To inspect what exactly your program does (e.g. when the program crashes), you can run a debugger. To use the debugger properly with your program you have to compile it with debug information (option -g):
$ icc -g ex.c -o ex
Intel Suite
The Intel Composer XE Suite consists of tools to compile and debug C, C++ and Fortran programs:
icc | Intel C compiler |
icpc | Intel C++ compiler |
ifort | Intel Fortran compiler |
idb | Intel debugger in GUI mode |
idbc | Intel debugger in console mode |
Aside from that the suite also includes the TBB (Threading Building Blocks) and IPP (Integrated Performance Primitives) libraries.
Loading: There are different versions of the Intel compilers installed. To get a list of these installations execute the following command:
$ module avail compiler/intel
There is a default version which will be loaded when no version is explicitly specified, so the command
$ module load compiler/intel
will load the default version.
Online documentation: http://software.intel.com/en-us/articles/intel-c-composer-xe-documentation
Local documentation: For version specific documentation see the help page of the module. For example
$ module help compiler/intel
will show the information for the default version. For detailed lists of the different program options consult the particular man page:
$ man icc $ man icpc $ man ifort $ man idb
Optimizations: You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is
$ icc -xHost -O2 ex.c
There are more aggressive optimization flags but the compiled programs can get quite large. Moreover it can happen that the so compiled program is even slower. Such a command would be for example
$ icc -fast ex.c
A tutorial on optimization can be found at http://download-software.intel.com/sites/default/files/article/301481/compiler-essentials.1.pdf and to get the different optimization options execute
$ icc -help opt $ icc -help advanced
Profiling: If you want to profile your program using gprof you have to compile your code with the profile flag:
$ icc -p ex.c -o ex
GCC
The GNU Compiler Collection (GCC) consists of tools to compile and debug C, C++ and Fortran programs:
gcc | GNU C compiler |
g++ | GNU C++ compiler |
gfortran | GNU Fortran compiler |
gdb | GNU debugger |
Loading: There are different versions of the GCC compilers installed. To get a list of these installations execute the following command:
$ module avail compiler/gnu
There is a default version which will be loaded when no version is explicitly specified, so the command
$ module load compiler/gnu
will load the default version.
Online documentation: http://gcc.gnu.org/onlinedocs/
Local documentation: For version specific documentation see the help page of the module. For example
$ module help compiler/gnu
will show the information for the default version. For detailed lists of the different program options consult the particular man page:
$ man gcc $ man g++ $ man gfortran $ man gdb
Optimizations: You can turn on various optimization options to enhance the performance of your program. Which options are the best depends on the specific program and can be determined by benchmarking your code. A command which gives good performance and a decent file size is
$ gcc -march=native -O2 ex.c -o ex
There are more aggressive optimization flags but the compiled programs can get quite large and the compilation process will probably take much longer. Moreover it can happen that the so compiled program is even slower. Such a command would be for example
$ gcc -Ofast ex.c -o ex
For a complete list of all the optimization options execute
$ gcc --help=optimizers
Profiling: If you want to profile your program using gprof you have to compile your code with the profile flag:
$ gcc -pg ex.c -o ex