qualpal 2.3.0
Loading...
Searching...
No Matches
threads.h
Go to the documentation of this file.
1
6#pragma once
7
8#include <stdexcept>
9
10#ifdef _OPENMP
11#include <omp.h>
12#endif
13
14namespace qualpal {
15
34{
35public:
41 static void set(const std::size_t n)
42 {
43 if (n > 0) {
44 num_threads = n;
45#ifdef _OPENMP
46 omp_set_num_threads(n);
47#endif
48 } else {
49 throw std::invalid_argument("Number of threads must be positive");
50 }
51 }
52
58 static std::size_t get() { return num_threads; }
59
60private:
61#ifdef _OPENMP
64 inline static std::size_t num_threads =
65 std::max(1, omp_get_max_threads() / 2);
66#else
68 inline static std::size_t num_threads = 1;
69#endif
70};
71
72} // namespace qualpal
Manages OpenMP thread settings across qualpal.
Definition threads.h:34
static void set(const std::size_t n)
Set the number of threads to use for parallel computations.
Definition threads.h:41
static std::size_t get()
Get the current number of threads.
Definition threads.h:58
Qualitative color palette generation library.
Definition analyze.h:19