Installing LLVM Flang Fortran compiler

Since 2015, NVIDIA has supported Flang: a Fortran compiler frontend to LLVM. Flang f18 targets modern Fortran 2008 / 2018 syntax and is implemented in C++17 internally. In early 2020, Flang will become part of LLVM 10.0, as per the LLVM-Dev mailing list. Perhaps as a result, the binary downloads of Flang haven't been updated for several months. To get the current version of Flang, build yourself or wait for LLVM 10.0.

Build system support

Flang is supported by Cmake ≥ 3.10, although CMake ≥ 3.14 is recommended in general to support more Fortran 2008 features.

Meson ≥ 0.50 supports Flang and in general Meson is easier to use and more powerful than CMake.

Select Flang in the build system as usual by setting environment variables:

FC=flang

How to install Flang

Pick ONE of the following:

  • Download the latest Flang Linux binary release (out of date, wait for LLVM 10.0)
  • Compile from source (non-trivial)

Download Flang binary

Flang prerelease binaries are provided for Linux. MacOS, Windows, BSD support is in work.

Download Flang binary and extract to ~/.local/flang

Add to ~/.bashrc

export PATH=$PATH:$HOME/.local/flang/bin
export LD_LIBRARY_PATH=$HOME/.local/flang/lib/:$LD_LIBRARY_PATH

Open a new Terminal and check

flang --version

Building Flang

Building the LLVM Flang Fortran compiler from source is a resource-intensive process.

  • A moderately powerful PC is needed to compile Flang with > 100 GB of free space on the drive you build Flang on. Flang install is small, but Flang build process requires a lot of drive space.
  • Don't use too much RAM with the -j option of make for building Flang. It maxed out RAM on a PC with 32 GB of RAM with make -j. Try just plain make.
  • follow the Flang build instructions sequentially. Don't try to build later parts while earlier parts are still building, this will not work properly.

Install NAG Fortran compiler

Related: Five free Fortran compiler suites


The NAG Fortran compiler is a non-free compiler for modern Fortran. New features in NAG 7.0 vs. NAG 6.2 include:

  • Fortran 2008 coarray for multiple images
  • half-precision (float16)
  • Fortran 2008 submodule support
  • -f2018 flag to indicate Fortran 2018 standard semantics

Install

If you don't already have a NAG license, request a NAG trial. Typically they ask for a little info to help them understand their potential customer's needs.

Download NAG compiler and extract the compressed folder to a non-ExFAT / non-FAT32 drive, since symbolic links are used.

Run installer:

./NAG_Fortran-amd64/INSTALL.sh

Consider installing to /home/username/.local/bin and all other choices as default. DO NOT use ~ or $HOME as the NAG installer did not recognize these shortcuts!

The NAG compiler should be available:

nagfor

However, compilation is disabled until a license is installed.

License setup

This procedure is for Linux. License key comes in an email from NAG. Scroll down for the one-line license key and copy it to $HOME/.local/lib/NAG_Fortran/nag.key

Add to ~/.bashrc:

export NAG_KUSARI_FILE=$HOME/.local/lib/NAG_Fortran/nag.key

Open a new Terminal and nagfor should now be able to compile programs.

NAG license FAQ

Graphical Debugger

NAG Fortran Builder is for Windows and MacOS only. For NAG command-line debugging use dbx90.

Build systems

CMake and Meson support NAG Fortran compiler.

Install Intel Compilers for C, C++ and Fortran

The Intel Parallel Studio XE 2020 suite includes compliers named:

  • Windows: icl (C, C++) and ifort (Fortran)
  • Linux / MacOS: icc ( C ) icpc (C++) ifort (Fortran)

Parallel Studio also includes Intel MPI compiler wrappers (on Windows and Linux):

  • mpiicc ( C )
  • mpicxx (C++)
  • mpiifort (Fortran)

OS-specific considerations include:

  • MacOS: MPICH is available instead of Intel MPI or OpenMPI with Intel compilers
  • Windows: Intel compilers on Windows require Microsoft Visual Studio of appropriate version installed with C++ extensions as well.
  • Windows: MPI has special considerations particular to Windows only.

Install

For all OS, sudo / administrator is not needed or desired to install Intel compilers. Just install under your home directory or common directory.

  1. Download the Parallel Studio XE Cluster Edition Composer Suite (online/custom installer, not the entire 4 GB file). Get the CLUSTER / “all tools” version, NOT just the Fortran version or you will NOT have MPI!

  2. Extract and run the installer.

    • Linux / MacOS: install to a permissions-aware drive (e.g. Ext4), NOT a non-permissions filesystem like ExFAT, or the compiler will silently fail to install.
    • Windows: can install to non-permissions-aware drive (ExFAT is OK if desired)
  3. Select options similar to as below, adding PGI compiler if you use it (can add later if needed):

    • architecture: Intel64 (IA-32 not used)
    • Intel C++ Compiler
    • Intel Fortran Compiler
    • Intel MKL for C/C++
    • Intel MKL for Fortran
    • LAPACK 95
    • Intel MPI Library
    • GNU GDB

Load environment

  • Linux: create a file ~/intel.sh like:
. ~/intel/bin/compilervars.sh intel64
. ~/intel/mkl/bin/mklvars.sh intel64

Enable the Intel compilers each time you want to use them with:

. ~/intel.sh
  • Windows: create a file intel.bat like:
"C:/Program Files (x86)/IntelSWTools/compilers_and_libraries_2020/windows/bin/compilervars.bat" intel64

set FC=ifort
set CC=icl
set CXX=icl

Intel MKL

If you installed MKL prior to the Intel Compiler, be sure to select Intel MKL or it will uninstall your preexisting MKL! The Intel MKL options you may want for a desktop PC include

  • Intel MKL core libraries for C/C++

  • Intel TBB threading support

  • GNU C/C++ compiler support

  • Intel MKL core libraries for Fortran

  • GNU Fortran compiler support

  • Fortran 95 interfaces for BLAS and LAPACK

CMake Intel compilers

FC=ifort CC=icc CXX=icpc cmake ..

To switch back to GNU or other compiler, you have to remove the CMake cached files. Using Intel compilers and libraries with CMake is quite straightforward and easy to switch between compilers.

Why use Intel compilers

To understand what Intel compilers can do for scaling your program from the desktop to HPC–or merely improve performance on your laptop, seeIntel Compiler new user guide.

Python f-string benchmarks

Python 3.6 f-strings have been shown to be the fastest string formatting method in microbenchmarks by Python core dev Raymond Hettinger:

In relative speed factors, that's:

  • f-string: 1.0
  • concatenate string: 1.33
  • join sequence of strings: 1.73
  • %s formatting operator: 2.40
  • .format() method: 3.62
  • Template() method: 11.48

The reason for this speedy performance was described by Python core dev Serhiy Storchaka:

Use Matplotlib constrained_layout instead of tight_layout

Many legacy tutorials and examples for Matplotlib use tight_layout(). A key problem with tight_layout() and subplots is that tight_layout destroys suptitle(). Matplotlib constrained_layout is still being improved and is recommended over tight_layout().

To make figures with subplots and suptitle work better, use figure(constrained_layout=True):

from matplotlib.pyplot import figure, show

fg = figure(constrained_layout=True)
ax = fg.subplots(3, 1)

for i in range(3):
    ax[i].plot(range(5+5*i))

fg.suptitle('lots of lines')

show()

This plot is much superior to fg.tight_layout()

Intel AMT / vPro KVM without proprietary RealVNC Viewer Plus

Intel vPro AMT is not for directly internet-connected remote PCs. The operating system firewall does not protect vPro ports, which exist outside the operating system. Be sure the PC is behind an external firewall. Exercise great care if making these changes on an already remote PC, as a wrong checkbox hit can necessitate a physical field trip to the PC to correct.

  1. On your laptop Download and install the free, open-source Intel Mesh Commander.
  2. Open the “Manageability Commander Tool” and click File → Add → Add Intel AMT computer and type the IP address and vPro username (typically “admin”) and password. Set the password in the remote PC BIOS if you haven't already.
  3. Click the little plus sign by Network and click on your AMT PC's name–then in the Connection tab, click Connect. This will take about 5-10 seconds to connect–if Unsuccessful, the button will fall back to saying Connect. If successful, the button will change to say Disconnect.
  4. Go to the Remote Control tab and wait about 10 seconds for the “remote desktop” items to change from “unknown” to the actual state. If Remote Desktop Settings is “Disabled”, click the little box to its right to open a new window.
  5. Click OK and then go back to the Connection tab and click Disconnect. Don't mess around with any of the other settings unless you know exactly what you're doing and are willing to drive out to the remote PC to fix it if you mess something up!  Close the MeshCommander program.

Now you should be able to connect using a standard VNC program. Use “localhost” since we SSH into the remote PC first.

DO NOT expose VNC port 5900 to the internet or you are highly likely to get quickly hacked.

Intel AMT configuration screen

Intel AMT configuration screen.

Setup Windows SSH server

The factory Windows OpenSSH server is robust for secure SSH port forwarding. Consider SSH ED25519 public key authentication as it is vastly more secure than keyboard passwords.

Notes

Intel MeshCommander replaces Intel Open Manageability Toolkit.

Intel vPro remote control ports

C++17 filesystem example and caveats

Some compilers will compile and link C++17 filesystem code, but fail on run. In general, although it's a little slower to configure, consider using run tests to more completely ensure a feature is properly implemented.

For example, in meson.build test for C++17 filesystem functionality by:

if add_languages('cpp', required: false)
  cpp = meson.get_compiler('cpp')
  code = '''
#include <filesystem>
namespace fs = std::filesystem;

int main(void) {
fs::path p = fs::path(".");
return 0;
}
'''
  # some compilers will compile and link, but only fail on run when accessing
  # the actual filesystem paths
  # e.g. MinGW G++ 9.2.0
  f17filesystem_ok = cpp.run(code, name: 'C++ filesystem').returncode() == 0
endif

Then use if f17filesystem_ok to decide if to build executables or libraries

fix bug with Git for Windows nano error

Git 2.24.1.windows.2 seems to have a bug in git.nanorc within Git Bash. Specifically, the wrong (Windows/DOS) \r\n line endings seem to have been introduced. A simple fix is to use dos2unix to correct the line endings.

Fix

Open Git Bash using “Run as Administrator” via the Windows Start menu and type into this Terminal:

dos2unix /usr/share/nano/git.nanorc

Symptom

Git operations using the nano editor, such as git commit without the -m option or git rebase -i invoke errors as below. This is despite the git.nanorc matching templates as old as 2016. The problem is, in Git 2.24.1.windows.2, the line endings were accidentally set to DOS \r\n instead of \n.

Error in /usr/share/nano/git.nanorc on line 1: Regex strings must begin and end with a " character
" not understoodare/nano/git.nanorc on line 2: Command "
" not understoodare/nano/git.nanorc on line 10: Command "
" not understoodare/nano/git.nanorc on line 15: Command "
Error in /usr/share/nano/git.nanorc on line 19: Regex strings must begin and end with a " character
" not understoodare/nano/git.nanorc on line 20: Command "
" not understoodare/nano/git.nanorc on line 23: Command "
" not understoodare/nano/git.nanorc on line 26: Command "
" not understoodare/nano/git.nanorc on line 33: Command "
" not understoodare/nano/git.nanorc on line 36: Command "
" not understoodare/nano/git.nanorc on line 42: Command "
" not understoodare/nano/git.nanorc on line 44: Command "
" not understoodare/nano/git.nanorc on line 47: Command "
" not understoodare/nano/git.nanorc on line 50: Command "
" not understoodare/nano/git.nanorc on line 51: Command "
Error in /usr/share/nano/git.nanorc on line 53: Regex strings must begin and end with a " character
" not understoodare/nano/git.nanorc on line 54: Command "
" not understoodare/nano/git.nanorc on line 57: Command "
" not understoodare/nano/git.nanorc on line 60: Command "
" not understoodare/nano/git.nanorc on line 74: Command "
" not understoodare/nano/git.nanorc on line 77: Command "
" not understoodare/nano/git.nanorc on line 80: Command "
Error in /usr/share/nano/git.nanorc on line 1: Regex strings must begin and end with a " character
" not understoodare/nano/git.nanorc on line 2: Command "
" not understoodare/nano/git.nanorc on line 15: Command "
Error in /usr/share/nano/git.nanorc on line 19: Regex strings must begin and end with a " character
" not understoodare/nano/git.nanorc on line 20: Command "
" not understoodare/nano/git.nanorc on line 23: Command "
" not understoodare/nano/git.nanorc on line 26: Command "
" not understoodare/nano/git.nanorc on line 33: Command "
" not understoodare/nano/git.nanorc on line 36: Command "
" not understoodare/nano/git.nanorc on line 42: Command "
" not understoodare/nano/git.nanorc on line 44: Command "
" not understoodare/nano/git.nanorc on line 47: Command "
" not understoodare/nano/git.nanorc on line 50: Command "
" not understoodare/nano/git.nanorc on line 51: Command "
" not understoodare/nano/git.nanorc on line 54: Command "
" not understoodare/nano/git.nanorc on line 57: Command "
" not understoodare/nano/git.nanorc on line 60: Command "
" not understoodare/nano/git.nanorc on line 74: Command "
" not understoodare/nano/git.nanorc on line 77: Command "
" not understoodare/nano/git.nanorc on line 80: Command "

Fix PGI compiler error required tool link was not found

Windows PGI compilers require Visual Studio. Visual Studio has frequent upgrades. Minor version Visual Studio upgrades can change the directory link is available under, usually under

c:/Program Files (x86)/Microsoft Visual Studio/2019\Community/VC/Tools/MSVC

We have found the quickest fix is to reinstall PGI. Trying to soft-link directories under the directory above didn't help.

NOTE: The “Repair” option doesn't work, you have to UNINSTALL and then do a fresh PGI install.

Octave 6.x what's new

GNU Octave prerelease binaries are available via FTP download. The NEWS file shows significant feature highlights that are easier to discern than the Changelog.

Missing features

GNU Octave does not support newer Matlab classes like:

  • string introduced in Matlab R2017a. The Matlab “string” class is quite powerful, akin to Python strings.

Schedule