OpenShot Library | libopenshot
1.1.1
Toggle main menu visibility
Loading...
Searching...
No Matches
Settings.cpp
Go to the documentation of this file.
1
8
9
// Copyright (c) 2008-2019 OpenShot Studios, LLC
10
//
11
// SPDX-License-Identifier: LGPL-3.0-or-later
12
13
#include <algorithm>
14
#include <cstdlib>
15
#include <omp.h>
16
#include "
Settings.h
"
17
18
using namespace
openshot
;
19
20
// Global reference to Settings
21
Settings
*Settings::m_pInstance =
nullptr
;
22
23
int
Settings::EffectiveOMPThreads
()
const
24
{
25
return
std::clamp(
OMP_THREADS
, 2,
MaxAllowedThreads
());
26
}
27
28
int
Settings::MaxAllowedThreads
()
const
29
{
30
return
std::max(2, std::max(2, omp_get_num_procs()) * 3);
31
}
32
33
void
Settings::ApplyOpenMPSettings
()
34
{
35
const
int
requested_threads =
EffectiveOMPThreads
();
36
if
(applied_omp_threads != requested_threads) {
37
omp_set_num_threads(requested_threads);
38
applied_omp_threads = requested_threads;
39
}
40
}
41
42
// Create or Get an instance of the settings singleton
43
Settings *
Settings::Instance
()
44
{
45
if
(!m_pInstance) {
46
// Create the actual instance of Settings only once
47
m_pInstance =
new
Settings;
48
const
int
machine_threads = std::max(2, omp_get_num_procs());
49
m_pInstance->default_omp_threads = machine_threads;
50
m_pInstance->default_ff_threads = machine_threads;
51
m_pInstance->OMP_THREADS = machine_threads;
52
m_pInstance->FF_THREADS = machine_threads;
53
auto
env_debug = std::getenv(
"LIBOPENSHOT_DEBUG"
);
54
if
(env_debug !=
nullptr
)
55
m_pInstance->DEBUG_TO_STDERR =
true
;
56
}
57
58
m_pInstance->
ApplyOpenMPSettings
();
59
60
return
m_pInstance;
61
}
Settings.h
Header file for global Settings class.
openshot::Settings
This class is contains settings used by libopenshot (and can be safely toggled at any point).
Definition
Settings.h:26
openshot::Settings::OMP_THREADS
int OMP_THREADS
Number of OpenMP threads.
Definition
Settings.h:77
openshot::Settings::MaxAllowedThreads
int MaxAllowedThreads() const
Return the maximum allowed thread override based on this machine.
Definition
Settings.cpp:28
openshot::Settings::ApplyOpenMPSettings
void ApplyOpenMPSettings()
Apply any explicit OpenMP thread override to the runtime.
Definition
Settings.cpp:33
openshot::Settings::Instance
static Settings * Instance()
Create or get an instance of this logger singleton (invoke the class with this method).
Definition
Settings.cpp:43
openshot::Settings::EffectiveOMPThreads
int EffectiveOMPThreads() const
Return the effective OpenMP worker budget used by libopenshot heuristics.
Definition
Settings.cpp:23
openshot
This namespace is the default namespace for all code in the openshot library.
Definition
AnimatedCurve.h:24
Settings.cpp
Generated by
1.17.0