Skip to content

Commit

Permalink
Merge branch 'develop' into publish-gh-pages
Browse files Browse the repository at this point in the history
  • Loading branch information
atztogo committed Nov 25, 2024
2 parents 237366e + 6578d07 commit 389ba8e
Show file tree
Hide file tree
Showing 28 changed files with 582 additions and 2,411 deletions.
42 changes: 42 additions & 0 deletions .github/workflows/phono3py-pytest-conda-nolapacke.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Pytest without linking BLAS and LAPACK in C

on:
pull_request:
branches: [ develop ]

jobs:
build-linux:
runs-on: ubuntu-latest
defaults:
run:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.12"]

steps:
- uses: actions/checkout@v4
# Use conda-incubator/setup-miniconda for precise control of conda infrastructure
- uses: conda-incubator/setup-miniconda@v3
with:
miniforge-version: latest
- name: Install dependent packages
run: |
conda activate test
conda install --yes python=${{ matrix.python-version }}
conda install --yes matplotlib-base pyyaml h5py scipy pytest spglib cmake c-compiler cxx-compiler
- name: Install phonopy develop branch
run: |
conda activate test
git clone https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
conda activate test
BUILD_WITHOUT_LAPACKE=ON pip install -e . -vvv
- name: Run pytest
run: |
conda activate test
pytest -v test
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ repos:
exclude: ^example/AlN-LDA/

- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.3
rev: v0.7.4
hooks:
- id: ruff
args: [ "--fix", "--show-fixes" ]
Expand Down
207 changes: 134 additions & 73 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ option(PHONO3PY_USE_OMP "Option to search OpenMP library" ON)
option(PHONO3PY_USE_MTBLAS "Use multithread BLAS if it exists" ON)
option(PHONO3PY_WITH_TESTS "build unit tests" OFF)
option(BUILD_SHARED_LIBS "Option to build shared library" OFF)
option(BUILD_WITHOUT_LAPACKE "Option to build without LAPACKE" ON)

if(PHONO3PY_WITH_Fortran)
enable_language(Fortran)
Expand Down Expand Up @@ -89,7 +90,8 @@ endif()

if(BUILD_PHPHCALC_LIB
OR BUILD_PHONONCALC_LIB
OR BUILD_NANOBIND_MODULE)
OR BUILD_NANOBIND_MODULE
AND (NOT BUILD_WITHOUT_LAPACKE))
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES

if(BLAS_FOUND)
Expand All @@ -105,7 +107,7 @@ if(BUILD_PHPHCALC_LIB
endif()

if(BLAS_LIBRARIES MATCHES "libmkl")
message(STATUS "MKL detected: Set C-macro MKL_LAPACKE.")
message(STATUS "MKL detected.")

if(PHONO3PY_USE_MTBLAS)
message(
Expand Down Expand Up @@ -190,68 +192,95 @@ if(BUILD_PHPHCALC_LIB OR BUILD_NANOBIND_MODULE)
# Shared library
add_library(phphcalc_lib SHARED ${SOURCES_PHPHCALC})

if(OpenMP_FOUND)
target_link_libraries(
phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
else()
target_link_libraries(phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS
LAPACK::LAPACK)
endif()

target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})

if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
if(BUILD_WITHOUT_LAPACKE)
if(OpenMP_FOUND)
target_link_libraries(phphcalc_lib PRIVATE recgrid_lib
OpenMP::OpenMP_C)
else()
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
target_link_libraries(phphcalc_lib PRIVATE recgrid_lib)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
target_compile_definitions(phphcalc_lib PRIVATE NO_INCLUDE_LAPACKE
THM_EPSILON=1e-10)
else()
if(OpenMP_FOUND)
target_link_libraries(
phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
else()
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
target_link_libraries(phphcalc_lib PRIVATE recgrid_lib BLAS::BLAS
LAPACK::LAPACK)
endif()
endif()
else()
# Static link library
add_library(phphcalc_lib STATIC ${SOURCES_PHPHCALC})

if(OpenMP_FOUND)
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
else()
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS LAPACK::LAPACK)
if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_BLAS MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib
PRIVATE MKL_BLAS THM_EPSILON=1e-10)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MULTITHREADED_BLAS THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib
PRIVATE THM_EPSILON=1e-10)
endif()
endif()
endif()

target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})

if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
# Static link library
add_library(phphcalc_lib STATIC ${SOURCES_PHPHCALC})

if(BUILD_WITHOUT_LAPACKE)
if(OpenMP_FOUND)
target_link_libraries(phphcalc_lib recgrid_lib OpenMP::OpenMP_C)
else()
target_compile_definitions(phphcalc_lib PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
target_link_libraries(phphcalc_lib recgrid_lib)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(phphcalc_lib PRIVATE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
target_compile_definitions(phphcalc_lib PRIVATE NO_INCLUDE_LAPACKE
THM_EPSILON=1e-10)
else()
if(OpenMP_FOUND)
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS
LAPACK::LAPACK OpenMP::OpenMP_C)
else()
target_compile_definitions(phphcalc_lib PRIVATE THM_EPSILON=1e-10)
target_link_libraries(phphcalc_lib recgrid_lib BLAS::BLAS
LAPACK::LAPACK)
endif()

if(BLAS_LIBRARIES MATCHES "libmkl")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MKL_BLAS MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib
PRIVATE MKL_BLAS THM_EPSILON=1e-10)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
if(PHONO3PY_USE_MTBLAS)
target_compile_definitions(
phphcalc_lib PRIVATE MULTITHREADED_BLAS THM_EPSILON=1e-10)
else()
target_compile_definitions(phphcalc_lib
PRIVATE THM_EPSILON=1e-10)
endif()
endif()
endif()

target_include_directories(phphcalc_lib PRIVATE ${MY_INCLUDES})
endif()

if(NOT BUILD_NANOBIND_MODULE)
Expand Down Expand Up @@ -285,45 +314,67 @@ if(BUILD_PHONONCALC_LIB OR BUILD_NANOBIND_MODULE)
# Shared library
add_library(phononcalc_lib SHARED ${SOURCES_PHONONCALC})

if(OpenMP_FOUND)
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
if(BUILD_WITHOUT_LAPACKE)
if(OpenMP_FOUND)
target_link_libraries(phononcalc_lib OpenMP::OpenMP_C)
else()
target_link_libraries(phononcalc_lib)
endif()

target_compile_definitions(phononcalc_lib PRIVATE NO_INCLUDE_LAPACKE)
else()
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK)
endif()
if(OpenMP_FOUND)
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
else()
target_link_libraries(phononcalc_lib BLAS::BLAS LAPACK::LAPACK)
endif()

target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_BLAS
MULTITHREADED_BLAS)
endif()

if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
MULTITHREADED_BLAS)
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})

else()
# Static link library
add_library(phononcalc_lib STATIC ${SOURCES_PHONONCALC})

if(OpenMP_FOUND)
target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
if(BUILD_WITHOUT_LAPACKE)
if(OpenMP_FOUND)
target_link_libraries(phononcalc_lib PRIVATE OpenMP::OpenMP_C)
else()
target_link_libraries(phononcalc_lib PRIVATE)
endif()

target_compile_definitions(phononcalc_lib PRIVATE NO_INCLUDE_LAPACKE)
else()
target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK)
endif()
if(OpenMP_FOUND)
target_link_libraries(
phononcalc_lib PRIVATE BLAS::BLAS LAPACK::LAPACK
OpenMP::OpenMP_C)
else()
target_link_libraries(phononcalc_lib PRIVATE BLAS::BLAS
LAPACK::LAPACK)
endif()

target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_BLAS
MULTITHREADED_BLAS)
endif()

if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(phononcalc_lib PRIVATE MKL_LAPACKE
MULTITHREADED_BLAS)
if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
target_compile_definitions(phononcalc_lib PRIVATE MULTITHREADED_BLAS)
endif()
target_include_directories(phononcalc_lib PRIVATE ${MY_INCLUDES})
endif()

if(NOT BUILD_NANOBIND_MODULE)
Expand Down Expand Up @@ -432,7 +483,17 @@ if(BUILD_NANOBIND_MODULE)
target_link_libraries(_phononcalc PRIVATE phononcalc_lib)
target_link_libraries(_recgrid PRIVATE recgrid_lib)

target_compile_definitions(_phono3py PRIVATE THM_EPSILON=1e-10)
if(BUILD_WITHOUT_LAPACKE)
target_compile_definitions(_phono3py PRIVATE NO_INCLUDE_LAPACKE
THM_EPSILON=1e-10)
else()
if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(_phono3py PRIVATE MKL_BLAS THM_EPSILON=1e-10)
else()
target_compile_definitions(_phono3py PRIVATE THM_EPSILON=1e-10)
endif()
endif()

install(TARGETS _phono3py LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
install(TARGETS _phononcalc LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
install(TARGETS _recgrid LIBRARY DESTINATION ${SKBUILD_PROJECT_NAME})
Expand Down
Loading

0 comments on commit 389ba8e

Please sign in to comment.