tatami_python
R bindings to tatami matrices
Loading...
Searching...
No Matches
parallelize.hpp
Go to the documentation of this file.
1#ifndef TATAMI_PYTHON_PARALLELIZE_HPP
2#define TATAMI_PYTHON_PARALLELIZE_HPP
3
7#ifdef TATAMI_PYTHON_PARALLELIZE_UNKNOWN
12#include "pybind11/pybind11.h"
13#include "subpar/subpar.hpp"
14
15#include <optional>
16
17#ifndef TATAMI_PYTHON_SERIALIZE
21#define TATAMI_PYTHON_SERIALIZE ::tatami_python::lock
22#endif
23
29namespace tatami_python {
30
49template<class Function_, class Index_>
50void parallelize(const Function_ fun, const Index_ tasks, int threads) {
51 std::optional<pybind11::gil_scoped_release> ungil;
52 if (PyGILState_Check()) {
53 ungil.emplace();
54 }
55 subpar::parallelize_range(threads, tasks, std::move(fun));
56}
57
67template<typename Function_>
68void lock(Function_ fun) {
69 std::optional<pybind11::gil_scoped_acquire> gil;
70 if (!PyGILState_Check()) {
71 gil.emplace();
72 }
73 fun();
74}
75
76}
77
81#endif
86#endif
tatami bindings for arbitrary Python matrices.
void parallelize(const Function_ fun, const Index_ tasks, int threads)
Definition parallelize.hpp:50
void lock(Function_ fun)
Definition parallelize.hpp:68