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

Refactor C build #315

Merged
merged 5 commits into from
Dec 23, 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
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
162 changes: 0 additions & 162 deletions c/_phono3py.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 3 additions & 2 deletions c/lapack_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down
29 changes: 18 additions & 11 deletions c/lapack_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +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;
#else
#include <mkl.h>
#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 <complex.h>
#define lapack_complex_double double _Complex
#ifdef CMPLX
Expand All @@ -45,18 +59,11 @@
#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 <lapacke.h>
#endif

#if defined(MKL_BLAS) || defined(SCIPY_MKL_H)
#include <mkl.h>
#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 <lapacke.h>
#endif

lapack_complex_double phonoc_complex_prod(const lapack_complex_double a,
Expand Down
31 changes: 0 additions & 31 deletions c/phono3py.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Loading