# External libraries

January 2020

Back to index.html.

# External libraries

## Free libraries for Fortran

Fortran is a plain programming language. It serves primitive statements and many, but simple intrinsic functions. Although these resources are enough to perform scientific operations (e.g., eigenvalue decomposition), Fortran does not provide such high-level procedures. Fortran has a long history, and many users have already had private subroutines useful in their work. Also, some companies provide popular commercial products, e.g., Intel Math Kernel Library (MKL), NAG Numerical Library, and IMSL Numerical Libraries. They are optional, and therefore, it is responsible for the user to prepare the external software.

Currently, a open-source project is moving forward to create the “standard library” in Fortran. It is going to have many essential procedures useful in scientific computing. While many professionals join this project, it may take time to finish developing the library.

Fortunately, besides the “standard library”, the past scientists and engineers have developed and released frequently-used subroutines available online under an explicit license at no cost. Some are old but still useful. In this chapter, we look at some external libraries and pack it as a custom module for future use.

## BLAS and LAPACK

BLAS (Basic Linear Algebra Subprograms) is a collection of Fortran subroutines for basic matrix/vector operations, mainly dedicated to matrix multiplications. LAPACK (Linear Algebra Package) is a library to perform well-known matrix operations such as Cholesky factorization, inversion, solution of linear equations, eigenvalue problems, and so on. LAPACK depends on BLAS. Some companies and research groups have optimized BLAS to enable parallel computations. The optimized BLAS accelerates the LAPACK subroutines, and therefore, you should use it in your serious studies. In this section, we are going to use a reference implementation i.e., non-optimized Fortran library. BLAS and LAPACK are available under the BSD license, an open-source license.

Here is an instruction to build the library.

1. Download the latest version of the package from the official website. The package contains both BLAS and LAPACK.
2. Extract the package and move into the directory.
3. Rename make.inc.example to make.inc.
• If you are using GFortran, do not touch this file anymore.
• If you are using the other compiler (e.g., ifort), open this file, and rewrite the macros: FC, FFLAGS, and FFLAGS_NOOPT.
4. Type make blaslib to compile the BLAS library.
5. Type BUILD_DEPRECATED=yes make lapacklib to compile the LAPACK library.
• Without BUILD_DEPRECATED, you should fail in the compilation of LAPACK95.
• If you cannot use it in the terminal, modify make.inc to activate this variable.
6. The compiled libraries, librefblas.a and liblapack.a, are available in the current directory. Copy these files to your directory.

If you want to test the libraries, type make blas_testing and make lapack_testing. The tests may need a long time to finish.

For BLAS, a test program is available. With GFortran, the following command compiles the file.

gfortran test_blas.f90 librefblas.a

A test program for LAPACK is available. It needs both BLAS and LAPACK (LAPACK comes first in the command line).

gfortran test_lapack.f90 liblapack.a librefblas.a

## LAPACK95

BLAS and LAPACK have many external subroutines. The style of the procedure is based on FORTRAN 77, and it is not easy to use. LAPACK95 provides some modules with the interface to selected subroutines. Unfortunately, this program is very old, and you would have some issues in the compilation. The license statement is found in the manual:

Since LAPACK95 is freely available, it can be included in commercial packages. It is requested only that proper credit be given to the authors by citing this Users’ Guide as the official reference for LAPACK95. Like all software, this package is copyrighted. It is not trademarked; however, if modifications are made that affect the interface, functionality, or accuracy of the resulting software, the name of the routine should be changed. Any modification to the software should be noted in the modifier’s documentation.

Here is the instruction for building the library.

1. Download the package from the official website.
2. Extract the package and move into the directory.
3. Rewrite make.inc.
• For GFortran, put FC=gfortran, FC1=gfortran and OPTS0=-O3.
• For Intel Fortran, use FC=ifort, FC1=ifort and OPTS0=-O3.
4. Move into SRC, and type make single_double.
5. Come back to the original directory with cd .. There is the library, lapack95.a. The mod files are in lapack95_modules.

LAPACK95 has modules so you need .mod files in addition to lapack95.a, liblapack.a, and librefblas.a. A test program for LAPACK is available. It needs both BLAS and LAPACK (LAPACK comes first in the command line).

gfortran test_lapack95.f90 lapack95.a liblapack.a librefblas.a

## RANLIB

RANLIB is a library for random number generators written in FORTRAN 77. The original package is available at Netlib. I restructured this package to have a module. The license is avauilable from the official documentation.

The instruction is as follows.

1. Download the module, ranlib77.f.
2. Compile it to create an object file with -c.
3. Convert the object file to a library file: ar cr ranlib77.a ranlib77.o.

A test program for RANLIB is available. You need ranlib77.a and ranlib77.mod to compile the test program.

gfortran test_ranlib77.f90 ranlib77.a

## CDFLIB

RANLIB is a library for various CDF (cumulative distribution functions) written in FORTRAN 77. The original package is available at Netlib. I restructured this package to have a module. The license is avauilable from the official documentation.

The instruction is the same as RANLIB.

1. Download the module, cdflib77.f.
2. Compile it to create an object file with -c.
3. Convert the object file to a library file: ar cr cdflib77.a cdflib77.o.

A test program for CDFLIB is available. You need cdflib77.a and cdflib77.mod to compile the test program.

gfortran test_cdflib77.f90 cdflib77.a

## Other libraries

There are more libraries available online. I show the pointers, and please explore the websites with the care of the license. Note that some programs are very old (written in FORTRAN 77 around the 1970s). It still compiles with the current Fortran compiler (with possible warnings).

Back to index.html.