OpenMathLib / OpenBLAS

OpenBLAS is an optimized BLAS library based on GotoBLAS2 1.13 BSD version.
http://www.openblas.net
BSD 3-Clause "New" or "Revised" License
6.24k stars 1.48k forks source link

MKL_GETRF equivalnet in OpenBLAS #3346

Open nnaron opened 3 years ago

nnaron commented 3 years ago

Hi,

I was converting my code from MKL to OpenBlAS, but I am not able to find an equvalent for dgetrf with partal pivoting and dgetrf witout pivoting.

Just I have found "getrf_parallel.c" in LAPACK directory of OpenBLAS, but it is not clear for me how to call it or what is the warpper.

Could you please give me some hint or an example for calling getrf in OpenBLAS?

martin-frbg commented 3 years ago

getrf_parallel.c is just an internal file, part of the optimized implementation of getrf in OpenBLAS - you would still call it as DGETRF or LAPACKE_DGETRF from your code just as with the original "netlib" reference implementation (and I believe it still does use partial pivoting). dgetrf without pivoting a.k.a MKL_DGETRFNP appears to be a MKL extension and is not implemented in OpenBLAS (nor Reference-LAPACK to my knowledge).

nnaron commented 3 years ago

Thanks Martin,

I have installed OpenBLAS in my home dircetory (because of permission issues).

I am caling DGETRF like this:

LAPACKE_DGETRF(&m, &n, A, &lda, ipiv, &info);

or

DGETRF(&m, &n, A, &lda, ipiv, &info);

And I am compiling like this:

cc -L ~/OpenBLAS_bin/lib -I ~/OpenBLAS_bin/include -m64 dgetrf_pp.c -lopenblas -lpthread -lgfortran -liomp5 -lpthread -lm -o dgetrf_pp

The error is:

warning: implicit declaration of function 'LAPACKE_DGETRF' [-Wimplicit-function-declaration] LAPACKE_DGETRF(&m, &n, A, &lda, ipiv, &info); ^~~~~~

I have included in my code.

I have this line also in my bashrc file.

export LD_LIBRARY_PATH=$OPENBLASDIR/lib:$LD_LIBRARY_PATH

martin-frbg commented 3 years ago

Do you #include <lapacke.h> as well ?

nnaron commented 3 years ago

Do you #include <lapacke.h> as well ?

After adding lapacke.h:

warning: implicit declaration of function 'LAPACKE_DGETRF'; did you mean 'LAPACKE_zgemqr'? [-Wimplicit-function-declaration] LAPACKE_DGETRF(&m, &n, A, &lda, ipiv, &info); ^~~~~~ LAPACKE_zgemqr

martin-frbg commented 3 years ago

Sorry, the correct capitalization should be LAPACKE_dgetrf , not LAPACKE_DGETRF

nnaron commented 3 years ago

Thanks. Now it is working. I have question about modification of LAPACKE_dgetrf code. Shoud I work on "getrf_parallel.c" to modify it? If so why this code is so different from the sturcture of LAPACK? I want to remove pivoting part to provide Non Pivoting version of LAPACKE_dgetrf.

martin-frbg commented 3 years ago

Perhaps try modifying getrf_single first, which should be closer to the structure of the Fortran getrf from Reference-LAPACK as it does not have the added complexity of the blocked multithreaded algorithm (which by the way is retained from the original GotoBLAS2 by Kazushige Goto, written 10+ years ago).

nnaron commented 3 years ago

Perhaps try modifying getrf_single first, which should be closer to the structure of the Fortran getrf from Reference-LAPACK as it does not have the added complexity of the blocked multithreaded algorithm (which by the way is retained from the original GotoBLAS2 by Kazushige Goto, written 10+ years ago).

I am reading this code (getrf_single.c) in OpenBLAS/lapack/getrf directory, but I am not understranding how the pivot element is found (searching for pivot element). Just I am seeing LASWP_PLUS and LASWP_ONCOPY which related to pivoting and I think this is not waht I want. In parallel version also just I am seeing a same thing.

martin-frbg commented 3 years ago

I must admit that it is not entirely clear to me either, where "ipiv" is calculated, and sadly there is no documentation of Goto's coding (unless he described it in a publication). Most likely seems to me that the recursive call (where it invokes "CNAME" from inside CNAME - where "CNAME" will be supplied as sgetrf, dgetrf etc. as appropriate by the Makefile) with a small subrange of elements meets the criteria for being forwarded to GETF2: https://github.com/xianyi/OpenBLAS/blob/0f0a0be95dc25d220cd59162dfacc0e930cf5428/lapack/getrf/getrf_single.c#L107 and https://github.com/xianyi/OpenBLAS/blob/0f0a0be95dc25d220cd59162dfacc0e930cf5428/lapack/getrf/getrf_single.c#L86-L87

monil01 commented 1 year ago

I have a similar need to use non-pivoting getrf using openblas. Is there any update on this?