Hprc banner tamu.png


Jump to: navigation, search

NAG Numerical Libraries


the NAG Libraries contain an extensive set of numerical and statistical algorithms (including full BLAS and LAPACK functionality) for various languages and compiler tool chains. Currently, the following NAG libraries are installed on ADA (the links refer to the official NAG homepage for that library and provides a wealth of information, including user manuals):

Every library is targeted for a specific architecture, language, and compiler toolchain. For example; the NAG PHI Library is designed to run on Intel Phi co-processors.

NOTE: The NAG SMP Library is basically a multi-threaded version of the NAG Fortran Library. The NAG SMP Library does not require any knowledge about parallel processing. The library code is executed in parallel automatically wherever possible. The functions/subroutines and argument lists in the NAG SMP Library are identical to their counterparts in the NAG Fortran Library. Switching between using the NAG Fortan Library and NAG SMP Library is completely transparent and doesn't require rewriting of the code. The only difference is during linking of the library. The NAG SMP Library also provides C header files so it can also be used by programs written in C/C++.

As mentioned, every NAG library is targeted for a specific compiler suite. Therefore there is different library for every compiler tool chain. The following table shows for every NAG library the available compiler toolchains:

NAG Library Tool chains
Fortran Intel / GNU / PGI / NAG compiler
C Intel / GNU
SMP Intel
PHI Intel

For example, there are four different NAG Fortran Libraries avaialable; Intel,GNU,PGI, and NAG compiler.

Setting up the Environment

As mentioned above, the NAG library packages contains a number of different libraries for various compiler tool chains. Currently the following combinations are installed:

-bash-4.1$ module avail NAG
   NAG/C-Library/Mark24-Intel           (D)
   NAG/Fortran-Library/Mark24-NAG-6.0     (D)

NOTE: Mark?? refers to the version of the NAG library. The latest version is Mark24

NOTE: unlike the other NAG libraries (e.g. NAG C library) the NAG Fortran Libraries are targeted for very specific compiler toolchain versions. The reason for this is that the NAG Fortran Library includes Fortran modules which are very compiler version specific. Loading any of the NAG Fortran Libraries will also load the appropriate compiler toolchain automatically.

For example, to load the NAG Fortran library for programs that will be compiled using the Intel compiler toolchain ictce/7.1.2, type:

-bash-4.1$ module load NAG/Fortran-Library/Mark24-ictce-7.1.2

Compiling/Linking NAG Libraries

The module load command will set a number of environmental variables that are needed for compiling/linking code that contains calls to NAG Library functions/subroutines. For compiling and linking the compiler needs to have information about the following directories:

  • INCLUDE path
  • LIBRARY path

The INCLUDE path is the directory that contains all the include files (i.e. compiled modules in Fortran and header files in C). The library path contains the shared and static NAG libraries.

The Table below shows the environmental variables for the correct INCLUDE and LIBRARY paths:

NAG Library INCLUDE path LIBRARY path

For example, $NAG_FORTRANLIB_LIB refers to the directory that contains all the Fortran compiled modules.

Example 1: Compiling/Linking Fortan code

The code below is a very simple program (let's call it nag_example.f90) that calls the NAG subroutine a00aaf. This subroutine just prints out information about the used NAG library version. Note the use nag_library statement. Although, not required it will add interface blocks which will assist the compiler in type checking the code.

program show_nag_version
! Don't forget to include the nag_library module
  use nag_library

! call the nag subroutine
  call a00aaf
end program show_nag_version

To compile and link (let's name the executable nag_example.x):

-bash-4.1$ module load NAG/Fortran-Library/Mark24-intel-2014b
-bash-4.1$ ifort -I$NAG_FORTRANLIB_INCLUDE -o nag_example.x nag_example.f90 -L$NAG_FORTRANLIB_LIB -lnag_nag
Example 2: Compiling/Linking C code

The code below (let's name is nag_example.c) is very similar to the Fortran example above. The difference is that the subroutine name is a00aac() instead of a00aaf(). Also note the #include command. Although, not always required, It's good practice to add the appropriate include commands in your program.

// include the appropriate header file
#include <naga00.h>                                                                                                                                              

int main(void) {
// call the nag subroutine
  return 0;

To compile and link (let's name the executable nag_example.x):

-bash-4.1$ module load intel
-bash-4.1$ module load NAG/C-Library/Mark24-Intel
-bash-4.1$ icc -I$NAG_CLIB_INCLUDE -o nag_example.x nag_example.C -L$NAG_CLIB_INCLUDE -lnagc_nag