Skip to main content

Programming Tools

Available Compilers

The Palmetto offers the following compiler suites for C, C++ and Fortran applications:

  1. GNU Compiler Collection (gcc)
  2. Intel Compiler Suite
  3. PGI Compiler Suite
module avail gcc
module avail intel

Compiling "Hello World" Program

C

Simple hello.c file that reads

#include <stdio.h>

int main(void){
printf("Hello, world!\n");
return 0;
}

can be compiled on Palmetto using the following commands

CompilerModuleCommand
Intelintel/13.0icc hello.c -o hello.x
GCCgcc/4.8.1gcc hello.c -o hello.x
PGIpgi/16.10pgcc hello.c -o hello.x

C++

The same example in C++ put in a file hello.cpp

#include <iostream>

int main()
{
std::cout << "Hello, world!" << std::endl;
return 0;
}

can be compiled on Palmetto using the following commands

CompilerModuleCommand
Intelintel/13.0icpc hello.cpp -o hello.x
GCCgcc/4.8.1g++ hello.cpp -o hello.x
PGIpgi/16.10pgc++ hello.cpp -o hello.x

FORTRAN

To compile a simple FORTRAN program test.f90

program test
print *,'hello from fortran'
end program test

use a command appropriate for a given compiler suite

CompilerModuleCommand
Intelintel/13.0ifort test.f90 -o test.x
GCCgcc/4.8.1gfortran test.f90 -o test.x
PGIpgi/16.10pgfortran test.f90 -o hello.x

GCC compiler options

SwitchDescription
-cCompile the source file but do not link
-x languageSet the specific language instead of letting the compiler decide based on the source file suffix. Useful for FORTRAN i.e. language can be replaced with f77, f77-cpp-input, f95 or f95-cpp-input
-o fileChange the name of the binary file from a.out to file
-vPrint version of the compiler with options used for its configuration
-fopenmpEnables OpenMP directives to create a multithreaded code
-fno-gnu-keywordsTurns off GNU specific language extensions
-wSuspend add warnings
-WallEnables all warnings
-gEnables debugging information
-p or -pgTurns on gprof profiling information
-ftree-vectorizer-verboseEnables verbose mode for GCC vectorization
-O, -O1, -O2 or -O3Different levels of code optimization; -O3 is the most aggressive
-Ofast-Ofast enables all -O3 optimizations. It also enables optimizations that are not valid for all standard-compliant programs
-OgTurns on debugging safe optimization mode
-floop-blockPerform loop blocking transformations on loops
-floop-interchangePerform loop interchange transformations on loops
-ftree-vectorizePerform loop vectorization on trees. This flag is enabled by default at -O3
-funroll-loopsUnroll loops whose number of iterations can be determined at compile time or upon entry to the loop
-fprefetch-loop-arraysGenerate instructions to prefetch memory to improve the performance of loops that access large arrays
-ffast-mathUse faster but less accurate mathematical functions
-DDefine a macro
-I<dir>Add <dir> to compilers path for included files
-l<lib>Pass a library <lib> to the linker
-L<dir>Add directory <dir> to the linker library path
-march=nativeThis selects the CPU to generate code for at compilation time by determining the processor type of the compiling machine
-ffree-formFORTRAN : Specify the layout used by the source file
-cppFORTRAN : Enable preprocessor for FORTRAN files
-fno-underscoringFORTRAN : Do not transform names of entities specified in the Fortran source file by appending underscores to them
-fexternal-blasFORTRAN : This option will make gfortran generate calls to BLAS functions for some matrix operations like "MATMUL"
-floop-parallelize-allIdentify loops that can be parallelized
-ftree-parallelize-loops=nParallelize loops, i.e., split their iteration space to run in n threads. This option implies -pthread

More information

Intel compiler options

SwitchDescription
-parallelenable the auto-parallelizer to generate multi-threaded code for loops that can be safely executed in parallel
-par-reportX(X=1,2,3) control the auto-parallelizer diagnostic level
-openmpenable the compiler to generate multi-threaded code based on the OpenMP* directives
-openmp-reportX(X=1,2,3) control the OpenMP parallelizer diagnostic level
-fastenable -xHOST -O3 -ipo -no-prec-div -static options set by -fast cannot be overridden with the exception of -xHOST, list options separately to change behavior
-O0disable optimizations
-O1optimize for maximum speed, but disable some optimizations which increase code size for a small speed benefit
-O2optimize for maximum speed (DEFAULT)
-O3optimize for maximum speed and enable more aggressive optimizations that may not improve performance on some programs
-threadsspecify that multi-threaded libraries should be linked against -nothreads disables multi-threaded libraries
-vecenables (DEFAULT) vectorization (-novec disables vectorization)
-mkllink to the Math Kernel Library (MKL) and bring in the associated headers, -mkl= one of parallel (default), sequential or cluster
-opt-matmulreplace matrix multiplication with calls to intrinsics and threading libraries for improved performance (DEFAULT at -O3 -parallel)
-xHostgenerate instructions for the highest instruction set and processor available on the compilation host machine
-integer-size XXspecifies the default size of integer and logical variables size: 16, 32, 64
-real-size XXspecify the size of REAL and COMPLEX declarations, constants, functions, and intrinsics size: 32, 64, 128
-wdisable all warnings, equivalent to -warn none or -nowarn
-warn allenables all warnings
-L<dir>instruct linker to search <dir> for libraries
-l<string>instruct the linker to link in the -l<string> library
-Wl,<o1>[,<o2>,...]pass options o1, o2, etc. to the linker for processing
-Vdisplay compiler version information
-multiple-processes[=<n>]create multiple processes that can be used to compile large numbers of source files at the same time
-ccompile to object (.o) only, do not link
-Scompile to assembly (.s) only, do not link
-o <file>name output executable file
-gproduce symbolic debug information in object file (implies -O0 when another optimization option is not explicitly set)
-pcompile and link for function profiling with UNIX gprof tool, -pg is also valid
-D<name>[=<text>]define macro
-I<dir>add directory to include file search path
-fpprun Fortran preprocessor on source files prior to compilation