ARCHIVED: Compile programs on Carbonate at IU

This content has been archived, and is no longer maintained by Indiana University. Information here may no longer be accurate, and links may no longer be available or reliable.

On this page:


Overview

At Indiana University, the ARCHIVED: Carbonate research supercomputer is designed to support codes that have extremely large memory requirements. Because such codes typically do not implement a distributed memory model, Carbonate is geared toward a serial or shared-memory (OpenMP) parallel programming paradigm. However, Carbonate also supports distributed memory (MPI) parallelism.

Following is information about compiling serial and parallel C, C++, and Fortran programs using the GNU Compiler Collection (GCC), the Intel Compiler Suite, Portland Group (PGI) compilers, and MPI (Open MPI and MPICH2) wrapper compilers available on Carbonate.

GNU Compiler Collection (GCC)

Set up your user environment

The GNU Compiler Collection (the gnu module) is added by default as part of the standard user environment. It includes compilers for C, C++, and Fortran codes:

GNU Compiler Collection
Language Compile command Manual page
C gcc man gcc
C++ g++ man g++
Fortran gfortran man gfortran

The GSL (GNU Scientific Library) numerical library for C and C++ programs is available. To add it to your user environment, load the appropriate module; on the command line, enter:

module load gsl

GNU versions of the FFTW (Fastest Fourier Transforms in the West) routines are also available. Use module avail fftw to see which versions are available, and then use the module load command to load the version you want to use.

You can save your customized user environment so that it loads every time you start a new session; for instructions, see Use modules to manage your software environment on IU research supercomputers.

Optimize your code

Adding the -O option to your compile command enables various optimization flags that tell the compiler to try to improve your code's performance. A higher -O level indicates higher optimization, but can add compilation time and potentially alter the semantics of your program:

UITS recommends using -O2 or -03 for production runs:

Optimization level Description
-O0
No optimization (this is the default)
-O or -O1
These levels are identical; the compiler tries to reduce code size and execution time, but doesn't perform optimizations that take a lot of compilation time.
-O2
This level turns on all -O1 optimization flags plus others that increase both performance and compilation time.
-O3
This turns on additional optimization flags along with those specified by -O2.

Examples

UITS recommends using the mtune=native and march=native options with the GNU compilers to generate instructions for the machine and CPU type. Compile by default in 64-bit. Add the -m32 switch to your compile command to compile in 32-bit; add the -m64 switch to return to 64-bit.

Following are example commands for compiling optimized serial programs with the GNU compilers:

  • To compile a serial C program (for example, my_program.c) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    gcc -O2 -mtune=native -march=native my_program.c -o my_program.exe
  • To compile a serial C++ program (for example, my_program.cpp) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    g++ -O2 -mtune=native -march=native my_program.cpp -o my_program.exe
  • To compile a serial Fortran program (for example, my_program.f) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    gfortran -O2 -mtune=native -march=native program.f -o my_program.exe

To enable support for shared-memory multi-threaded (OpenMP) parallel programs, you must pass the -fopenmp flag to the compiler; for example:

gcc -fopenmp my_omp_program.c -o my_omp_program.exe

For distributed-memory examples, see the MPI wrapper compiler section.

Intel Compiler Suite

Set up your user environment

The Intel Compiler Suite is available on Carbonate; it includes compilers for C, C++, and Fortran codes:

Intel Compiler Suite
Language Compile command Manual page
C icc man icc
C++ icpc man icpc
Fortran ifort man ifort

To see which versions are currently available, on the command line, enter:

module avail intel

To add the default version to your user environment, load the intel module; on the command line, enter:

module load intel

To add a non-default version instead, on the command line, enter (replacing version_number with the desired version number (for example, 12.1.5):

module load intel/version_number

Loading the intel module sets environment variables allowing you to link the following Intel performance libraries into your applications:

  • Integrated Performance Primitives (IPP)
  • Math Kernel Library (MKL)
  • Threaded Building Blocks (TBB)

You can save your customized user environment so that it loads every time you start a new session; for instructions, see Use modules to manage your software environment on IU research supercomputers.

Optimize your code

Adding the -O option to your compile command enables various optimization flags that tell the compiler to try to improve your code's performance. A higher -O level indicates higher optimization, but can add compilation time and potentially alter the semantics of your program:

Optimization level Description
-O1
Optimize for maximum speed, but disable some optimizations that increase code size for a small speed benefit.
-O or -O2
These levels are identical. Optimize for maximum speed. This is the default.
-O3
Optimize for maximum speed and enable more aggressive optimizations that may not improve performance on some programs.
-O0 Disable optimizations.

UITS recommends using -O2 for production runs. You can also try the -fast switch to see if this improves your code's performance.

Examples

Following are example commands for compiling optimized serial programs with the Intel compilers (compile by default in 64-bit):

  • To compile a serial C program (for example, my_program.c) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    icc -O my_program.c -o my_program.exe
  • To compile a serial C++ program (for example, my_program.cpp) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    icpc -O my_program.cpp -o my_program.exe
  • To compile a serial Fortran program (for example, my_program.f) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    ifort -O my_program.f -o my_program.exe

To enable support for shared-memory multi-threaded (OpenMP) parallel programs, pass the -openmp flag to the compiler; for example:

icc -O2 -openmp my_omp_program.c -o my_omp_program.exe

For distributed-memory examples, see the MPI wrapper compiler section.

Portland Group (PGI) compilers

Set up your user environment

The Portland Group (PGI) compilers are available on Carbonate. The PGI package includes compilers for C, C++, and Fortran codes:

Portland Group (PGI) compilers
Language Compile command Manual page
C pgcc man pgcc
C++ pgCC man pgCC
Fortran 77
Fortran 90/95
pgf77
pgfortran
man pgf77
man pgfortran

To see which versions are currently available, on the command line, enter:

module avail pgi

To add the default version to your user environment, on the command line, enter:

module load pgi

To load a non-default version instead, on the command line, enter (replacing version_number with the desired version number (for example, 13.4):

module load pgi/version_number

You can save your customized user environment so that it loads every time you start a new session; for instructions, see Use modules to manage your software environment on IU research supercomputers.

Optimize your code

Adding the -O option to your compile command enables various optimization flags that tell the compiler to try to improve your code's performance. A higher -O level indicates higher optimization, but can add compilation time and potentially alter the semantics of your program:

  • Using the -O switch without specifying an optimization level is equivalent to specifying -O2 (global optimization).
  • Using -O0 compiles and links your code without optimization, which is useful for debugging.

    Alternatively, to set the optimization level to -O0 and generate symbolic debug information, add the -g switch to your compile command.

  • Excluding the -O and -g switches sets optimization to -O1 (local optimization).

Examples

Compile by default in 64-bit. For 32-bit compilations, add the -tp p7 switch to your compiler command.

Following are example commands for compiling optimized serial programs with the PGI compilers:

  • To compile a serial C program (for example, my_program.c) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    pgcc -O my_program.c -o my_program.exe
  • To compile a serial C++ program (for example, my_program.C) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    pgCC -O my_program.C -o my_program.exe
  • To compile a serial Fortran program (for example, my_program.f) and create an optimized executable (for example, my_program.exe), on the command line, enter:
    pgfortran -O my_program.f -o my_program.exe

To enable support for shared-memory multi-threaded (OpenMP) parallel programs, you must pass the -mp flag to the compiler; for example:

pgcc -O -mp my_omp_program.c -o my_omp_program.exe

For distributed-memory examples, see the MPI wrapper compiler section.

MPI wrapper compilers

Set up your user environment

Open MPI and MPICH wrapper compilers are available on Carbonate. The wrapper compilers add the necessary flags for compiling and linking MPI programs, and then invoke the respective back-end compilers to perform the actual commands.

To see which Open MPI wrapper compilers are available, on the command line, enter:

module avail openmpi

To see which MPICH wrapper compilers are available, on the command line, enter:

module avail mpich

To add the wrapper compilers to your user environment, load the appropriate module along with any required prerequisite packages.

You can save your customized user environment so that it loads every time you start a new session; for instructions, see Use modules to manage your software environment on IU research supercomputers.

Examples

MPI wrapper compilers are available for C, C++, and Fortran codes:

MPI/MPICH wrapper compilers
Language Wrapper compiler Manual page
C mpicc man mpicc
C++ mpic++ man mpic++
Fortran mpifort man mpifort

Once you've added the appropriate modules to your environment:

  • To compile and link an MPI program written in C (for example, my_mpi_program.c), on the command line, enter:
    mpicc my_mpi_program.c -o my_mpi_program.exe
  • To compile and link an MPI program written in C++ (for example, my_mpi_program.cxx), on the command line, enter:
    mpicxx my_mpi_program.cxx -o my_mpi_program.exe
  • To compile and link an MPI program written in Fortran (for example, my_mpi_program.f), on the command line, enter:
    mpiffort my_mpi_program.f -o my_mpi_program.exe

Get help

If you have questions about compilers on the IU research supercomputers or need help, contact the UITS Research Applications and Deep Learning team.

This is document beys in the Knowledge Base.
Last modified on 2023-12-17 07:04:59.