GCC (GNU Compiler Collection)

GCC on SeaWulf

This KB Article References: High Performance Computing
This Information is Intended for: Instructors, Researchers, Staff, Students
Created: 01/20/2018
Last Updated: 03/06/2025

Introduction to GCC on SeaWulf2 and SeaWulf3

The GNU Compiler Collection (GCC) is a cornerstone of high-performance computing on SeaWulf2 and SeaWulf3, offering a comprehensive set of compilers and development tools for scientific and technical applications. With powerful optimization capabilities and compatibility with various programming models, GCC provides users with the flexibility needed for diverse computational tasks.

This open-source toolchain supports multiple programming languages and integrates seamlessly with MPI implementations for parallel computing, making it an essential resource for researchers, staff, and students utilizing SeaWulf's supercomputing environment.

Recommended GCC Stack

We provide users with a single module that effectively loads most recent versions of the GCC compiler and MVAPICH. To use this module, enter the following command:

module load gcc-stack

Current Version: GCC 13.2 + MVAPICH 2.3.7

Modules: gcc/13.2.0, mvapich2/gcc13.2/2.3.7

Note: The gcc-stack module automatically configures your environment with optimized settings for high-performance computing applications on SeaWulf's architecture.

Important Notes for Users

  • Module Loading: When utilizing MVAPICH3 with GCC compilers on SeaWulf2 and SeaWulf3, ensure integration into your workflow by including the MVAPICH2 module in your SLURM job scripts (See example). This ensures seamless integration.
  • Verifying Paths: After loading modules, use the
    which
    command to confirm correct path configurations.

Example SLURM script with GCC and MVAPICH:

#!/bin/bash
#SBATCH --job-name=gcc_test
#SBATCH --output=gcc_test.out
#SBATCH -p short-40core
#SBATCH --ntasks=40
#SBATCH --time=01:00:00

# Load necessary modules

module load gcc-stack


# Compile and run your code

mpicc -O3 mpi_example.c -o mpi_example mpirun -np $SLURM_NTASKS ./mpi_example

GCC Compilers

The GNU Compiler Collection provides a suite of compilers tailored for high-performance computing and parallel programming tasks. When integrated with tools like MVAPICH, GCC compilers offer powerful capabilities for optimizing code performance:

  • C Compiler: gcc
  • C++ Compiler: g++
  • Fortran Compiler: gfortran

Example usage:

gcc myprogram.c -o myprogram # Compile a C program with the GCC C compiler
g++ myprogram.cpp -o myprogram # Compile a C++ program with the GCC C++ compiler
gfortran myprogram.f90 -o myprogram # Compile a Fortran program with the GCC Fortran compiler

MVAPICH GCC Wrappers

MVAPICH provides GCC compiler wrappers that streamline the compilation process for C, C++, and Fortran codes:

Note: These wrappers automatically include the necessary MPI libraries and compiler flags, simplifying the compilation of MPI-enabled applications.

  • mpicc: for GCC C compiler (gcc)
  • mpicxx: for GCC C++ compiler (g++)
  • mpif90: for GCC Fortran compiler (gfortran)

Example usage:

mpicc mpi_program.c -o mpi_program # Compile an MPI C program
mpicxx mpi_program.cpp -o mpi_program # Compile an MPI C++ program
mpif90 mpi_program.f90 -o mpi_program # Compile an MPI Fortran program

For further details on utilizing MVAPICH 2.3.7, visit the MVAPICH User Guide. Integrating these components ensures optimal performance and compatibility within your computational workflows on these supercomputers.

Alternative GCC Stack

We also support older versions of GCC and MVAPICH on SeaWulf. If you would prefer to use a custom stack, you will have to separately load the modules. See example below:

module load gcc/12.1.0 module load mvapich2/gcc12.1/2.3.7

Note: When using custom module combinations, ensure that the MVAPICH version is compatible with your selected GCC version to avoid compilation and runtime issues.

Important Version Information

When this software is updated, sometimes there are revisions that can significantly change how you should write your code and potentially alter the output of your programs. For detailed information on update revisions and deprecated features, refer to the following links:

Additionally, subtle changes not always documented publicly can affect software behavior. Of particular concern in high-performance computing applications is floating point precision, as different GCC versions may yield varying results. For insights into how version switches can impact floating point calculations, refer to this discussion on Stack Overflow: GCC Rounding Difference Between Versions. These resources are crucial for maintaining compatibility and optimizing performance across software updates.

Optimization Tips for GCC

To maximize performance with GCC on SeaWulf, consider the following optimization strategies:

  • Basic Optimization Flags:
    # High optimization level
    gcc -O3 myprogram.c -o myprogram
    # Maximum optimization (may affect precision)
    gcc -Ofast myprogram.c -o myprogram
  • Architecture-Specific Optimization:
    # Optimize for the current CPU architecture
    gcc -march=native myprogram.c -o myprogram

    Note: -march=native optimizes for the specific CPU on which the compilation occurs. However, this may lead to incompatibility across different SeaWulf nodes if they have varying architectures. If your code will run on multiple nodes, specify the target architecture explicitly using -march=<arch>.

  • Vectorization:
    # Enable and report vectorization
    gcc -O3 -ftree-vectorize -fopt-info-vec myprogram.c -o myprogram
  • Profile-Guided Optimization:
    # Step 1: Compile with instrumentation
    gcc -O3 -fprofile-generate myprogram.c -o myprogram

    # Step 2: Run the program to collect profile data
    ./myprogram

    # Step 3: Recompile using the profile data
    gcc -O3 -fprofile-use myprogram.c -o myprogram

Note: Always test your code's correctness after applying aggressive optimizations, as some optimizations might affect numerical precision or algorithm behavior.