xiaoyeli / superlu

Supernodal sparse direct solver. https://portal.nersc.gov/project/sparse/superlu/
Other
280 stars 96 forks source link

Single precision on MacOS #155

Open TobiasDuswald opened 1 month ago

TobiasDuswald commented 1 month ago

I tried installing and testing superlu (v7.0.0) by running the following commands:

git clone https://github.com/xiaoyeli/superlu.git
cd superlu
mkdir build
cd build
cmake ..
make -j
make test

The tests failed for single precision and complex single precision failed:

The following tests FAILED:
      1 - s_test_9_2_0_LA (Failed)
      2 - s_test_19_2_0_LA (Failed)
      3 - s_test_2_0_SP (Failed)
      4 - s_test_9_2_10000000_LA (Failed)
      5 - s_test_19_2_10000000_LA (Failed)
      6 - s_test_2_10000000_SP (Failed)
     13 - c_test_9_2_0_LA (Failed)
     14 - c_test_19_2_0_LA (Failed)
     15 - c_test_2_0_SP (Failed)
     16 - c_test_9_2_10000000_LA (Failed)
     17 - c_test_19_2_10000000_LA (Failed)
     18 - c_test_2_10000000_SP (Failed)
Errors while running CTest

I suppose that this is related to the cmake output

-- The C compiler identification is AppleClang 15.0.0.15000309
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- SuperLU will be built as a static library.
-- Looking for sgemm_
-- Looking for sgemm_ - not found                  <-------------------- here
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Looking for dgemm_
-- Looking for dgemm_ - found
-- Found BLAS: /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/Accelerate.framework
-- Using TPL_BLAS_LIBRARIES='/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.5.sdk/System/Library/Frameworks/Accelerate.framework'
-- Will not link with METIS.
-- Configuring done (1.3s)
-- Generating done (0.6s)
-- Build files have been written to: /Users/tobiasduswald/Software/superlu/build

I also attach all logs (make , cmake, ctest). Is there a simple fix to get this running? make.log test.log cmake.log

TobiasDuswald commented 1 month ago

MacOS 14.5, Xcode 15.4

TobiasDuswald commented 1 month ago

I tried to get rid of this the warning in Cmake by adding a case for macOS to sluCnames.h but the failing tests persisted. I ran the tests in debug mode and the address sanitizer complained for the respective tests. The log is from macOS 14.5, Xcode 15.4, with cmake -DCMAKE_BUILD_TYPE="Debug" -DCMAKE_C_FLAGS="-fsanitize=address -fsanitize=undefined -glldb" ... Commit v7.0.0. test-debugbuild.log

xiaoyeli commented 1 month ago

Can you try using internal BLAS first, with the following cmake definition: -Denable_internal_blaslib=ON

TobiasDuswald commented 1 month ago

Compiling the project with cmake -Denable_internal_blaslib=ON .. && make -j && make test compiles successfully and all tests pass. 👍

xiaoyeli commented 1 month ago

This is good. However, the internal BLAS is not fast. You need to link with a high performance BLAS. The one you were using in Xcode does not have single precision. Alternatively, if you are not using single precision, you can disable it in cmake.

TobiasDuswald commented 1 month ago

I'll use double precision in any case so I'll think it should be okay. :)

I still find it a bit confusing that it compiles if there is apparently no single precision implementation available, yet yields wrong results in the tests. If it is not available, I expected errors during compilation / linking.

Also It appears to me that Xcode / Apple BLAS provides single precision interfaces (see https://developer.apple.com/documentation/accelerate/blas#1805465) but it wasn't immediately obvious to me how to include this in the library and which changes are necessary to facilitate single precision.

xiaoyeli commented 1 month ago

A good public domain BLAS is OpenBLAS: https://www.openblas.net/