TCM
UoC crest

MJ Rutter's Linpack Sources

The code here is not in any sense an officially blessed version of Linpack. It lazily sets the machine epsilon to 2.2e-16, rather than attempting to calculate it. (The value chosen is good enough for IEEE 754 double precision.) However, it does provide a quick way of running the Linpack benchmark in various different languages: C, C++, Fortran, Java, python and Matlab.

There is also a page discussing the merits of unrolling vs blocking using C as an example.

Python

linpack.py (python3 and numpy)
linpack.py2 (python and numpy)

Run as ./linpack.py 5000. Output something like:

Running Linpack  5000 x 5000 

Residual is  2.525624154259276e-11
Normalised residual is  45.5067443271
Machine epsilon is  2.22e-16
x[0]-1 is  -1.1606604566338774e-11
x[n-1]-1 is  7.389644451905042e-12
Time is  25.00330138206482
MFLOPS:  3334.892943103315

Note that x[0]-1 and x[n-1]-1 should both be (approximately) zero. The normalised residual should be of order unity.

Matlab and Octave

linpack.m

This code should be run twice, as there is a lot of overhead on the first function call in Matlab. For those who hate GUIs, start Matlab by typing

$ matlab -nojvm -nodisplay -nosplash

and then, with linpack.m in the same directory, type linpack twice.

Java (no libraries required)

linpack.java
linpack.class

This source is taken from Netlib's Java benchmark page and lightly modified, notably to change the random number routine to one which works for larger matrix sizes. It uses the same algorithm as the Fortran and C code from Netlib.

To run from the command line, with linpack.class in the current directory:

$ java linpack 5000

To regenerate the class file, type

$ javac linpack.java

To run using gjc, type

$ gcj -O --main=linpack linpack.java
$ ./a.out 5000

Fortran 90/95/2003 with system linpack library

linpack.f90 (using dgesv)

For gfortran one can try something like

$ gfortran linpack.f90 -llapack
$ ./a.out 5000

For the Intel compiler and Maths Kernel Library unthreaded:

$ ifort linpack.f90 -mkl=sequential

Other possibilities include:

ifort linpack.f90 -mkl (Intel compiler, threaded MKL)
sunf95 -xlic_lib=sunperf linpack.f90
openf90 linpack.f90 -lacml

C

linpack.c (using Fortran dgesv and C rand())
linpack_with_rand.c (ditto, but own random number generator)

This can be compiled with gcc linpack.c -llapack or icc linpack.c -mkl. Its performance is expected to be identical to the Fortran versions, as the timed part of the code is the external library.

C++ / eigen

linpack_eigen.cc

This requires version 3 of the Eigen C++ template library. Its performance is hugely dependent on the level of compiler optimisation. With g++ 280 MFLOPS was achieved, with g++ -O3 12.2 GFLOPS, and with g++ -O3 -fopenmp 34 GFLOPS.

C (no libraries required)

lpk.c

This requires no libraries, but is an example of how not to write fast code. Its deficiencies are discussed further on the page on unrolling vs blocking. It will probably achieve a couple of GFLOPS.

Original

The original Linpack benchmark files can be found on Netlib's benchmark page, with 1000d being the relevant file. There is a local copy here as 2000d.f and 5000d.f modified to use the F95 timer function and a larger matrix sizes. Note that the matrix size cannot be specified on the command line.

This version does not use any external LAPACK library, so is dependent on the quality of the compiler.

Back to Linpack page.