From be5d2dd30c9ee249ba11be32679f9eabe95821e7 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 14:17:06 +0900 Subject: [PATCH 1/5] Set BUILD_WITHOUT_LAPACKE=ON as default --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index c178490f..3b2ad2ac 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -52,7 +52,7 @@ sdist.include = [ PHONO3PY_USE_MTBLAS = {env="PHONO3PY_USE_MTBLAS", default="ON"} USE_CONDA_PATH = {env="USE_CONDA_PATH", default="ON"} PHONO3PY_USE_OMP = {env="PHONO3PY_USE_OMP", default="ON"} -BUILD_WITHOUT_LAPACKE = {env="BUILD_WITHOUT_LAPACKE", default="OFF"} +BUILD_WITHOUT_LAPACKE = {env="BUILD_WITHOUT_LAPACKE", default="ON"} [tool.setuptools_scm] write_to = "phono3py/_version.py" From eb1ebe0cf29f5efbb91edeae32e7893fa6169d2a Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 14:43:32 +0900 Subject: [PATCH 2/5] Update CMakeLists.txt --- CMakeLists.txt | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 11dc20d1..0e46d3fa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -66,7 +66,9 @@ endif() message(STATUS "Build type: ${CMAKE_BUILD_TYPE}") message(STATUS "CMAKE_SYSTEM_PREFIX_PATH: ${CMAKE_SYSTEM_PREFIX_PATH}") -if(USE_CONDA_PATH AND DEFINED ENV{CONDA_PREFIX}) +if((NOT BUILD_WITHOUT_LAPACKE) + AND USE_CONDA_PATH + AND DEFINED ENV{CONDA_PREFIX}) message(STATUS "$ENV{CONDA_PREFIX}") set(CMAKE_MODULE_PATH $ENV{CONDA_PREFIX}) set(MY_INCLUDES $ENV{CONDA_PREFIX}/include ${PROJECT_SOURCE_DIR}/c) From 7b8f7a8d841de8634d583e670ad151a8a1b957a0 Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 15:20:16 +0900 Subject: [PATCH 3/5] Define complex for VC --- c/lapack_wrapper.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/c/lapack_wrapper.h b/c/lapack_wrapper.h index b18db54a..a2e30008 100644 --- a/c/lapack_wrapper.h +++ b/c/lapack_wrapper.h @@ -36,6 +36,20 @@ #define __lapack_wrapper_H__ #ifdef NO_INCLUDE_LAPACKE +#if defined(_MSC_VER) +typedef struct { + double real; + double imag; +} lapack_complex_double; +lapack_complex_double lapack_make_complex_double(double re, double im) { + lapack_complex_double c; + c.real = re; + c.imag = im; + return c; +} +#define lapack_complex_double_real(z) ((z).real) +#define lapack_complex_double_imag(z) ((z).imag) +#else #include #define lapack_complex_double double _Complex #ifdef CMPLX @@ -46,6 +60,7 @@ #define lapack_complex_double_real(z) (creal(z)) #define lapack_complex_double_imag(z) (cimag(z)) #endif +#endif #if defined(MKL_BLAS) || defined(SCIPY_MKL_H) #include From 71dcf8410835fd57a453290cfaa156e2d331374d Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 15:45:51 +0900 Subject: [PATCH 4/5] Define complex for VC --- c/lapack_wrapper.c | 5 +++-- c/lapack_wrapper.h | 28 ++++++++++------------------ 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/c/lapack_wrapper.c b/c/lapack_wrapper.c index 166e2000..f8838cb1 100644 --- a/c/lapack_wrapper.c +++ b/c/lapack_wrapper.c @@ -38,7 +38,7 @@ #define min(a, b) ((a) > (b) ? (b) : (a)) -#if (defined(MKL_BLAS) || defined(SCIPY_MKL_H)) && !defined(NO_INCLUDE_LAPACKE) +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) lapack_complex_double lapack_make_complex_double(double re, double im) { lapack_complex_double z; z.real = re; @@ -47,7 +47,8 @@ lapack_complex_double lapack_make_complex_double(double re, double im) { } #endif -#if defined(MKL_BLAS) || defined(SCIPY_MKL_H) || defined(NO_INCLUDE_LAPACKE) +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) || \ + defined(NO_INCLUDE_LAPACKE) #ifndef LAPACKE_malloc #define LAPACKE_malloc(size) malloc(size) #endif diff --git a/c/lapack_wrapper.h b/c/lapack_wrapper.h index a2e30008..2c4178a4 100644 --- a/c/lapack_wrapper.h +++ b/c/lapack_wrapper.h @@ -35,21 +35,21 @@ #ifndef __lapack_wrapper_H__ #define __lapack_wrapper_H__ -#ifdef NO_INCLUDE_LAPACKE +#if defined(_MSC_VER) || defined(MKL_BLAS) || defined(SCIPY_MKL_H) #if defined(_MSC_VER) typedef struct { double real; double imag; } lapack_complex_double; -lapack_complex_double lapack_make_complex_double(double re, double im) { - lapack_complex_double c; - c.real = re; - c.imag = im; - return c; -} +#else +#include +#define lapack_complex_double MKL_Complex16 +#endif +lapack_complex_double lapack_make_complex_double(double re, double im); #define lapack_complex_double_real(z) ((z).real) #define lapack_complex_double_imag(z) ((z).imag) #else +#if defined(NO_INCLUDE_LAPACKE) #include #define lapack_complex_double double _Complex #ifdef CMPLX @@ -59,19 +59,11 @@ lapack_complex_double lapack_make_complex_double(double re, double im) { #endif #define lapack_complex_double_real(z) (creal(z)) #define lapack_complex_double_imag(z) (cimag(z)) +#else +#if !defined(MKL_BLAS) && !defined(SCIPY_MKL_H) +#include #endif #endif - -#if defined(MKL_BLAS) || defined(SCIPY_MKL_H) -#include -#define lapack_complex_double MKL_Complex16 -MKL_Complex16 lapack_make_complex_double(double re, double im); -#define lapack_complex_double_real(z) ((z).real) -#define lapack_complex_double_imag(z) ((z).imag) -#endif - -#if !defined(MKL_BLAS) && !defined(SCIPY_MKL_H) && !defined(NO_INCLUDE_LAPACKE) -#include #endif lapack_complex_double phonoc_complex_prod(const lapack_complex_double a, From 0b677509b9969ee29a39213a6a6eb5f906b66aaa Mon Sep 17 00:00:00 2001 From: Atsushi Togo Date: Mon, 23 Dec 2024 16:04:55 +0900 Subject: [PATCH 5/5] Remove unnecessary functions from _phono3py.cpp and phono3py.h --- c/_phono3py.cpp | 162 ------------------------------------------------ c/phono3py.h | 31 --------- 2 files changed, 193 deletions(-) diff --git a/c/_phono3py.cpp b/c/_phono3py.cpp index a7017d66..52e7ff14 100644 --- a/c/_phono3py.cpp +++ b/c/_phono3py.cpp @@ -887,168 +887,6 @@ void py_get_triplets_integration_weights_with_sigma( num_triplets, frequencies, num_band, num_iw); } -long py_get_grid_index_from_address(nb::ndarray<> py_address, - nb::ndarray<> py_D_diag) { - long *address; - long *D_diag; - long gp; - - address = (long *)py_address.data(); - D_diag = (long *)py_D_diag.data(); - - gp = ph3py_get_grid_index_from_address(address, D_diag); - - return gp; -} - -long py_get_ir_grid_map(nb::ndarray<> py_grid_mapping_table, - nb::ndarray<> py_D_diag, nb::ndarray<> py_is_shift, - nb::ndarray<> py_rotations) { - long *D_diag; - long *is_shift; - long(*rot)[3][3]; - long num_rot; - - long *grid_mapping_table; - long num_ir; - - D_diag = (long *)py_D_diag.data(); - is_shift = (long *)py_is_shift.data(); - rot = (long(*)[3][3])py_rotations.data(); - num_rot = (long)py_rotations.shape(0); - grid_mapping_table = (long *)py_grid_mapping_table.data(); - - num_ir = ph3py_get_ir_grid_map(grid_mapping_table, D_diag, is_shift, rot, - num_rot); - return num_ir; -} - -void py_get_gr_grid_addresses(nb::ndarray<> py_gr_grid_addresses, - nb::ndarray<> py_D_diag) { - long(*gr_grid_addresses)[3]; - long *D_diag; - - gr_grid_addresses = (long(*)[3])py_gr_grid_addresses.data(); - D_diag = (long *)py_D_diag.data(); - - ph3py_get_gr_grid_addresses(gr_grid_addresses, D_diag); -} - -long py_get_reciprocal_rotations(nb::ndarray<> py_rec_rotations, - nb::ndarray<> py_rotations, - long is_time_reversal) { - long(*rec_rotations)[3][3]; - long(*rotations)[3][3]; - long num_rot, num_rec_rot; - - rec_rotations = (long(*)[3][3])py_rec_rotations.data(); - rotations = (long(*)[3][3])py_rotations.data(); - num_rot = (long)py_rotations.shape(0); - - num_rec_rot = ph3py_get_reciprocal_rotations(rec_rotations, rotations, - num_rot, is_time_reversal); - - return num_rec_rot; -} - -bool py_transform_rotations(nb::ndarray<> py_transformed_rotations, - nb::ndarray<> py_rotations, nb::ndarray<> py_D_diag, - nb::ndarray<> py_Q) { - long(*transformed_rotations)[3][3]; - long(*rotations)[3][3]; - long *D_diag; - long(*Q)[3]; - long num_rot, succeeded; - - transformed_rotations = (long(*)[3][3])py_transformed_rotations.data(); - rotations = (long(*)[3][3])py_rotations.data(); - D_diag = (long *)py_D_diag.data(); - Q = (long(*)[3])py_Q.data(); - num_rot = (long)py_transformed_rotations.shape(0); - - succeeded = ph3py_transform_rotations(transformed_rotations, rotations, - num_rot, D_diag, Q); - if (succeeded) { - return true; - } else { - return false; - } -} - -bool py_get_snf3x3(nb::ndarray<> py_D_diag, nb::ndarray<> py_P, - nb::ndarray<> py_Q, nb::ndarray<> py_A) { - long *D_diag; - long(*P)[3]; - long(*Q)[3]; - long(*A)[3]; - long succeeded; - - D_diag = (long *)py_D_diag.data(); - P = (long(*)[3])py_P.data(); - Q = (long(*)[3])py_Q.data(); - A = (long(*)[3])py_A.data(); - - succeeded = ph3py_get_snf3x3(D_diag, P, Q, A); - if (succeeded) { - return true; - } else { - return false; - } -} - -long py_get_bz_grid_addresses(nb::ndarray<> py_bz_grid_addresses, - nb::ndarray<> py_bz_map, nb::ndarray<> py_bzg2grg, - nb::ndarray<> py_D_diag, nb::ndarray<> py_Q, - nb::ndarray<> py_PS, - nb::ndarray<> py_reciprocal_lattice, long type) { - long(*bz_grid_addresses)[3]; - long *bz_map; - long *bzg2grg; - long *D_diag; - long(*Q)[3]; - long *PS; - double(*reciprocal_lattice)[3]; - long num_total_gp; - - bz_grid_addresses = (long(*)[3])py_bz_grid_addresses.data(); - bz_map = (long *)py_bz_map.data(); - bzg2grg = (long *)py_bzg2grg.data(); - D_diag = (long *)py_D_diag.data(); - Q = (long(*)[3])py_Q.data(); - PS = (long *)py_PS.data(); - reciprocal_lattice = (double(*)[3])py_reciprocal_lattice.data(); - - num_total_gp = - ph3py_get_bz_grid_addresses(bz_grid_addresses, bz_map, bzg2grg, D_diag, - Q, PS, reciprocal_lattice, type); - - return num_total_gp; -} - -long py_rotate_bz_grid_addresses(long bz_grid_index, nb::ndarray<> py_rotation, - nb::ndarray<> py_bz_grid_addresses, - nb::ndarray<> py_bz_map, - nb::ndarray<> py_D_diag, nb::ndarray<> py_PS, - long type) { - long(*bz_grid_addresses)[3]; - long(*rotation)[3]; - long *bz_map; - long *D_diag; - long *PS; - long ret_bz_gp; - - bz_grid_addresses = (long(*)[3])py_bz_grid_addresses.data(); - rotation = (long(*)[3])py_rotation.data(); - bz_map = (long *)py_bz_map.data(); - D_diag = (long *)py_D_diag.data(); - PS = (long *)py_PS.data(); - - ret_bz_gp = ph3py_rotate_bz_grid_index( - bz_grid_index, rotation, bz_grid_addresses, bz_map, D_diag, PS, type); - - return ret_bz_gp; -} - long py_get_default_colmat_solver() { #if defined(MKL_BLAS) || defined(SCIPY_MKL_H) || !defined(NO_INCLUDE_LAPACKE) return (long)1; diff --git a/c/phono3py.h b/c/phono3py.h index 54247e24..351a7c3f 100644 --- a/c/phono3py.h +++ b/c/phono3py.h @@ -176,37 +176,6 @@ void ph3py_get_integration_weight_with_sigma( const double *frequency_points, const long num_band0, const long (*triplets)[3], const long num_triplets, const double *frequencies, const long num_band, const long tp_type); -long ph3py_get_grid_index_from_address(const long address[3], - const long mesh[3]); -void ph3py_get_gr_grid_addresses(long gr_grid_addresses[][3], - const long D_diag[3]); -long ph3py_get_reciprocal_rotations(long rec_rotations[48][3][3], - const long (*rotations)[3][3], - const long num_rot, - const long is_time_reversal); -long ph3py_transform_rotations(long (*transformed_rots)[3][3], - const long (*rotations)[3][3], - const long num_rot, const long D_diag[3], - const long Q[3][3]); -long ph3py_get_snf3x3(long D_diag[3], long P[3][3], long Q[3][3], - const long A[3][3]); -long ph3py_transform_rotations(long (*transformed_rots)[3][3], - const long (*rotations)[3][3], - const long num_rot, const long D_diag[3], - const long Q[3][3]); -long ph3py_get_ir_grid_map(long *ir_grid_map, const long D_diag[3], - const long PS[3], const long (*grg_rotations)[3][3], - const long num_rot); -long ph3py_get_bz_grid_addresses(long (*bz_grid_addresses)[3], long *bz_map, - long *bzg2grg, const long D_diag[3], - const long Q[3][3], const long PS[3], - const double rec_lattice[3][3], - const long type); -long ph3py_rotate_bz_grid_index(const long bz_grid_index, - const long rotation[3][3], - const long (*bz_grid_addresses)[3], - const long *bz_map, const long D_diag[3], - const long PS[3], const long bz_grid_type); void ph3py_symmetrize_collision_matrix(double *collision_matrix, const long num_column, const long num_temp,