Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release version 3.0.2 #221

Merged
merged 5 commits into from
Apr 21, 2024
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
46 changes: 46 additions & 0 deletions .github/workflows/phono3py-pytest-conda-mkl-phphmtblas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Pytest with mkl sing BLAS for phph-calc

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@v3
# Use conda-incubator/setup-miniconda for precise control of conda infrastructure
- uses: conda-incubator/setup-miniconda@v2
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 "libblas=*=*openblas" openblas h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler
conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
cd phonopy
PHONOPY_USE_OPENMP=true pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
conda activate test
PHPHCALC_USE_MTBLAS=true pip install -e . -vvv
- name: Run pytest
run: |
pytest -v --cov=./ --cov-report=xml test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
verbose: true
10 changes: 2 additions & 8 deletions .github/workflows/phono3py-pytest-conda-mkl-v2.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ name: Pytest with mkl and --v2 option
on:
pull_request:
branches: [ develop ]
push:
branches-ignore:
- publish-gh-pages
- develop
- master
- rc

jobs:
build-linux:
Expand All @@ -18,7 +12,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +31,7 @@ jobs:
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
PHONOPY_USE_OPENMP=true pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
Expand Down
10 changes: 2 additions & 8 deletions .github/workflows/phono3py-pytest-conda-mkl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ name: Pytest with mkl
on:
pull_request:
branches: [ develop ]
push:
branches-ignore:
- publish-gh-pages
- develop
- master
- rc

jobs:
build-linux:
Expand All @@ -18,7 +12,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.11"]
python-version: ["3.12"]

steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +31,7 @@ jobs:
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
PHONOPY_USE_OPENMP=true pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
Expand Down
46 changes: 46 additions & 0 deletions .github/workflows/phono3py-pytest-conda-phphmtblas.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Pytest with openblas using BLAS for phph-calc

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@v3
# Use conda-incubator/setup-miniconda for precise control of conda infrastructure
- uses: conda-incubator/setup-miniconda@v2
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 "libblas=*=*openblas" openblas h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler
#conda install --yes matplotlib-base pyyaml "libblas=*=*mkl" mkl-include h5py scipy pytest codecov pytest-cov spglib alm cmake c-compiler
- name: Install phonopy develop branch
run: |
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
cd phonopy
PHONOPY_USE_OPENMP=true pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
conda activate test
PHPHCALC_USE_MTBLAS=true pip install -e . -vvv
- name: Run pytest
run: |
pytest -v --cov=./ --cov-report=xml test
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v3
with:
verbose: true
10 changes: 2 additions & 8 deletions .github/workflows/phono3py-pytest-conda.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,6 @@ name: Pytest with openblas
on:
pull_request:
branches: [ develop ]
push:
branches-ignore:
- publish-gh-pages
- develop
- master
- rc

jobs:
build-linux:
Expand All @@ -18,7 +12,7 @@ jobs:
shell: bash -l {0}
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11"]
python-version: ["3.9", "3.10", "3.11", "3.12"]

steps:
- uses: actions/checkout@v3
Expand All @@ -37,7 +31,7 @@ jobs:
conda activate test
git clone --depth 1 https://github.com/phonopy/phonopy.git
cd phonopy
pip install -e . -vvv
PHONOPY_USE_OPENMP=true pip install -e . -vvv
cd ..
- name: Install phono3py
run: |
Expand Down
57 changes: 43 additions & 14 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
cmake_minimum_required(VERSION 3.15)
project(phono3py C)

option(PHONO3PY "Option to build phono3py module" OFF)
option(PHPHCALC "Option to build phph calculation module" OFF)
option(PHONONCALC "Option to build phonon calculation module" OFF)
option(GRIDSYS "Option to build gridsys module" OFF)
option(WITH_Fortran "enable fortran interface" OFF)
option(USE_OpenMP "Option to search OpenMP library" ON)
option(PHONO3PY_USE_OMP "Option to search OpenMP library" ON)
option(PHPHCALC_USE_MTBLAS "Use multithread BLAS is it exists" OFF)
option(WITH_TESTS "build unit tests" OFF)
option(BUILD_SHARED_LIBRARIES "Option to build shared library" OFF)
if(WITH_Fortran)
Expand Down Expand Up @@ -51,7 +52,7 @@ else()
set(MY_INCLUDES ${PROJECT_SOURCE_DIR}/c)
endif()

if(USE_OpenMP)
if(PHONO3PY_USE_OMP)
message(STATUS "Find OpenMP library")
find_package(OpenMP)

Expand All @@ -61,7 +62,7 @@ if(USE_OpenMP)
endif()
endif()

if(PHONO3PY OR PHONONCALC)
if(PHPHCALC OR PHONONCALC)
find_package(BLAS REQUIRED) # set BLAS_LIBRARIES

if(BLAS_FOUND)
Expand All @@ -77,22 +78,30 @@ if(PHONO3PY OR PHONONCALC)
endif()
endif()

if(PHONO3PY OR PHONONCALC)
if(PHPHCALC OR PHONONCALC)
if(BLAS_LIBRARIES MATCHES "libmkl")
message(STATUS "MKL detected: Set C-macros MKL_LAPACKE MULTITHREADED_BLAS")
message(STATUS "Use multithreaded BLAS for phonon calculation.")
if(PHPHCALC_USE_MTBLAS)
message(STATUS "Use multithreaded BLAS for ph-ph calculation.")
endif()
endif()

if(BLAS_LIBRARIES MATCHES "libopenblas")
message(STATUS "OpenBLAS detected: Set C-macro MULTITHREADED_BLAS")
message(STATUS "Use multithreaded BLAS for phonon calculation.")
if(PHPHCALC_USE_MTBLAS)
message(STATUS "Use multithreaded BLAS for ph-ph calculation.")
endif()
endif()
endif()

# ##############################################################################
# phono3py #
# ##############################################################################
if(PHONO3PY)
if(PHPHCALC)
# Source code
set(SOURCES_PHONO3PY
set(SOURCES_PHPHCALC
${PROJECT_SOURCE_DIR}/c/bzgrid.c
${PROJECT_SOURCE_DIR}/c/collision_matrix.c
${PROJECT_SOURCE_DIR}/c/fc3.c
Expand All @@ -116,18 +125,28 @@ if(PHONO3PY)

if(BUILD_SHARED_LIBRARIES)
# Shared library
add_library(ph3py SHARED ${SOURCES_PHONO3PY})
add_library(ph3py SHARED ${SOURCES_PHPHCALC})
target_link_libraries(ph3py m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(ph3py PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py PRIVATE ${OpenMP_C_FLAGS})

if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(ph3py PRIVATE MKL_LAPACKE MULTITHREADED_BLAS
THM_EPSILON=1e-10)
else()
target_compile_definitions(ph3py PRIVATE MKL_LAPACKE THM_EPSILON=1e-10)
endif()
endif()

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

set_property(TARGET ph3py PROPERTY VERSION ${SERIAL})
Expand All @@ -136,19 +155,29 @@ if(PHONO3PY)
endif()

# Static link library
add_library(ph3py_static STATIC ${SOURCES_PHONO3PY})
add_library(ph3py_static STATIC ${SOURCES_PHPHCALC})
target_link_libraries(ph3py_static m ${BLAS_LIBRARIES} ${LAPACK_LIBRARIES}
${OpenMP_C_LIBRARIES})
target_include_directories(ph3py_static PRIVATE ${MY_INCLUDES})
target_compile_options(ph3py_static PRIVATE ${OpenMP_C_FLAGS})

if(BLAS_LIBRARIES MATCHES "libmkl")
target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
if(PHPHCALC_USE_MTBLAS)
target_compile_definitions(
ph3py_static PRIVATE MKL_LAPACKE MULTITHREADED_BLAS THM_EPSILON=1e-10)
else()
target_compile_definitions(ph3py_static PRIVATE MKL_LAPACKE
THM_EPSILON=1e-10)
endif()
endif()

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

set_property(TARGET ph3py_static PROPERTY VERSION ${SERIAL})
Expand Down
10 changes: 10 additions & 0 deletions c/reciprocal_to_normal.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,13 @@

#include "reciprocal_to_normal.h"

#ifdef MULTITHREADED_BLAS
#if defined(MKL_LAPACKE) || defined(SCIPY_MKL_H)
#include <mkl_cblas.h>
#else
#include <cblas.h>
#endif
#endif
#include <math.h>
#include <stdlib.h>
#include <string.h>
Expand All @@ -55,11 +57,13 @@ static double get_fc3_sum(const lapack_complex_double *e0,
const lapack_complex_double *e2,
const lapack_complex_double *fc3_reciprocal,
const long num_band);
#ifdef MULTITHREADED_BLAS
static double get_fc3_sum_blas(const lapack_complex_double *e0,
const lapack_complex_double *e1,
const lapack_complex_double *e2,
const lapack_complex_double *fc3_reciprocal,
const long num_band);
#endif
static double get_fc3_sum_blas_like(const lapack_complex_double *e0,
const lapack_complex_double *e1,
const lapack_complex_double *e2,
Expand Down Expand Up @@ -153,6 +157,7 @@ void reciprocal_to_normal_squared(
if (freqs0[band_indices[g_pos[i][0]]] > cutoff_frequency &&
freqs1[g_pos[i][1]] > cutoff_frequency &&
freqs2[g_pos[i][2]] > cutoff_frequency) {
#ifdef MULTITHREADED_BLAS
if (use_multithreaded_blas) {
fc3_normal_squared[g_pos[i][3]] =
get_fc3_sum_blas(e0 + band_indices[g_pos[i][0]] * num_band,
Expand All @@ -162,14 +167,17 @@ void reciprocal_to_normal_squared(
(freqs0[band_indices[g_pos[i][0]]] * freqs1[g_pos[i][1]] *
freqs2[g_pos[i][2]]);
} else {
#endif
fc3_normal_squared[g_pos[i][3]] =
get_fc3_sum_blas_like(
e0 + band_indices[g_pos[i][0]] * num_band,
e1 + g_pos[i][1] * num_band,
e2 + g_pos[i][2] * num_band, fc3_reciprocal, num_band) /
(freqs0[band_indices[g_pos[i][0]]] * freqs1[g_pos[i][1]] *
freqs2[g_pos[i][2]]);
#ifdef MULTITHREADED_BLAS
}
#endif
} else {
fc3_normal_squared[g_pos[i][3]] = 0;
}
Expand Down Expand Up @@ -224,6 +232,7 @@ static double get_fc3_sum(const lapack_complex_double *e0,
return (sum_real * sum_real + sum_imag * sum_imag);
}

#ifdef MULTITHREADED_BLAS
static double get_fc3_sum_blas(const lapack_complex_double *e0,
const lapack_complex_double *e1,
const lapack_complex_double *e2,
Expand Down Expand Up @@ -259,6 +268,7 @@ static double get_fc3_sum_blas(const lapack_complex_double *e0,
lapack_complex_double_imag(retval) *
lapack_complex_double_imag(retval);
}
#endif

static double get_fc3_sum_blas_like(const lapack_complex_double *e0,
const lapack_complex_double *e1,
Expand Down
Loading
Loading