NERSCPowering Scientific Discovery Since 1974


Description and Overview

The Numerical Algorithms Group (NAG) library is a comprehensive math library that is usually considered the British analogue of IMSL. The functionality is comparable to that of IMSL. The version is double precision.

How to Use NAG

NOTE: There are a limited number of NAG licenses, and access to the NAG libraries is granted only to the people whose work is critically dependent on the software. Many NAG functionalities can be found in other math libraries, such as LAPACK, PARPACK, SLATEC, GSL (GNU Scientific Library), FFTW, etc., that are available. If your work doesn't have to depend on NAG, please look for these alternatives. If you need help with that or if you need to use the NAG software, please contact the consultants.

There are PGI, GNU and Intel versions available on Hopper; and GNU and Intel versions on Edison. The module names for them are nag/24-pgi, nag/24-gnu, and nag/24-intel, etc. Load an appropriate module and then build an executable as follows:

% module load nag           # using the default version on the machine
% ftn -o myprogram myprogram.f90 $NAG

You can separate the compile and link stages, too:

% ftn -c myprogram.f90 $NAG_INC
% ftn -o myprogram myprogram.o $NAG

Then, run the executable, myprogram, on compute nodes, by using 'aprun -n ... ./myprogram' in your batch script.

Example Programs

NAG example programs can be accessed by the command nagexample. For example, the following example is to build and run c02affe example code in an interactive batch job:

% qsub -I -lmppwidth=24    # interactive batch job to run on compute nodes
qsub: waiting for job 3721248.edique02 to start
qsub: job 3721248.edique02 ready

% module load nag
% nag_example f02gbf

The last command will copy the source code of the specified example program and its data from the $NAG_DIR/examples direcotry into the files f02gbfe.f and f02gbfe.d in the current directory; compile, link, and execute the example; and write its results to stdout. Further usage details may be obtained by using the command nag_example without arguments.


For NAG on-line documentation in HTML/PDF format, see the NAG website.  You can make use of NAG's search tools for keywords or routine names; you can also use their Site Map.  See also the Library Manual.


The NAG Fortran Library is a comprehensive collection of Fortran routines for the solution of numerical and statistical problems. The word routine is used to denote subroutine or function.

The library is divided into chapters, each devoted to a branch of numerical analysis or statistics. Each chapter has a three-character name and a title, e.g.,

  D01 - Quadrature

All documented routines in the Library have six-character names, beginning with the characters of the chapter name, e.g.,


Note that the second and third characters are digits, not letters; e.g., 0 is the digit zero, not the letter O. The last letter of each routine name always appears as F in the commercial documentation, but it appears as E in single-precision versions.

Availability at NERSC

PackagePlatformCategoryVersionModuleInstall DateDate Made Default
NAG edison libraries/ programming 24-gnu nag/24-gnu 2015-09-25
NAG edison libraries/ programming 24-intel nag/24-intel 2015-09-25 2015-09-25
NAG edison libraries/ programming 25-intel nag/25-intel 2015-10-02
NAG hopper_cle52 libraries/ programming 24-gnu nag/24-gnu 2015-09-25
NAG hopper_cle52 libraries/ programming 24-intel nag/24-intel 2015-09-25
NAG hopper_cle52 libraries/ programming 24-pgi nag/24-pgi 2015-09-25 2015-09-25
NAG hopper_cle52 libraries/ programming 25-intel nag/25-intel 2015-10-02