Skip to content

NVHPC compiler on MeluXina

The MeluXina system environment provides the NVHPC compiler.

EasyBuild module description

  C, C++ and Fortran compilers included with the NVIDIA HPC SDK (previously: PGI).

You can use NVHPC to compile your C/C++ programs.

Note

Currently the NVHPC package does not provide a Fortran compiler and MPI toolchain. For any MPI usage, please load IntelMPI/OpenMPI packages.

NVHPC usage

Interactive

Reserve an interactive session:

salloc -A COMPUTE_ACCOUNT -t 01:00:00 -q dev --res cpudev -p cpu -N 1

The example above will allocate one CPU node in interactive mode (dev QoS with cpudev reservation). Load the NVHPC (Will load default version if not specified) module as in below script.

module load NVHPC
nvcc hello.c -o ./HelloTest_C

Batch

NVHPC can also be used in a batch job using Slurm. The script below compile a simple C HelloWorld test on one CPU node allocated for 5 minutes.

#!/bin/bash -l
#SBATCH -N 1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=1
#SBATCH -p cpu
#SBATCH -q test
#SBATCH --time 00:05:00

#Load NVHPC module
module load NVHPC

#Check NVHPC version
nvcc --version

#Compile C program with NVHPC
nvcc hello.c -o ./hello_c

#Execute the program
hello_c

It is recommended to use a Makefile to compile your program. Your Makefile should look like the example below:

#Defines compiler
CC=nvcc

# These are the options we pass to the compiler.
# -std=c++14 means we want to use the C++14 standard.
# -stdlib=libc++ specifies that we want to use the standard library implementation called libc++
# -g specifies that we want to include "debugging symbols" which allows us to use a debugging program.
# -O0 specifies to do no optimizations on our code.
# -Wall, -Wextra, and -pedantic tells the compiler to look out for common problems with our code. -Werror makes it so that these warnings stop compilation.
CFLAGS = -std=c++1y -stdlib=libc++ -c -O0 -Wall -Wextra -Werror -pedantic

all: hello

hello: hello.o
        $CC $CFLAGS -o hello_c hello.o

hello.o: hello.cpp
          $CC $CFLAGS -c hello.c

It is also possible to compile via a Makefile inside a batch job:

#!/bin/bash -l
#SBATCH -N 1
#SBATCH --ntasks=1
#SBATCH --cpus-per-task=128
#SBATCH -p cpu
#SBATCH -q test
#SBATCH --time 00:05:00

#Load NVHPC module
module load NVHPC

#Check NVHPC version
nvcc --version

#Compile C program with NVHPC (in parallel)
make -j

#Execute the program
hello_c