Skip to content

Commit

Permalink
re-arranging omp support options
Browse files Browse the repository at this point in the history
  • Loading branch information
peekxc committed Dec 12, 2023
1 parent acaac3b commit 2cff0c9
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 36 deletions.
12 changes: 2 additions & 10 deletions include/_lanczos/lanczos.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
#include <concepts>
#include <functional> // function
#include <algorithm> // 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.h> // 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 <Eigen/Core>
#include "eigen_core.h"
#include <Eigen/Eigenvalues>

#include <iostream>
Expand Down
9 changes: 1 addition & 8 deletions include/_random_generator/vector_generator.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,11 @@
#ifndef _RANDOM_GENERATOR_RANDOM_ARRAY_GENERATOR_H_
#define _RANDOM_GENERATOR_RANDOM_ARRAY_GENERATOR_H_

#ifdef _OPENMP
#include <omp.h> // 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 <random> // uniform_random_bit_generator, normal_distribution
#include <cstdint> // uint64_t
#include <cmath> // isnan
#include <bitset> // bitset
#include "omp_support.h" // conditionally enables openmp pragmas
#include "threadedrng64.h" // ThreadSafeRBG
#include "rne_engines.h" // all the engines

Expand Down
13 changes: 13 additions & 0 deletions include/omp_support.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#ifndef _OMP_SUPPORT_H
#define _OMP_SUPPORT_H

#ifdef OMP_MULTITHREADED
#include <omp.h> // 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
10 changes: 8 additions & 2 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
29 changes: 15 additions & 14 deletions meson.options
Original file line number Diff line number Diff line change
@@ -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')
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
1 change: 0 additions & 1 deletion src/primate/_lanczos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2cff0c9

Please sign in to comment.