Search Docs by Keyword
Cpp, C++ Programming Language
Description
C++ (C plus plus) is an object-oriented high-level programing language. C++ files typically have .cpp
as the file extension. You can compile C++ codes with either GNU compilers (gcc) or Intel compilers (intel).
Best Practice
We recommend requesting an interactive job to compile a C++ program on a compute node (instead of a login node). The compilation could take up to few seconds to a minute and depending on the complexity of the code. Additionally, it is best to utilize the test
partition to compile and test a program before executing its production run on the cluster as a batch-job.
It is best practice to compile a C++ code separately and then use the executable, generated during compilation, in the production run using the sbatch
script. If possible, avoid including the compilation command in the sbatch
script, which will recompile the program every time the job is submitted. If any changes are made to the source code, compile the source code separately, and then submit the production run as a batch-job.
Compilers
You can compile a C++ code using either a GNU or an Intel compiler.
GNU compiler
To get a list of currently available GNU compilers on the cluster, execute: module spider gcc
The default GNU compiler is typically the latest compiler version on the cluster and can be loaded using module load gcc
To compile a code using a specific version of the GNU compiler and the O2
optimization flag, you can do the following:
module load gcc g++ -O2 -o sum.x sum.cpp
Intel compiler
To get a list of currently available Intel compilers on the cluster, execute: module spider intel
Intel recommendations and notes
- Intel released Intel OneAPI 23.2 with
icpx
, however, this version does not contain all the features, so we highly recommend using Intel 24 foricpx
- Intel 17 is quite old. Avoid using it as it can have many incompatibilities with the current operating system
- Intel has changed its compiler in the past few years and each module may need different flags. Below is a table of executables and possible flags
Intel module version | Command | Additional flag |
---|---|---|
intel/17.0.4-fasrc01 | icpc | -std=gnu++98 |
intel/23.0.0-fasrc01 | icpc | |
intel/23.2.0-fasrc01 | icpx | |
intel/24.0.1-fasrc01 | icpx |
To compile using a specific version of the Intel compiler, execute:
module load intel/24.0.1-fasrc01 icpx -O2 -o sum.x sum.cpp