Install PGI free Fortran compiler

Related: Install Flang LLVM Fortran compiler


The PGI Community Edition compilers are a set of no-cost, non-open-source, high performance compilers for:

  • C pgcc
  • C++ pgc++
  • Fortran pgfortran including CUDA Fortran support.

Like Flang, PGI supports significant portions of modern Fortran 2008 / 2018 syntax.

Install

Download and install PGI Community Edition:

  • Linux / Mac: ~/.local/pgi sudo not required, but must be on symbolic-link-aware drive (not ExFAT)
  • Windows: d:\PGI (can be on any drive, including ExFAT). Requires Visual Studio as well.

This is over 2 GB download. You don’t need to install CUDA support unless you have and want to use a CUDA-capable GPU.

Linux / Mac

add to ~/.bashrc:

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

or whichever directory you find with

find $HOME/.local/pgi -name pgfortran

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

Windows

add to PATH (ensure pgfortran.exe is there):

d:\PGI\win64\2019\bin

Usage

Sadly, PGI 19.7 deprecated PGI debugger. PGI Java-based pgdbg graphical debugger was for Fortran, C and C++ and was in the no-cost Community Edition as well. The program to be debugged needs compile options -g -O0 to provide maximum debugging information.

Example with hello.f90:

  1. pgfortran -g hello.f90
  2. pgdbg a.out opened the graphical Fortran debugger.

If you don’t see code in the upper left of the graphical PGI debugger for your program, be sure you compiled the executable with -g -O0 options.

CMake

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

cmake_minimum_required (VERSION 3.10)
project(myproj Fortran)

if(CMAKE_Fortran_COMPILER_ID STREQUAL Intel)
  if(WIN32)
    add_compile_options(/stand:f18 /warn:declarations)
  else()
    add_compile_options(-stand f18 -warn declarations)
  endif()
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL GNU) # gfortran
  add_compile_options(-fstd=f2018 -fimplicit-none)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL PGI)
  add_compile_options(-Mdclchk)
elseif(CMAKE_Fortran_COMPILER_ID STREQUAL Flang) # cmake >= 3.10

endif()

and then clear out your build directory and select the PGI compilers with

FC=pgfortran CC=pgcc CXX=pgc++ cmake ..

Meson

Meson ≥ 0.50 supports PGI and Flang compilers.

project('demo','fortran')

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