Our department has a 2-seat floating licence for the NAG Fortran 6.1 and 6.2 and 7.1 versions for OS X (Mac) only. On a Mac machine (desktop/laptop) with Intel CPUs download the disk image file npmi671na_macx64_7138.dmg or on an ARM processore machine use npma871na_macarm64_7138.dmg that contains NAGFOR 7.1 (7138) that has been improved to stop at floating point exceptions despite the incomplete hardware support of the ARM chip. This is the latest version that our current license is valid for. (Newer versions can be obtained from the NAG download page). Open it

open npm*_macx64*.dmg

and from the command line run the install script (as admin):

sudo -s /Volumes/NAG_Fortran-macarm64/INSTALL.sh

and go through the installation steps.

If you have a NAG license key file, remember to place it into

/usr/local/lib/NAG_Fortran/nag.key

Alternatively set the NAG_KUSARI_FILE to point to the license server. For example, under csh or tcsh, use

setenv NAG_KUSARI_FILE server.machine.university.edu:

in the .cshrc file. Under ksh or bash use

export NAG_KUSARI_FILE=server.machine.university.edu:

The actual name of the server machine can be obtained from Gabor Toth. You will need to use VPN to access the license server remotely.

Try checking the available licenses:

  nagfor -xlicinfo
  NAG Fortran Compiler Release 7.1(Hanzomon) Build 7138
  FLOATING licence, 2 total, 1 in use, perpetual (licence from server)
  Kusari version is 2.2(101)
If the executable does not run because it is not from the App Store, then open Security settings under System Settings, and provide permission to run it.

It is recommended to use the MPICH version of the MPI library that is available from Share/MPI which is configured for nagfor.

If you are using OpenMPI installed for gfortran (through MacPorts, for example) then set the following environment variables (under csh/tcsh):

setenv OMPI_FC nagfor
setenv OMPI_F77 nagfor
setenv OMPI_FCFLAGS ' '
setenv OMPI_FFLAGS ' '
or under ksh or bash use
export OMPI_FC=nagfor
export OMPI_F77=nagfor
export OMPI_FCFLAGS=' '
export OMPI_FFLAGS=' '
before compilation. You can define a load_nagfor alias to execute the above statements and a load_gfortran alias that undoes them.

NAGFOR translates the Fortran code into C, which is then compiled with a C compiler. The 7.1 version running on a Mac assumes that the C compiler named "gcc" is Apple's clang compiler in named /usr/bin/gcc as opposed to the original GNU gcc compiler. If you wish to use the original GNU gcc compiler, it needs to be installed, it has to be in the path before /usr/bin/ and it needs to be selected with the -Wc=`which gcc` flag passed to nagfor.

In addtion the clang specific compiler flag "-fbracket-depth=..." needs to be removed from the call to gcc. This can be done by calling the gcc Perl script that removes the offending switch. Place this script into a directory in the path, for example ~/bin/, so that "which gcc" finds this instead of Apple's /usr/bin/gcc or the original GNU gcc compiler. Remember to make the script executable with

chmod +x gcc

In addition put a link "g++" pointing at the the desired version of the GNU g++ compiler:

ln -s `which g++-12-mp` ~/bin/g++

so that mpicxx uses the GNU g++ compiler instead of the Apple version.

To use the nagfor compiler with GNU gcc, install the SWMF or any of the SWMF models with

Config.pl -install -compiler=nagfor,gcc_mpicc

To use nagfor with Apple's clang compiler, use

Config.pl -install -compiler=nagfor,clang_mpicc

or simply

Config.pl -install

as this compiler combination is actually the default on Mac OS.