Install PGI free Fortran compiler

less than 1 minute read

Related: Install Flang LLVM Fortran compiler


The PGI Community Edition compilers are a set of no-cost (but not open source) compilers for C, C++ and Fortran, including Fortran CUDA support.

A big downside to PGI (like Flang, which is partly based on PGI) is PGI compiler has very little Fortran 2008 support, not even the ubiquitous error stop statement.

  1. Download and install PGI Community Edition
  2. add to ~/.bashrc:
    export PATH="$PATH:/opt/pgi/linux86-64/2018/bin/"
    

    or whichever directory you find with

    find /opt/pgi -name pgf90
    
  3. open a new terminal to use pgf90

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)
  add_compile_options(-check all -fpe0 -warn -traceback -debug extended)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL GNU) # gfortran
  add_compile_options(-Wall -Werror=array-bounds -Wextra -Wpedantic)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL PGI)
  add_compile_options(-Mallocatable=03)
elseif(${CMAKE_Fortran_COMPILER_ID} STREQUAL Flang) # cmake >= 3.10
  add_compile_options(-Mallocatable=03)
  link_libraries(-static-flang-libs)
endif()

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

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

Leave a Comment