EzLAPACK is a lightweight wrapper for the LAPACK library, written in Fortran 90
.
It provides an easy-to-use interface for leveraging LAPACK's performance while minimizing its common constraints, such as the large number of arguments and the lack of generic templates.
Before installing EzLAPACK, ensure that the following tools and libraries are installed on your system:
gfortran
make
- BLAS and LAPACK libraries
To install these on a Debian-based system (e.g., Ubuntu), run:
sudo apt install gfortran make liblapack-dev libblas-dev
To install these on a macOS system, run:
brew install gfortran make lapack
-
Clone the EzLAPACK repository from GitHub:
git clone /~https://github.com/antoine-frot/ezlapack.git
-
Navigate to the EzLAPACK directory:
cd ezlapack/
Install EzLAPACK locally using:
```bash
make install
```
You can now move the directory lib
in your projects to use it.
Install EzLAPACK globally using:
```bash
make install_global
```
By default, the static library is installed in /usr/local/lib
, and the .mod
files are placed in /usr/local/include
.
You can customize these installation paths by modifying the PATH_LIBRARY
and PATH_MOD
variables in the Makefile to suit your preferences.
Uninstall EzLAPACK using:
```bash
make uninstall
```
After that, there will be no trace of the library remaining.
To integrate EzLAPACK, include the following statement at the beginning of your Fortran program:
program program_name
use ezlapack
! Your code here
end program program_name
When compiling your program, ensure that the EzLAPACK module is linked properly by using the following command:
gfortran -o program_name program_name.f90 -I/path/to/mod/files -L/path/to/lib -lezlapack -lblas -llapack
- Local Installation:
-I
and-L
flags should point to thelib
directory. - Global Installation: Use
-I/usr/local/include
(default),-L
flag can be omitted - Library Order: Place
-lezlapack
before-lblas -llapack
.
The use of use ezlapack
and the flag -J
is essential due to the presence of the generic interfaces.
ezmatmul
provides a user-friendly generic interface for LAPACK's matrix multiplication routines *gemm
(i.e. sgemm
, dgemm
, cgemm
, zgemm
).
It computes:
C := alpha*op(A)*op(B) + beta*C
where:
alpha
andbeta
are scalars.A
,B
, andC
are matrices.op(X)
can beX
,X**T
, orX**H
.
-
Basic Matrix Multiplication:
call ezmatmul(A, B, C)
This computes
C := A * B
using LAPACK's performance while maintaining the simplicity of Fortran'smatmul
. -
Advanced Usage:
call ezmatmul('C', 'T', 8d6, A, B, -3d-7, C)
This computes
C := 8d6 * A**H * B**T - 3d-7 * C
Type can be either real(4)
, real(8)
, complex(4)
or complex(8)
,
but all arguments should have the same type.
subroutine ezmatmul(
character*1, optional (default = 'N') :: transa,
character*1, optional (default = 'N') :: transb,
type, optional (default = 1 ) :: alpha,
type, dimension(:,:), contiguous :: A,
type, dimension(:,:), contiguous :: B,
type, optional (default = 0 ) :: beta,
type, dimension(:,:), contiguous :: C
)
-
transa
: (optional, default ='N'
) Specifies the operation applied to matrixA
:'N'
: No transpose,op(A) = A
.'T'
: Transpose,op(A) = A**T
.'C'
: Hermitian,op(A) = A**H
.
-
transb
: (optional, default ='N'
) Specifies the operation applied to matrixB
:'N'
: No transpose,op(B) = B
.'T'
: Transpose,op(B) = B**T
.'C'
: Hermitian,op(B) = B**H
.
-
alpha
: (optional, default =1
) Scalar multiplier forop(A) * op(B)
. -
beta
: (optional, default =0
) Scalar multiplier forC
. -
A
,B
,C
: Contiguous matrices with the same type.
Fortran’s built-in random_number
function is limited to generating random real numbers. To extend this functionality, additional subroutines have been created, particularly for testing purposes. These subroutines are included in the library and are outlined below.
random_complex(output_complex)
Generate random complex numbers (single or double precision) within the unit circle. Supports scalars and arrays up to rank-2.
random_integer(low, high, output_integer)
Generate a random integer between low
and high
, inclusive.
random_character(character_array, output_character)
Randomly select and return a character from an input array of strings.
The LAPACK library is known for its speed, but performance can vary across different computers.
A speed test script has been created to measure LAPACK's execution time and compare it with the intrinsic matmul
function, the EzLAPACK
wrapper and NumPy
from Python
.
To run the speed test, use the following command:
make run
As usually observed, NumPy is as fast as EzLAPACK since it is build on LAPACK.
To verify your EzLAPACK installation, navigate to the EzLAPACK directory and run:
make test
This will compile and execute test cases to ensure everything works as expected.
This project relies on the following tools and libraries:
- Fortran Compiler: gfortran 13.3.0
- LAPACK: 3.11.0
- BLAS: 3.11.0
- Operating System: Ubuntu 22.04 (WSL)
- Bash: 5.1.16
- Make: 4.3
- Python: 3.12.3
We recommend replicating this setup for best results.
The code follows the coding conventions outlined in the Fortran-lang Style Guide. Subroutine names are designed to closely align with the names of intrinsic Fortran subroutines, while variable names adhere to the LAPACK names. The documentation adheres to the nomenclature conventions of Doxygen.
For questions, suggestions, or feedback, please contact:
- Email: Antoine Frot
- GitHub: EzLAPACK Repository