blechta / pardiso-matlab-recipes

(Unofficial) build recipes for official Pardiso-Matlab bindings
BSD 2-Clause "Simplified" License
9 stars 2 forks source link

========================================= Build recipes for Pardiso-Matlab bindings

This is a collection of scripts for building Pardiso <https://www.pardiso-project.org/> wrappers for Matlab. Wrapper source code is officially available from Pardiso website <https://pardiso-project.org/manual/pardiso-matlab.tgz> but documentation of the build process is basically missing. The aim of this repository is to address this issue.

Warning: BLAS integer size issue

Matlab is shipped with MKL BLAS/LAPACK built with 64-bit wide integers. Available Pardiso binaries are build against BLAS with 32-bit wide integers. This recipe downloads and builds OpenBLAS <https://github.com/xianyi/OpenBLAS>_, both with 32-bit and 64-bit integers. 32-bit version works with Pardiso but makes Matlab segfault on any call to BLAS. Examples is Matlab polyfit() function. It is not known how much functionality this breaks in Matlab.

Quick install guide

::

cp /path/to/{libpardiso600-GNU720-X86-64.so,pardiso.lic} .
./make_openblas.sh
./make_pardiso_wrappers.sh
./test32.sh
cp -r build32/* <prefix>  # optionally install to other location

Note that the last line in test32.sh will segfault as explained above.

To use Pardiso from Matlab::

source build32/share/pardiso_wrappers.conf     # if kept in build dir
source <prefix>/share/pardiso_wrappers.conf  # if installed elsewhere

matlab

>> pardisoinit(...);
>> ...

Usage of Matlab/Pardiso

See https://pardiso-project.org/manual/manual.pdf#page=34.

Dependencies

Combinations known to work:

Combinations known not working:

Detailed install guide

Step 0. Obtain Pardiso

Go to https://www.pardiso-project.org and obtain libpardiso600-GNU720-X86-64.so and pardiso.lic.

Step 1. Build OpenBLAS

Run ./make_openblas.sh. That will download OpenBLAS, build single-threaded version, and install it into build32/ amd build64/ directories. You might need to tweak the file in order to

see https://github.com/xianyi/OpenBLAS/wiki.

Step 2. Build Pardiso Matlab wrappers

Drop the files obtained in Step 0 in this directory. Run ./make_pardiso_wrappers.sh. This will download the wrappers source from the Pardiso website and build them. You might need to set CXX and/or MEX variables. For example::

export CXX=/usr/bin/g++-5
export MEX=/usr/local/MATLAB/R2018a/bin/mex
./make_pardiso_wrappes.sh

Step 3. Test

Run ./test32.sh and check that Matlab output looks like::

[...]
The factors have 17 nonzero entries.
The matrix has 3 positive and 1 negative eigenvalues.
PARDISO performed 0 iterative refinement steps.
The maximum residual for the solution X is 1.72e-13.
The factors have 14 nonzero entries.
PARDISO performed 0 iterative refinement steps.
The maximum residual for the solution X is 8.88e-16.
The factors have 289 nonzero entries.
PARDISO performed 0 iterative refinement steps.
The maximum residual for the solution is 8.89e-16.
Grid size: 30 x 240
The factors have 130416 nonzero entries.
PARDISO performed 0 iterative refinement steps.
The maximum residual for the solution is 9.9e-12.
!!! Now running failing tests !!!
[...]

If you spot some erros then you probably have to go back to the previous steps.

Step 4. Install

Installation in the build32 directory is relocatable. You can just move its contents to any <prefix> (or leave it where it is) and setup the environment by source <prefix>/share/pardiso_wrappers.conf before launching matlab binary.

Note of LD_PRELOAD="${PREFIX}/lib/libopenblas.so" trick in the configuration file which makes your Matlab use OpenBLAS instead of MKL.

Testing

There is obviously no public CI because Matlab and Pardiso license do not allow to do that. So you have to believe me that this works.

License

BSD 2-clause. Note that this license only applies to the recipes in this repository and in no way applies to source codes and binaries downloaded, built, linked, and installed by these recipes.

Authors

Jan Blechta <https://www-user.tu-chemnitz.de/~blej/>_