请注意,如果在编译程序的时候使用
module load加载了某个编译器,在sbatch作业脚本里也需要加载相同的编译器
单机程序编译和运行
GCC 编译器
使用系统自带的 GCC
默认情况下,系统自带一套 GCC 编译器,无需 module load 加载,直接可以使用
使用预装的其它版本 GCC
使用 module avail 命令查看可用的其它版本,选择所需要的版本,例如
module load scl/gcc13
使用 GCC 编译 C 程序
gcc -O2 source.c -o exefile
使用 GCC 编译 C++ 程序
g++ -O2 source.cpp -o exefile
使用 GCC 编译 Fortran 程序
gfortran -O2 source.f90 -o exefile
使用 GCC 编译 OpenMP 程序
gcc -O2 -fopenmp ompsource.c -o ompexefile
g++ -O2 -fopenmp ompsource.cpp -o ompexefile
gfortran -O2 -fopenmp ompsource.f90 -o ompexefile
Intel 编译器套装
Intel oneAPI 编译器套装包括 Intel C/C++/Fortran 编译器、MKL 数学库、Intel MPI 编译器和运行库等,使用 module avail 命令查看可用的 Intel 编译器套装版本,选择所需要的版本,例如
module load intel/oneapi/2023
使用 Intel 套装编译 C 程序
icc source.c -o exefile
使用 Intel 套装编译 C++ 程序
icpc source.cpp -o exefile
使用 Intel 套装编译 Fortran 程序
ifort source.f90 -o exefile
使用 Intel 套装编译 OpenMP 程序
icc -qopenmp ompsource.c -o ompexefile
icpc -qopenmp ompsource.cpp -o ompexefile
ifort -qopenmp ompsource.f90 -o ompexefile
串行程序运行
串行程序示例作业脚本
#!/bin/bash
#SBATCH --partition=hpxg
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=1
#SBATCH --time=6:00:00
module load scl/gcc13
cd $SLURM_SUBMIT_DIR
./exefile
OpenMP 程序运行
OpenMP 程序示例作业脚本
#!/bin/bash
#SBATCH --partition=hpxg
#SBATCH --nodes=1
#SBATCH --ntasks-per-node=16
#SBATCH --time=6:00:00
module load scl/gcc13
cd $SLURM_SUBMIT_DIR
./ompexefile