From 2cff0c97e3ef85b892b409525792c64390b05672 Mon Sep 17 00:00:00 2001 From: peekxc Date: Tue, 12 Dec 2023 12:30:29 -0500 Subject: [PATCH] re-arranging omp support options --- include/_lanczos/lanczos.h | 12 ++------ include/_random_generator/vector_generator.h | 9 +----- include/omp_support.h | 13 +++++++++ meson.build | 10 +++++-- meson.options | 29 ++++++++++---------- pyproject.toml | 2 +- src/primate/_lanczos.cpp | 1 - 7 files changed, 40 insertions(+), 36 deletions(-) create mode 100644 include/omp_support.h diff --git a/include/_lanczos/lanczos.h b/include/_lanczos/lanczos.h index cfe9ba4..8e7a58b 100644 --- a/include/_lanczos/lanczos.h +++ b/include/_lanczos/lanczos.h @@ -1,19 +1,11 @@ #include #include // function #include // max +#include "omp_support.h" // conditionally enables openmp pragmas #include "_linear_operator/linear_operator.h" // LinearOperator #include "_orthogonalize/orthogonalize.h" // orth_vector, mod #include "_random_generator/vector_generator.h" // ThreadSafeRBG, generate_array - -#ifdef _OPENMP - #include // omp_set_num_threads, omp_get_thread_num -#else - #define omp_get_thread_num() 0 - #define omp_set_num_threads() 0 - #define omp_get_max_threads() 1 -#endif - -#include +#include "eigen_core.h" #include #include diff --git a/include/_random_generator/vector_generator.h b/include/_random_generator/vector_generator.h index 4968886..e049d3c 100644 --- a/include/_random_generator/vector_generator.h +++ b/include/_random_generator/vector_generator.h @@ -1,18 +1,11 @@ #ifndef _RANDOM_GENERATOR_RANDOM_ARRAY_GENERATOR_H_ #define _RANDOM_GENERATOR_RANDOM_ARRAY_GENERATOR_H_ -#ifdef _OPENMP - #include // omp_set_num_threads, omp_get_thread_num -#else - #define omp_get_thread_num() 0 - #define omp_set_num_threads() 0 - #define omp_get_max_threads() 1 -#endif - #include // uniform_random_bit_generator, normal_distribution #include // uint64_t #include // isnan #include // bitset +#include "omp_support.h" // conditionally enables openmp pragmas #include "threadedrng64.h" // ThreadSafeRBG #include "rne_engines.h" // all the engines diff --git a/include/omp_support.h b/include/omp_support.h new file mode 100644 index 0000000..ffee824 --- /dev/null +++ b/include/omp_support.h @@ -0,0 +1,13 @@ +#ifndef _OMP_SUPPORT_H +#define _OMP_SUPPORT_H + +#ifdef OMP_MULTITHREADED + #include // omp_set_num_threads, omp_get_thread_num +#else + #define omp_get_thread_num() 0 + #define omp_set_num_threads(x) 0 + #define omp_get_max_threads() 1 +#endif + + +#endif \ No newline at end of file diff --git a/meson.build b/meson.build index c137d62..95b0dc1 100644 --- a/meson.build +++ b/meson.build @@ -6,12 +6,18 @@ project( default_options : [ 'buildtype=debugoptimized', 'cpp_std=c++20', - 'warning_level=2', + 'warning_level=2', # 'blas=openblas', # 'lapack=openblas', 'pkgconfig.relocatable=true' ] ) +use_openmp = get_option('use_openmp') +if use_openmp + add_global_arguments('-DOMP_MULTITHREADED=1', language : 'cpp') + message('Compiling with OpenMP support') +endif + OS_platform = host_machine.system() env = environment() @@ -79,7 +85,7 @@ dependency_map = {} # subdir('blas') # Configure BLAS / LAPACK ## Include OpenMP (mandatory ; but exclude on windows because it's too difficult to link) -if OS_platform != 'windows' +if get_option('use_openmp') and OS_platform != 'windows' omp = dependency('openmp', required: false) openmp_flags = [] if omp.found() diff --git a/meson.options b/meson.options index a14f691..3c9a8b4 100644 --- a/meson.options +++ b/meson.options @@ -1,16 +1,17 @@ -option('blas', type: 'string', value: 'auto', - description: 'Option for BLAS library selection. By default, try to find any in the order given by `blas-order`') -option('lapack', type: 'string', value: 'auto', - description: 'Option for LAPACK library selection. By default, try to find any in the order given by `lapack-order`') -option('allow-noblas', type: 'boolean', value: false, - description: 'If set to true, allow building with (slow!) internal fallback routines') -option('blas-order', type: 'array', - value: ['accelerate', 'openblas', 'mkl', 'flexiblas', 'blis', 'blas']) -option('lapack-order', type: 'array', - value: ['accelerate', 'openblas', 'mkl', 'flexiblas', 'lapack']) -option('blas-symbol-suffix', type: 'string', value: 'auto', - description: 'BLAS and LAPACK symbol suffix to use, if any') -option('use-ilp64', type: 'boolean', value: false, - description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces') +option('use_openmp', type : 'boolean', value : false, description : 'Whether to compile with OpenMP support') +# option('blas', type: 'string', value: 'auto', +# description: 'Option for BLAS library selection. By default, try to find any in the order given by `blas-order`') +# option('lapack', type: 'string', value: 'auto', +# description: 'Option for LAPACK library selection. By default, try to find any in the order given by `lapack-order`') +# option('allow-noblas', type: 'boolean', value: false, +# description: 'If set to true, allow building with (slow!) internal fallback routines') +# option('blas-order', type: 'array', +# value: ['accelerate', 'openblas', 'mkl', 'flexiblas', 'blis', 'blas']) +# option('lapack-order', type: 'array', +# value: ['accelerate', 'openblas', 'mkl', 'flexiblas', 'lapack']) +# option('blas-symbol-suffix', type: 'string', value: 'auto', +# description: 'BLAS and LAPACK symbol suffix to use, if any') +# option('use-ilp64', type: 'boolean', value: false, +# description: 'Use ILP64 (64-bit integer) BLAS and LAPACK interfaces') # option('use_nanobind', type: 'boolean', value: false, # description: 'whether to create the bindings with nanobind') diff --git a/pyproject.toml b/pyproject.toml index 6d5d925..4762642 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ requires = ['meson-python', 'wheel', 'ninja', 'pybind11', 'numpy'] # 'pythran-op [project] name = "primate" -version = "0.2.5" +version = "0.2.6" readme = "README.md" classifiers = [ "Intended Audience :: Science/Research", diff --git a/src/primate/_lanczos.cpp b/src/primate/_lanczos.cpp index 3760419..ef8645c 100644 --- a/src/primate/_lanczos.cpp +++ b/src/primate/_lanczos.cpp @@ -179,7 +179,6 @@ void _lanczos_wrapper(py::module& m, const std::string suffix, WrapperFunc wrap return py::cast(output); }) .def("matvec", [](const MatrixFunction< F, WrapperType >& m, const py_array< F >& x, py_array< F >& y) -> void { - using VectorF = Eigen::Matrix< F, Dynamic, 1 >; m.matvec(x.data(), y.mutable_data()); }) // .def_method("__repr__", &MatrixFunction::eval)