(new) Tag: 2017 source edit |
(No difference)
|
Latest revision as of 06:40, 20 April 2026
📍 Magus02 Knowledge Base → HPC User → Compilers
A compiler translates human-readable source code (C, C++, Fortran) into executable binary programs. Choosing the right compiler and flags can significantly affect application performance on Magus02.
General
Compilers are loaded via the module system. Never invoke compilers directly without loading the appropriate module first.
A basic compilation workflow:
# 1. Load the compiler module $ module load intel/oneapi # 2. Compile your source code $ icc hello_world.c -o hello_world # 3. Run the resulting binary $ ./hello_world Hello, World!
Optimization Flags
Always compile with optimization enabled for production runs. Common optimization levels:
| Flag | Effect |
|---|---|
-O0 |
No optimization. Fastest compile; use when debugging. |
-O1 |
Basic optimizations. |
-O2 |
Recommended default for production — good balance of speed and compile time. |
-O3 |
Aggressive optimization, including vectorization. May change floating-point behavior. |
-march=native |
Optimize specifically for the current CPU architecture (AMD EPYC / Intel Xeon on Magus02). |
Intel Compiler (icc / ifort)
The Intel compiler is optimized for Intel and compatible AMD microprocessors and often produces the fastest binaries for numerical codes.
Load the module:
$ module load intel/oneapi
Compile C, C++, or Fortran:
$ icc source.c -O2 -o my_program # C $ icpc source.cpp -O2 -o my_program # C++ $ ifort source.f90 -O2 -o my_program # Fortran 90
GNU Compiler Collection (gcc / gfortran)
GCC is a free, open-source compiler available on all platforms. Reliable and widely tested.
Load the module:
$ module load gcc/11.2.0
Compile:
$ gcc source.c -O2 -o my_program # C $ g++ source.cpp -O2 -o my_program # C++ $ gfortran source.f90 -O2 -o my_program # Fortran
LLVM / Clang
The LLVM project provides modern, modular compiler infrastructure. Useful for C/C++ and when targeting specific optimization analyses.
$ module load llvm $ clang source.c -O2 -o my_program # C $ clang++ source.cpp -O2 -o my_program # C++
PGI / NVIDIA Compilers
PGI compilers (now NVIDIA HPC SDK) are particularly useful for GPU programming with OpenACC pragmas.
$ module load nvhpc $ pgcc source.c -O2 -o my_program $ pgfort source.f90 -O2 -o my_program
Compiling Multi-file Projects
For programs split across multiple source files, use a linker or a build system:
# Compile with multiple source files: $ icc file1.c file2.c file3.c -O2 -o my_program # Or use make (for larger projects with a Makefile): $ module load intel/oneapi $ make
References
- Intel Compilers
- GNU Compiler Collection
- LLVM Compiler Infrastructure
- MPI Usage — Compiler Wrappers
- OpenMP Usage — Compiler Flags
↑ Back to Knowledge Base · Maintained by HPC Administration · wiki.snu.edu.in