Skip to content
This repository was archived by the owner on Dec 17, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 1 addition & 4 deletions .github/workflows/CI_PublishTestPyPI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,13 @@ jobs:
CIBW_BUILD_VERBOSITY: 1
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_28"
CIBW_BUILD: "${{ matrix.py_tag }}-*"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.deployment_target || '11.0' }} SPARSEIR_USE_BLAS=1"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.deployment_target || '11.0' }}"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_SKIP: "*-manylinux_i686 *-musllinux_i686"
# Install OpenBLAS using micromamba (conda-forge) - separate for manylinux and musllinux
CIBW_BEFORE_ALL_MANYLINUX: "curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba && ./bin/micromamba create -y -p /opt/openblas && ./bin/micromamba install -y -c conda-forge openblas -p /opt/openblas --no-deps"
CIBW_BEFORE_ALL_MUSLLINUX: "apk add --no-cache bzip2 && curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba && ./bin/micromamba create -y -p /opt/openblas && ./bin/micromamba install -y -c conda-forge openblas -p /opt/openblas --no-deps"
CIBW_BEFORE_ALL_MACOS: "brew install openblas"
# Set environment variables to help CMake find OpenBLAS
CIBW_ENVIRONMENT_MANYLINUX: "SPARSEIR_USE_BLAS=1"
CIBW_ENVIRONMENT_MUSLLINUX: "SPARSEIR_USE_BLAS=1"
with:
package-dir: ./python
output-dir: dist
Expand Down
5 changes: 1 addition & 4 deletions .github/workflows/PublishPyPI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,13 @@ jobs:
CIBW_BUILD_VERBOSITY: 1
CIBW_MANYLINUX_X86_64_IMAGE: "manylinux_2_28"
CIBW_BUILD: "${{ matrix.py_tag }}-*"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.deployment_target || '11.0' }} SPARSEIR_USE_BLAS=1"
CIBW_ENVIRONMENT_MACOS: "MACOSX_DEPLOYMENT_TARGET=${{ matrix.deployment_target || '11.0' }}"
CIBW_ARCHS: ${{ matrix.cibw_archs }}
CIBW_SKIP: "*-manylinux_i686 *-musllinux_i686"
# Install OpenBLAS using micromamba (conda-forge) - separate for manylinux and musllinux
CIBW_BEFORE_ALL_MANYLINUX: "curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba && ./bin/micromamba create -y -p /opt/openblas && ./bin/micromamba install -y -c conda-forge openblas -p /opt/openblas --no-deps"
CIBW_BEFORE_ALL_MUSLLINUX: "apk add --no-cache bzip2 && curl -Ls https://micro.mamba.pm/api/micromamba/linux-64/latest | tar -xvj bin/micromamba && ./bin/micromamba create -y -p /opt/openblas && ./bin/micromamba install -y -c conda-forge openblas -p /opt/openblas --no-deps"
CIBW_BEFORE_ALL_MACOS: "brew install openblas"
# Set environment variables to help CMake find OpenBLAS
CIBW_ENVIRONMENT_MANYLINUX: "SPARSEIR_USE_BLAS=1"
CIBW_ENVIRONMENT_MUSLLINUX: "SPARSEIR_USE_BLAS=1"
with:
package-dir: ./python
output-dir: dist
Expand Down
39 changes: 37 additions & 2 deletions .github/workflows/test_cxx_backend.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test C++ Backend

on:
push:
branches: [ "main", "459-restructure-directories" ]
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
Expand Down Expand Up @@ -40,9 +40,44 @@ jobs:
working-directory: capi_sample
run: ./run_sample.sh

test-cxx-backend-ilp64:
runs-on: ubuntu-latest
name: C++ backend with ILP64 BLAS
timeout-minutes: 60 # Allow up to 60 minutes for ILP64 tests

steps:
- uses: actions/checkout@v5

- name: Install dependencies with ILP64 BLAS
run: |
sudo apt update && sudo apt install -y libeigen3-dev libopenblas64-0 libopenblas64-dev

- name: Build and test C++ backend with ILP64
working-directory: backend/cxx
run: |
rm -rf build
mkdir -p build && cd build
cmake .. -DSPARSEIR_BUILD_TESTING=ON -DSPARSEIR_USE_BLAS_ILP64=ON
cmake --build . -j$(nproc)
ctest --output-on-failure --verbose -j$(nproc)

- name: Build and test capi_test against ILP64 backend
working-directory: capi_test
env:
SPARSEIR_USE_BLAS_ILP64: 1
run: ./test_with_cxx_backend.sh

- name: Build and run capi_sample with ILP64
working-directory: capi_sample
env:
SPARSEIR_USE_BLAS_ILP64: 1
run: ./run_sample.sh

test-cxx-backend-rollup:
runs-on: ubuntu-latest
needs: test-cxx-backend
needs:
- test-cxx-backend
- test-cxx-backend-ilp64
if: always()
steps:
- name: All tests passed
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test_fortran.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Test Fortran Bindings

on:
push:
branches: [ "main", "459-restructure-directories" ]
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
Expand Down
19 changes: 4 additions & 15 deletions .github/workflows/test_python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ on:
push:
branches:
- main
- 459-restructure-directories
pull_request:
branches:
- main
Expand Down Expand Up @@ -50,21 +49,11 @@ jobs:
with:
enable-cache: true

- name: Setup build environment
- name: Setup and run tests
working-directory: python
run: python3 setup_build.py

- name: Run uv sync
working-directory: python
run: uv sync
env:
SPARSEIR_USE_BLAS: 1

- name: Run tests
working-directory: python
run: uv run pytest tests/ -v
env:
SPARSEIR_USE_BLAS: 1
run: |
chmod +x run_tests.sh
./run_tests.sh

test-python-rollup:
runs-on: ubuntu-latest
Expand Down
104 changes: 35 additions & 69 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -49,65 +49,32 @@ endif()

# Eigen3
# BLAS/LAPACK options
option(SPARSEIR_USE_BLAS "Enable BLAS support" OFF)
option(SPARSEIR_USE_ILP64 "Enable ILP64 BLAS interface (requires SPARSEIR_USE_BLAS=ON)" OFF)

# BLAS/LAPACK search and configuration
if(SPARSEIR_USE_BLAS)
add_compile_definitions(SPARSEIR_USE_BLAS)
message(STATUS "BLAS support enabled")

# ILP64 support
if(SPARSEIR_USE_ILP64)
add_compile_definitions(SPARSEIR_USE_ILP64)
message(STATUS "ILP64 BLAS interface enabled")
else()
message(STATUS "LP64 BLAS interface enabled (default)")
endif()
option(SPARSEIR_USE_BLAS_ILP64 "Enable ILP64 BLAS interface (64-bit integers)" OFF)

# BLAS search and configuration (always enabled)
message(STATUS "BLAS support enabled")

# Set BLAS integer size based on SPARSEIR_USE_BLAS_ILP64
if(SPARSEIR_USE_BLAS_ILP64)
set(BLA_SIZEOF_INTEGER 8)
message(STATUS "Searching for ILP64 BLAS interface (64-bit integers)")
else()
set(BLA_SIZEOF_INTEGER 4)
message(STATUS "Searching for LP64 BLAS interface (32-bit integers, default)")
endif()

# Find BLAS package using standard CMake FindBLAS
find_package(BLAS REQUIRED)

# Find BLAS package
if(SPARSEIR_USE_ILP64)
# For ILP64, check if BLAS_LIBRARIES is already set by user
if(BLAS_LIBRARIES)
message(STATUS "ILP64 BLAS library specified: ${BLAS_LIBRARIES}")
# Verify the library exists
if(NOT EXISTS "${BLAS_LIBRARIES}")
message(FATAL_ERROR "Specified ILP64 BLAS library not found: ${BLAS_LIBRARIES}")
endif()
set(BLAS_FOUND TRUE)
else()
# Try to find ILP64 BLAS automatically
find_library(BLAS_LIBRARIES
NAMES openblas64
PATHS /usr/lib/x86_64-linux-gnu /usr/lib /usr/local/lib
NO_DEFAULT_PATH
)
if(BLAS_LIBRARIES)
message(STATUS "ILP64 BLAS found automatically: ${BLAS_LIBRARIES}")
set(BLAS_FOUND TRUE)
else()
message(FATAL_ERROR "ILP64 BLAS (libopenblas64) not found. You can specify it with -DBLAS_LIBRARIES=/path/to/libopenblas64.so")
endif()
endif()
if(BLAS_FOUND)
message(STATUS "BLAS found: ${BLAS_LIBRARIES}")
if(SPARSEIR_USE_BLAS_ILP64)
message(STATUS "BLAS with ILP64 interface (BLA_SIZEOF_INTEGER=8)")
else()
# For LP64, use standard CMake BLAS finder
find_package(BLAS REQUIRED)
if(BLAS_FOUND)
message(STATUS "BLAS found: ${BLAS_LIBRARIES}")
else()
message(FATAL_ERROR "BLAS not found")
endif()
message(STATUS "BLAS with LP64 interface (BLA_SIZEOF_INTEGER=4)")
endif()

# CMake's find_package(BLAS) should provide include directories
#if(BLAS_INCLUDE_DIRS)
#include_directories(${BLAS_INCLUDE_DIRS})
#message(STATUS "BLAS include directories: ${BLAS_INCLUDE_DIRS}")
#else()
#message(FATAL_ERROR "BLAS include directories not found")
#endif()
elseif(SPARSEIR_USE_ILP64)
message(FATAL_ERROR "SPARSEIR_USE_ILP64 requires SPARSEIR_USE_BLAS=ON")
else()
message(FATAL_ERROR "BLAS not found")
endif()


Expand Down Expand Up @@ -187,23 +154,22 @@ set_target_properties(sparseir PROPERTIES

target_link_libraries(sparseir PRIVATE Eigen3::Eigen Threads::Threads)

# Add BLAS/LAPACK linking
if(SPARSEIR_USE_BLAS)
if(SPARSEIR_USE_ILP64 OR BLAS_FOUND)
target_link_libraries(sparseir PRIVATE ${BLAS_LIBRARIES})
message(STATUS "Linked BLAS libraries: ${BLAS_LIBRARIES}")
else()
message(FATAL_ERROR "BLAS libraries not found")
# Add BLAS linking (always enabled)
# Link BLAS privately, but ensure it's not dropped by linker
# This allows dlopen/dlsym to find BLAS symbols at runtime
if(SPARSEIR_USE_BLAS_ILP64 OR BLAS_FOUND)
target_link_libraries(sparseir PRIVATE ${BLAS_LIBRARIES})
message(STATUS "Linked BLAS libraries: ${BLAS_LIBRARIES}")

# Ensure BLAS dependency is retained even if symbols are not directly used
# This is necessary for dynamic symbol resolution at runtime
if(NOT APPLE)
target_link_options(sparseir PRIVATE "LINKER:--no-as-needed")
endif()
else()
message(STATUS "BLAS linking disabled")
message(FATAL_ERROR "BLAS libraries not found - BLAS is required")
endif()

if(SPARSEIR_USE_LAPACKE AND LAPACK_FOUND)
target_link_libraries(sparseir PRIVATE ${LAPACK_LIBRARIES})
endif()


# macOS-specific configuration
if(APPLE AND ACCELERATE_FRAMEWORK)
target_link_libraries(sparseir PRIVATE ${ACCELERATE_FRAMEWORK})
Expand Down
Loading
Loading