irlba
A C++ library for IRLBA
Loading...
Searching...
No Matches
parallel.hpp
Go to the documentation of this file.
1#ifndef IRLBA_PARALLEL_HPP
2#define IRLBA_PARALLEL_HPP
3
4#include "utils.hpp"
5#include <vector>
6#include "Eigen/Dense"
7
8#ifndef IRLBA_CUSTOM_PARALLEL
9#include "subpar/subpar.hpp"
10#endif
11
18namespace irlba {
19
32template<typename Task_, class Run_>
33void parallelize(Task_ num_tasks, Run_ run_task) {
34#ifndef IRLBA_CUSTOM_PARALLEL
35 // Use cases here don't allocate or throw, so nothrow_ = true is fine.
36 subpar::parallelize_simple<true>(num_tasks, std::move(run_task));
37#else
38 IRLBA_CUSTOM_PARALLEL(num_tasks, run_task);
39#endif
40}
41
59#ifndef _OPENMP
60public:
64 EigenThreadScope([[maybe_unused]] int num_threads) {}
65
66#else
67public:
71 EigenThreadScope([[maybe_unused]] int num_threads) : my_previous(Eigen::nbThreads()) {
72#ifdef IRLBA_CUSTOM_PARALLEL
73#ifdef IRLBA_CUSTOM_PARALLEL_USES_OPENMP
74 Eigen::setNbThreads(num_threads);
75#else
76 Eigen::setNbThreads(1);
77#endif
78#else
79#ifdef SUBPAR_USES_OPENMP_SIMPLE
80 Eigen::setNbThreads(num_threads);
81#else
82 Eigen::setNbThreads(1);
83#endif
84#endif
85 }
86
87private:
88 int my_previous;
89
90public:
91 ~EigenThreadScope() {
92 Eigen::setNbThreads(my_previous);
93 }
94#endif
95
96public:
100 EigenThreadScope(const EigenThreadScope&) = delete;
102 EigenThreadScope& operator=(const EigenThreadScope&) = delete;
103 EigenThreadScope& operator=(EigenThreadScope&&) = delete;
107};
108
109}
110
111#endif
Restrict the number of available threads for Eigen.
Definition parallel.hpp:58
EigenThreadScope(int num_threads)
Definition parallel.hpp:64
void parallelize(Task_ num_tasks, Run_ run_task)
Definition parallel.hpp:33