Skip to content.
Infrastructure > CerebroRocks > CR_AppsCompilers


Cranium: Compilers

This page contains instructions on how to use the different compilers we have installed in the Cranium cluster like the GCC, Intel and PGI.

GCC
Intel
PGI





GCC

Here is a guide on how to use the GCC compiler. Here is a general description on how to compile with C++:


How do I use gcc, g++, and gdb?

If you want to use the GNU C (gcc) compiler to compile your code from the command line just type:

% gcc file.c
or
% g++ file.c

This compiles file.c into an executable binary named a.out. If you use Makefiles to compile your programs, then put the following line at the top of your Makefile:

CC=gcc
or
CC=g++

By default our GCC compiler build executables for 64 bits, but if you need to build an executable for 32 bits, set the following variables in the command line or in your Makefile:

setenv CFLAGS "-O2 -m32"
setenv CXXFLAGS "-O2 -m32"


Here are a few options to gcc and g++:

-o outputfile
To specify the name of the output file. The executable will be named a.out unless you use this option.

-g
To compile with debugging flags, for use with gdb.
-L dir
To specify directories for the linker to search for the library files.
-l library

This specifies a library to link with.
-I dir
This specifies a directories for the compile to search for when looking for include files.


For a complete set of options that control compile optimization, use this link.


Now, to check errors on a "correctly" compiled binary you can use the debugger 'gdb'. Here is a typical example of a gcc/gdb session:


% cat hello.c
#include<stdio.h>

main() {
    int count;

    for (count=0;count<10;count++)
       printf("Hello from LONI!\n");
}
% gcc -g hello.c
% gdb ./a.out
GDB is free software and you are welcome to distribute copies of it
 under certain conditions; type "show copying" to see the conditions.
There is absolutely no warranty for GDB; type "show warranty" for details.
GDB 4.13 (sparc-sun-solaris2.3), 
Copyright 1994 Free Software Foundation, Inc...
(gdb) b main
Breakpoint 1 at 0x10784: file hello.c, line 6.
(gdb) r
Starting program: /home1/b/bozo/./a.out 


Breakpoint 1, main () at hello.c:6
6           for (count=0;count<10;count++)
(gdb) s
7              printf("Hello from LONI!\n");
(gdb) p count
$1 = 0
(gdb) disp count
1: count = 0
(gdb) set count=8
(gdb) s
Hello from LONI!
6           for (count=0;count<10;count++)
1: count = 8
(gdb) 
7              printf("Hello from LONI!\n");
1: count = 9
(gdb) c
Continuing.
Hello from LONI!

Program exited with code 01.
(gdb) q
%

Here are a few gdb commands:

help

Will give you help on most gdb functions. If you wish for help on a specific command, type help command.
b function-name
To set a breakpoint at a function.
r args

To run the program. It will run until it reaches a breakpoint.
s
To single-step through lines of code.
c
To continue until the next breakpoint.
p variable

To print a variable's value.
q
To quit gdb.


Intel

The Intel C++ Compiler lets you build and optimize C/C++ applications for Intel IA-32, Intel Extended Memory 64 Technology (Intel EM64T), and Intel Itanium-based systems running Linux operating systems. You can check a detailed user guide by following this link.

For the 64 bit compiler (please check the appropriate paths),

setenv ICCPATH /usr/local/intel_cc-10.1.008_64bit
setenv PATH bin:${PATH}

This should enable you to compile and link programs using the Intel compiler. In case you are using Makefiles, it's also helpful to set up the path as

Use the Intel compiler,

CC = /usr/local/intel_cc-10.1.008_64bit/bin/icc

Use the Intel Linker,

LD = /usr/local/intel_cc-10.1.008_64bit/bin/icpc


Optimizing with the Intel compiler, most gcc options such as -g, -O2, -O1 should work. Additionally, exclusive optimizing options are provided as follows:


For parallelizing loops,

-parallel

Enables the auto-parallelizer to generate multithreaded code for loops that can be safely executed in parallel.


General faster optimization,

-fast

Provides a single, simple optimization that enables a collection of optimizations that favor run-time performance.


For targetting specific processors,

-mtune=itanium2
or
-mtune=itanium


For generating vectorized code,

-xS

Can generate SSE4 Vectorizing Compiler and Media Accelerators instructions for future Intel processors that support the instructions. Can generate SSSE3, SSE3, SSE2, and SSSE4 instructions and it can optimize for future Intel processors.


-xT

Can generate SSSE3, SSE3, SSE2, and SSE instructions for Intel processors, and it can optimize for the Intel Core Duo processor family.


-xP

Can generate SSE3, SSE2, and SSE instructions for Intel processors, and it can optimize for processors based on Intel Core microarchitecture and Intel NetBurst microarchitecture, like Intel Core Duo processors, Pentium 4 processors with SSE3, and Intel Xeon processors with SSE3.


Linking with the intel compiler,

icpc -L$(LIBDIR) <.o files> -o

Additionally, if one is using C++ and requires -lstdc++, it's better to specify -lguide -lpthread before -lstdc++ to avoid linker errors.


PGI

To compile PGI applications for 32 bits, please set the following variables (if you are using a tcsh shell):

Set the PGI variable,

setenv PGI /usr/local/pgi-7.1.3_64bit

Set the variable for the license file,

setenv LM_LICENSE_FILE ${PGI}/license.dat

Include PGI in your current path,

setenv PATH ${PGI}/linux86/7.1-3/bin:${PATH}

Set the compiler variables,

setenv CC ${PGI}/linux86/7.1-3/bin/pgCC
setenv CFLAGS "-O3 -Bstatic_pgi"

If you have to set additional include directories,

INCLUDES = -I/needed_include_path

And, for additional libraries needed when compiling your code,

INCLUDES = -L/needed_library_path


For 64 bits, follow a similar procedure like with 32 bits:

setenv PGI /usr/local/pgi-7.1.3_64bit setenv PGI /usr/local/pgi-7.1.3_64bit
setenv LM_LICENSE_FILE ${PGI}/license.dat
setenv PATH ${PGI}/linux86-64/7.1-3/bin:${PATH}
setenv CC ${PGI}/linux86-64/7.1-3/bin/pgCC
setenv CFLAGS "-O3 -tp x64 -Bstatic_pgi"


A complete guide for PGI can be found by clicking here. Check also:

PGI User's guide,
PGI Tools guide,
PGI Compiler suite.