Compiling OpenMP Code at NERSC¶
OpenMP Flags for Different PrgEnv Modules¶
Depending on the compiler suite used, a different flag is needed to use OpenMP:
| Vendor | PrgEnv | Language(s) | OpenMP flag |
|---|---|---|---|
| GNU | PrgEnv-gnu |
C/C++/Fortran | -fopenmp |
| NVIDIA | PrgEnv-nvidia |
C/C++/Fortran | -mp |
| HPE | PrgEnv-cray |
C/C++ | -fopenmp |
| HPE | PrgEnv-cray |
Fortran | -homp |
GPU Offload¶
GPU target must be set
Either load the cudatoolkit and craype-accel-nvidia80
modules or use the "target" flags below.
PrgEnv-nvidia¶
Use the -mp=gpu option.
Details of OpenMP support and programming recommendation are available at in the OpenMP section of the Perlmutter Readiness Guide.
PrgEnv-cray¶
| Language(s) | OpenMP flag | target |
|---|---|---|
| C/C++ | -fopenmp |
-fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 -march=sm_80 |
| Fortran | -homp -hnoacc |
-haccel=nvidia80 |
linker warning
The following linker warning can be safely ignored:
Target selection error with Fortran
Target selection error With PrgEnv-cray Fortran applications with
OpenMP offload can be avoided by
- unset the
CRAYPE_ACCEL_TARGETvariable - manually specify the target architecture
-homp -hnoacc -haccel=nvidia80
mixed C/C++ and Fortran applications
Use -fopenmp -fopenmp-targets=nvptx64 -Xopenmp-target=nvptx64 -march=sm_80
to manually specify the target architecture for C/C++ code.
PrgEnv-gnu¶
PrgEnv-gnu is not recommended for OpenMP offloading.
To access it:
An example to compile your code: