- Join us
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.
Pythonlinpack.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-1 is -1.1606604566338774e-11 x[n-1]-1 is 7.389644451905042e-12 Time is 25.00330138206482 MFLOPS: 3334.892943103315
x[n-1]-1 should both
be (approximately) zero. The normalised residual should be of order
Matlab and Octavelinpack.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
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
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 librarylinpack.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
Clinpack.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
This requires version 3 of
the Eigen C++ template
library. Its performance is hugely dependent on the level of compiler
C (no libraries required)
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.
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.