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
58#ifndef _OPENMP
59public:
63 EigenThreadScope([[maybe_unused]] int num_threads) {}
64
65#else
66public:
70 EigenThreadScope([[maybe_unused]] int num_threads) : my_previous(Eigen::nbThreads()) {
71#ifdef IRLBA_CUSTOM_PARALLEL
72#ifdef IRLBA_CUSTOM_PARALLEL_USES_OPENMP
73 Eigen::setNbThreads(num_threads);
74#else
75 Eigen::setNbThreads(1);
76#endif
77#else
78#ifdef SUBPAR_USES_OPENMP_SIMPLE
79 Eigen::setNbThreads(num_threads);
80#else
81 Eigen::setNbThreads(1);
82#endif
83#endif
84 }
85
86private:
87 int my_previous;
88
89public:
90 ~EigenThreadScope() {
91 Eigen::setNbThreads(my_previous);
92 }
93#endif
94
95public:
99 EigenThreadScope(const EigenThreadScope&) = delete;
101 EigenThreadScope& operator=(const EigenThreadScope&) = delete;
102 EigenThreadScope& operator=(EigenThreadScope&&) = delete;
106};
107
108}
109
110#endif
Restrict the number of available threads for Eigen.
Definition parallel.hpp:57
EigenThreadScope(int num_threads)
Definition parallel.hpp:63
Implements IRLBA for approximate SVD.
Definition compute.hpp:22
void parallelize(Task_ num_tasks, Run_ run_task)
Definition parallel.hpp:33