Install PGI free Fortran compiler

The no-cost PGI Community Edition compilers are for:

  • C: pgcc (C11)
  • C++: pgc++ (C++17, Linux only)
  • Fortran: pgfortran (Fortran 2003)

In our experience, PGI-compiled binaries offer speed improvements over GNU GCC / GFortran, but Intel-compiled binaries are significantly faster than PGI-compiled binaries. Although we are grateful for NVIDIA providing no-cost access to PGI Community Edition, we unfortunately find that PGI compilers are among the most buggy, giving false syntax errors and segmentation faults on running binaries that careful inspection reveals to be the apparent “fault” of the PGI compilers. Due to these observations, we would only carefully consider a new project designed for PGI compilers. Consider GNU, Clang or Intel compilers, whose bugs are generally significantly less impactful than PGI.

Install

If you have an older PGI compiler installed, uninstall that first to avoid license server issues–even when using the no-cost Community Edition.

Download and install PGI Community Edition:

  • Linux: sudo not required, but must be on symbolic-link-aware drive (not ExFAT)
  • Windows: Requires Visual Studio
  • MacOS is no longer supported by PGI after version 19.10.

PGI compiler is over 2 GB download. CUDA install is optional.

Linux

We assume PGI was installed under “~/.local/pgi” – add to ~/.bashrc like:

export PATH="$PATH:$HOME/.local/pgi/linux86-64/2019/bin/"

Open a new terminal to use PGI pgfortran pgcc pgc++

Windows

use PGI command prompt–you may need to do

set FC=pgfortran
set CC=pgcc

Note that there is no pgc++ on Windows.

PGI on Windows requires Visual Studio. If upgrading Visual Studio (even a minor update) after installing PGI, one may need to reinstall PGI compilers.

Usage

Typically we invoke compilers from a build system such as Meson or CMake.

Meson

Meson build system supports PGI and Flang compilers.

project('demo','fortran', meson_version: '>=0.52.0')

fc = meson.get_compiler('fortran')
if fc.get_id() == 'pgi'
  message('PGI compiler')
endif

CMake

CMake distinguishes between PGI and Flang compilers. Set compiler-specific options in CMakeLists.txt for various Fortran compilers like:

project(myproj Fortran)

if(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
  add_compile_options(-Mdclchk)
endif()

select the PGI compilers at CMake configure step:

FC=pgfortran CC=pgcc CXX=pgc++ cmake -B build

PGI Debugger

PGI 19.10 ended the “pgdbg” graphical debugger. The Java-based “pgdbg” graphical debugger was for Fortran, C and C++, including the no-cost Community Edition.