qualpal 3.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
39{
40public:
48 static void set(const std::size_t n)
49 {
50 if (n > 0) {
51 num_threads = n;
52#ifdef _OPENMP
53 omp_set_num_threads(n);
54#endif
55 } else {
56 throw std::invalid_argument("Number of threads must be positive");
57 }
58 }
59
65 static std::size_t get() { return num_threads; }
66
67private:
68#ifdef _OPENMP
72 inline static std::size_t num_threads =
73 std::max(1, omp_get_max_threads() / 2);
74#else
76 inline static std::size_t num_threads = 1;
77#endif
78};
79
80} // namespace qualpal
Centralized management of thread settings for parallel computations.
Definition threads.h:39
static void set(const std::size_t n)
Set the number of threads to use for parallel computations.
Definition threads.h:48
static std::size_t get()
Get the current number of threads used for parallel computations.
Definition threads.h:65
Qualitative color palette generation library.
Definition analyze.h:21