High Performance Computing

NAG Libraries

The NAG Fortran Library on the HPC is callable from programs written in Fortran or C/C++.

Compiling

To compile any Fortran program, the nagfor Fortran compiler from NAG can be used. It must be used if the program calls routines from the NAG Fortran Numerical Library. The command to access this compiler on the HPC is:

/software/nag/for
The man entry nagfor gives the full specification of the options available with this compiler.

Using the NAG Fortran Library from a Fortran program

To compile a Fortran program which calls routines from the NAG Library, the command mentioned above is used and the NAG Library is specified to be searched. For example:

/software/nag/for prog.f -lnag
Here the file prog.f contains the Fortran program.

The following script can be used to run the executable program:

/software/nag/run

Example Fortran programs, calling each NAG Library routine, can be found in:

/software/nagflib/examples

Using the NAG Fortran Library from a c/c++ program

A document from NAG describes how to pass parameters from a c/c++ program to Fortran routines. For the HPC we have created some example programs in both c and c++ calling NAG Fortran Library routines. These program files are in the following folder:

/software/nagflib/examples_c
A header file is provided by NAG containing definitions of the Fortran Library routine headers. This file can be included in a c/c++ program to check for correct passing of parameters to NAG routines. This has been installed on the HPC. To include this file, you must specify the following at the beginning of a c/c++ program:
#include <nagmk22.h>
To compile a c++ program contained in a file ex1.cpp and access the include file, the following command should be used:
cc -c ex1.cpp -I/software/nag
Similarly, for a c program in a file ex1.c it would be as follows:
cc -c ex1.c -I/software/nag
This example command produces compiled output in file ex1.o. To link this file to produce the executable, the following command is used for a c/c++ program:
/software/nag/for ex1.o -lstdc++ -lnag
For a c program, -lstdc++ can be omitted. To run the executable file a.out, the following command is used:
/software/nag/run ./a.out

Notes

By default the NAG Fortran compiler produces dynamically linked executables. To produce statically linked executables the option -Bstatic must be used.

The version of the NAG Library specified by -lnag is the self-contained NAG Library. There is another version based on the acml library, which is recommended for better performance. To link with that version, use:

-lnag_acml
This requires in addition the acml library itself. There is a version of the acml library supplied with the NAG Library, and to access it the following libraries must be specified:
-lnag_acml -lacml -lacml_mv