HiGHS icon indicating copy to clipboard operation
HiGHS copied to clipboard

undefined reference to `cblas_daxpy'

Open jschueller opened this issue 1 month ago • 10 comments

it seems cblas should be linked to the library (using netlib blas here):

cmake -DHIPO=ON -DBLA_VENDOR=Generic
...
-- Specified BLA_VENDOR: Generic
-- Using BLAS library: /usr/lib/libblas.so
...
[ 98%] Linking CXX shared library ../lib/libhighs.so
[ 98%] Built target highs
[ 99%] Building CXX object examples/CMakeFiles/call_highs_from_cpp.dir/call_highs_from_cpp.cpp.o
[ 99%] Building CXX object app/CMakeFiles/highs-bin.dir/RunHighs.cpp.o
[ 99%] Linking CXX executable ../bin/call_highs_from_cpp
/usr/bin/ld: ../lib/libhighs.so.1.12.0: undefined reference to `cblas_daxpy'

this is version 1.12.0, on archlinux

jschueller avatar Oct 29 '25 18:10 jschueller

Is there a reason you want to use Generic blas? The performance is very poor and we strongly recommend using OpenBLAS instead.

Did you install it with

sudo apt update
sudo apt install libblas-dev

Some libblas.so are just wrappers, may only have fortran and may not include the CBLAS (C interface to BLAS) functions like cblas_dax_py, and then you may have to link cblas explicitly. But you would still get inferior performance, so it is best to use openblas instead:

sudo apt update
sudo apt install libopenblas-dev

galabovaa avatar Oct 30 '25 13:10 galabovaa

I'm refraining from using openblas since I found some severe performance issues recently:

  • https://github.com/OpenMathLib/OpenBLAS/issues/5402
  • https://github.com/OpenMathLib/OpenBLAS/issues/5404

jschueller avatar Oct 30 '25 16:10 jschueller

@filikat I guess HiPO would not be affected by these issues

jajhall avatar Oct 30 '25 16:10 jajhall

These issues appear to be related to multi-threaded OpenBLAS. HiPO uses OpenBLAS only in single-threaded mode. I would expect OpenBLAS to outperform the BLAS reference implementation by orders of magnitude in general.

filikat avatar Oct 30 '25 17:10 filikat

what do you mean by single-threaded mode ? do you explicitely restrict the number of openblas threads to 1 ?

jschueller avatar Oct 30 '25 17:10 jschueller

Yes, we call openblas_set_num_threads(1). We parallelise some of the large matrix-matrix productst by hand and there is other parallel stuff happening in HiPO. Using more than one thread for OpenBLAS seems to degrade performance, perhaps due to too much contention for the resources.

filikat avatar Oct 30 '25 18:10 filikat

it could also be the same openblas throwing all available threads to small matrices kind of issue

highs should still link to cblas regardless

jschueller avatar Oct 31 '25 07:10 jschueller

OK, so can you confirm that cblas is available on your machine and not just the fortran modules?

galabovaa avatar Oct 31 '25 10:10 galabovaa

yes, as if I manually add -lcblas linker flag it works (it would have failed earlier if the cblas headers were not present anyway)

jschueller avatar Oct 31 '25 10:10 jschueller

I just merged this into latest too: cblas should be linked explicitly. Please let me know if you still get issues.

galabovaa avatar Oct 31 '25 15:10 galabovaa