Skip to content

Canonicalize source file name in tests for BLAS threading.#1009

Merged
DrTimothyAldenDavis merged 1 commit intoDrTimothyAldenDavis:dev2from
mmuetzel:suitesparse_config
Nov 4, 2025
Merged

Canonicalize source file name in tests for BLAS threading.#1009
DrTimothyAldenDavis merged 1 commit intoDrTimothyAldenDavis:dev2from
mmuetzel:suitesparse_config

Conversation

@mmuetzel
Copy link
Contributor

@mmuetzel mmuetzel commented Nov 4, 2025

These tests are run repeatedly for different libraries. Canonicalize the path to the source files of the tests to allow early deduplication. This avoids issues with some generators (e.g., Ninja).

Fixes #1008.

In general, it might be a good idea to convert these to runtime checks instead of configure checks. Otherwise, it might lead to strange results if the BLAS implementation changes after the libraries have been built (e.g., with Debian's alternatives mechanism).

These tests are run repeatedly for different libraries. Canonicalize the path
to the source files of the tests to allow early deduplication. This avoids
issues with some generators (e.g., Ninja).

Fixes DrTimothyAldenDavis#1008.
@DrTimothyAldenDavis
Copy link
Owner

Thanks for the update -- I'll give it a try shortly.

It can't be done as a runtime check, unfortunately. The Apr 2024 version of OpenBLAS adds a new function, openblas_set_num_threads_local, that appears in 0.3.27 but not doesn't appear in earlier versions. It also doesn't appear in any other BLAS library.

The Intel MKL library has an mkl_set_num_threads_local, and has had it for a long time. This OpenBLAS function does the same thing, but for the OpenBLAS library.

We need this functionality in ParU, for best performance.

if the functions are not available, then ParU has to use a different method for its own parallelism.

I don't think it would be possible to check if these functions exist at run time. The check would have to be done at link time at the latest, perhaps dynamically, but I don't know how to do that in a portable way. So the only time I can do this check is at compile time of ParU, to determine if these functions are available.

It's an unfortunate situation. Both MKL and OpenBLAS are making up for a fundamental flaw in the BLAS library standard, by allowing the caller to control the # of threads used by any given call to the BLAS, on a per-user-thread basis. But they've done so in different ways, with different function names.

So a compile time test is the only think I can do.

@DrTimothyAldenDavis DrTimothyAldenDavis merged commit 32083d5 into DrTimothyAldenDavis:dev2 Nov 4, 2025
29 checks passed
@DrTimothyAldenDavis
Copy link
Owner

The update works on my desktop ("hyper") but fails on my laptop ("slash").

The slash output:

slash $ make
( cd SuiteSparse_config && make )
make[1]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config'
( cd build && cmake  .. && cmake --build . --config Release -j8 )
-- Building SuiteSparse_config version: v7.12.0 (Nov 1, 2025)
-- The C compiler identification is GNU 13.3.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Source:           /home/davis/dev2/SuiteSparse/SuiteSparse_config 
-- Build:            /home/davis/dev2/SuiteSparse/SuiteSparse_config/build 
-- Install lib:      lib
-- Install include:  include/suitesparse
-- Install bin:      bin
-- Install pkg-file: lib
-- Install rpath:    $ORIGIN
-- Build   rpath:    
-- Build type:       Release 
-- Checking if Fortran is available and compatible with C/C++
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - /usr/bin/f95
-- The CXX compiler identification is GNU 13.3.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is GNU 13.3.0
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/f95 - skipped
-- Fortran:          enabled
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - NOTFOUND
-- CUDA:             not found
-- CUDA:             not enabled
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5") found components: C 
-- OpenMP C libraries: /usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.a 
-- SuiteSparse_config has OpenMP: ON
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Using clock_gettime without librt
-- Looking for Intel 32-bit BLAS
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - found
-- Found BLAS: /opt/intel/oneapi/mkl/2025.1/lib/libmkl_gf_lp64.so;/opt/intel/oneapi/mkl/2025.1/lib/libmkl_gnu_thread.so;/opt/intel/oneapi/mkl/2025.1/lib/libmkl_core.so;/usr/lib/gcc/x86_64-linux-gnu/13/libgomp.so;-lm;-ldl  
-- Found Intel10_64lp 32-bit BLAS
CMake Error at cmake_modules/SuiteSparse__blas_threading.cmake:78 (try_run):
  Unknown extension "" for file

    /home/davis/dev2/SuiteSparse/SuiteSparse_config

  try_compile() works only for enabled languages.  Currently these are:

    C CXX Fortran

  See project() command to enable other languages.
Call Stack (most recent call first):
  cmake_modules/SuiteSparseBLAS32.cmake:23 (include)
  cmake_modules/SuiteSparseBLAS.cmake:181 (include)
  CMakeLists.txt:121 (include)


CMake Error at cmake_modules/SuiteSparse__blas_threading.cmake:96 (message):
  BLAS: Intel MKL failed to compile
Call Stack (most recent call first):
  cmake_modules/SuiteSparseBLAS32.cmake:23 (include)
  cmake_modules/SuiteSparseBLAS.cmake:181 (include)
  CMakeLists.txt:121 (include)


-- Configuring incomplete, errors occurred!
make[1]: *** [Makefile:40: library] Error 1
make[1]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config'
make: *** [Makefile:33: library] Error 2

The "hyper" output:

hyper $ make
( cd build && cmake  .. && cmake --build . --config Release -j8 )
-- Building SuiteSparse_config version: v7.12.0 (Nov 1, 2025)
-- The C compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Source:           /home/davis/dev2/SuiteSparse/SuiteSparse_config 
-- Build:            /home/davis/dev2/SuiteSparse/SuiteSparse_config/build 
-- Install lib:      lib
-- Install include:  include/suitesparse
-- Install bin:      bin
-- Install pkg-file: lib
-- Install rpath:    $ORIGIN
-- Build   rpath:    
-- Build type:       Release 
-- Checking if Fortran is available and compatible with C/C++
-- Looking for a Fortran compiler
-- Looking for a Fortran compiler - /usr/bin/f95
-- The CXX compiler identification is GNU 11.4.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- The Fortran compiler identification is GNU 11.4.0
-- Detecting Fortran compiler ABI info
-- Detecting Fortran compiler ABI info - done
-- Check for working Fortran compiler: /usr/bin/f95 - skipped
-- Fortran:          enabled
-- Looking for a CUDA compiler
-- Looking for a CUDA compiler - NOTFOUND
-- CUDA:             not found
-- CUDA:             not enabled
-- Found OpenMP_C: -fopenmp (found version "4.5") 
-- Found OpenMP: TRUE (found version "4.5") found components: C 
-- OpenMP C libraries: /usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.a 
-- SuiteSparse_config has OpenMP: ON
-- Looking for clock_gettime
-- Looking for clock_gettime - found
-- Using clock_gettime without librt
-- Looking for Intel 32-bit BLAS
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Looking for Fortran sgemm
-- Looking for Fortran sgemm - found
-- Found BLAS: /home/davis/intel/oneapi/2025.2/lib/libmkl_gf_lp64.so;/home/davis/intel/oneapi/2025.2/lib/libmkl_gnu_thread.so;/home/davis/intel/oneapi/2025.2/lib/libmkl_core.so;/usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;-lm;-ldl  
-- Found Intel10_64lp 32-bit BLAS
-- BLAS: Intel MKL: multi-threaded (threads: 24)
-- BLAS libraries:      /home/davis/intel/oneapi/2025.2/lib/libmkl_gf_lp64.so;/home/davis/intel/oneapi/2025.2/lib/libmkl_gnu_thread.so;/home/davis/intel/oneapi/2025.2/lib/libmkl_core.so;/usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;-lm;-ldl 
-- BLAS linker flags:    
-- BLAS include:         
-- Detecting Fortran/C Interface
-- Detecting Fortran/C Interface - Found GLOBAL and MODULE mangling
-- C to Fortran calling protocol: 
--     SUITESPARSE_HAS_FORTRAN  : ON
--     FortranCInterface_GLOBAL_MACRO  : (name,NAME) name##_
--     FortranCInterface_GLOBAL__MACRO : (name,NAME) name##_
-- Looking for fmax
-- Looking for fmax - found
-- OpenMP C libraries:      /usr/lib/gcc/x86_64-linux-gnu/11/libgomp.so;/usr/lib/x86_64-linux-gnu/libpthread.a 
-- OpenMP C include:         
-- OpenMP C flags:          -fopenmp 
-- ------------------------------------------------------------------------
-- SuiteSparse CMAKE report for: SuiteSparseConfig
-- ------------------------------------------------------------------------
-- inside common SuiteSparse root:  OFF
-- install in SuiteSparse/lib and SuiteSparse/include: OFF
-- build type:           Release
-- BUILD_SHARED_LIBS:    ON
-- BUILD_STATIC_LIBS:    ON
-- C compiler:           /usr/bin/cc 
-- C flags:              
-- C++ compiler:         /usr/bin/c++
-- C++ flags:            
-- C Flags release:      -O3 -DNDEBUG 
-- C++ Flags release:    -O3 -DNDEBUG 
-- Fortran compiler:     /usr/bin/f95 
-- compile definitions:  BLAS_Intel10_64lp;BLAS_Intel10
-- BLAS integer:         int32_t
-- ------------------------------------------------------------------------
-- CMAKE_SYSTEM_PROCESSOR: x86_64
-- Configuring done
-- Generating done
-- Build files have been written to: /home/davis/dev2/SuiteSparse/SuiteSparse_config/build
gmake[1]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[2]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[3]: Entering directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
[ 25%] Building C object CMakeFiles/SuiteSparseConfig.dir/SuiteSparse_config.c.o
[ 50%] Building C object CMakeFiles/SuiteSparseConfig_static.dir/SuiteSparse_config.c.o
[ 75%] Linking C shared library libsuitesparseconfig.so
[100%] Linking C static library libsuitesparseconfig.a
gmake[3]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
[100%] Built target SuiteSparseConfig
gmake[3]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
[100%] Built target SuiteSparseConfig_static
gmake[2]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'
gmake[1]: Leaving directory '/home/davis/dev2/SuiteSparse/SuiteSparse_config/build'

@DrTimothyAldenDavis
Copy link
Owner

Should line this be "${ABS_SOURCE_PATH}"?

@mmuetzel
Copy link
Contributor Author

mmuetzel commented Nov 4, 2025

Should line this be "${ABS_SOURCE_PATH}"?

Oops. That should be it indeed.
I don't have the Intel MKL installed currently. So, I didn't hit that in my tests.

@mmuetzel
Copy link
Contributor Author

mmuetzel commented Nov 4, 2025

I don't think it would be possible to check if these functions exist at run time.

Unfortunately, that isn't possible cross-platform.

But it should be possible to use proc = dlsym(RTLD_DEFAULT, "symbol_name"); to get a procedure entry point for a symbol in any of the currently loaded libraries on Linux and macOS.

On Windows, that's a bit more complicated. But you could use something like the following:

#include <windows.h>
#include <psapi.h>

[...]

    FARPROC proc = NULL;
    HMODULE hMods[1024];
    DWORD cbNeeded;
    HANDLE hProcess = GetCurrentProcess();

    if (EnumProcessModules(hProcess, hMods, sizeof(hMods), &cbNeeded)) {
        for (unsigned int i = 0; i < cbNeeded / sizeof(HMODULE); ++i) {
            proc = GetProcAddress(hMods[i], "symbol_name");
            if (proc) {
                break;
            }
        }
    }

(That assumes that no more than 1024 libraries are loaded at the same time...)

In both cases, proc should be a NULL pointer if no symbol of that name can be found in any of the loaded libraries. And you should be able to cast it to the appropriate function pointer otherwise.

@DrTimothyAldenDavis
Copy link
Owner

Should line this be "${ABS_SOURCE_PATH}"?

Oops. That should be it indeed. I don't have the Intel MKL installed currently. So, I didn't hit that in my tests.

No worries -- I can fix it. My tests on the "hyper" desktop passed by mistake; I forgot the "git pull" to bring in this latest update. With the "git pull" it fails the same way as my laptop, and with the fix to this line, it works.

I was surprised it passed on my desktop but failed on my laptop since I have the MKL on both systems. But it was just a mistake; they both failed.

I made the change just now and it works on my desktop with MKL now. (see 0b3ea61 ).

I will release a SuiteSparse 7.12.1 with this update, so it can work in flatpak (issue #1008).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

build error: check_openblas_Apr2024.c is defined as an output multiple times

2 participants