mirror of
https://git.mirrors.martin98.com/https://github.com/prusa3d/PrusaSlicer.git
synced 2025-07-28 12:42:02 +08:00
Add option cmd option to limit the number of threads
This commit is contained in:
parent
6bd9c50c7a
commit
eff53d4dba
@ -817,7 +817,13 @@ bool CLI::setup(int argc, char **argv)
|
|||||||
if (opt_loglevel != 0)
|
if (opt_loglevel != 0)
|
||||||
set_logging_level(opt_loglevel->value);
|
set_logging_level(opt_loglevel->value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
const ConfigOptionInt *opt_threads = m_config.opt<ConfigOptionInt>("threads");
|
||||||
|
if (opt_threads != nullptr)
|
||||||
|
thread_count = opt_threads->value;
|
||||||
|
}
|
||||||
|
|
||||||
//FIXME Validating at this stage most likely does not make sense, as the config is not fully initialized yet.
|
//FIXME Validating at this stage most likely does not make sense, as the config is not fully initialized yet.
|
||||||
std::string validity = m_config.validate();
|
std::string validity = m_config.validate();
|
||||||
|
|
||||||
|
@ -5066,6 +5066,11 @@ CLIMiscConfigDef::CLIMiscConfigDef()
|
|||||||
def->label = L("Data directory");
|
def->label = L("Data directory");
|
||||||
def->tooltip = L("Load and store settings at the given directory. This is useful for maintaining different profiles or including configurations from a network storage.");
|
def->tooltip = L("Load and store settings at the given directory. This is useful for maintaining different profiles or including configurations from a network storage.");
|
||||||
|
|
||||||
|
def = this->add("threads", coInt);
|
||||||
|
def->label = L("Maximum number of threads");
|
||||||
|
def->tooltip = L("Sets the maximum number of threads the slicing process will use. If not defined, slic3r will decide.");
|
||||||
|
def->min = 1;
|
||||||
|
|
||||||
def = this->add("loglevel", coInt);
|
def = this->add("loglevel", coInt);
|
||||||
def->label = L("Logging level");
|
def->label = L("Logging level");
|
||||||
def->tooltip = L("Sets logging sensitivity. 0:fatal, 1:error, 2:warning, 3:info, 4:debug, 5:trace\n"
|
def->tooltip = L("Sets logging sensitivity. 0:fatal, 1:error, 2:warning, 3:info, 4:debug, 5:trace\n"
|
||||||
|
@ -235,12 +235,11 @@ void name_tbb_thread_pool_threads_set_locale()
|
|||||||
// const size_t nthreads_hw = std::thread::hardware_concurrency();
|
// const size_t nthreads_hw = std::thread::hardware_concurrency();
|
||||||
const size_t nthreads_hw = tbb::this_task_arena::max_concurrency();
|
const size_t nthreads_hw = tbb::this_task_arena::max_concurrency();
|
||||||
size_t nthreads = nthreads_hw;
|
size_t nthreads = nthreads_hw;
|
||||||
|
if (thread_count) {
|
||||||
|
nthreads = std::min(nthreads_hw, *thread_count);
|
||||||
|
}
|
||||||
|
|
||||||
#if 0
|
enforce_thread_count(nthreads);
|
||||||
// Shiny profiler is not thread safe, thus disable parallelization.
|
|
||||||
disable_multi_threading();
|
|
||||||
nthreads = 1;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
size_t nthreads_running(0);
|
size_t nthreads_running(0);
|
||||||
std::condition_variable cv;
|
std::condition_variable cv;
|
||||||
|
@ -21,6 +21,7 @@ namespace boost { namespace filesystem { class directory_entry; }}
|
|||||||
|
|
||||||
namespace Slic3r {
|
namespace Slic3r {
|
||||||
|
|
||||||
|
inline std::optional<std::size_t> thread_count;
|
||||||
extern void set_logging_level(unsigned int level);
|
extern void set_logging_level(unsigned int level);
|
||||||
extern unsigned get_logging_level();
|
extern unsigned get_logging_level();
|
||||||
// Format memory allocated, separate thousands by comma.
|
// Format memory allocated, separate thousands by comma.
|
||||||
@ -29,7 +30,7 @@ extern std::string format_memsize_MB(size_t n);
|
|||||||
// The string is non-empty if the loglevel >= info (3) or ignore_loglevel==true.
|
// The string is non-empty if the loglevel >= info (3) or ignore_loglevel==true.
|
||||||
// Latter is used to get the memory info from SysInfoDialog.
|
// Latter is used to get the memory info from SysInfoDialog.
|
||||||
extern std::string log_memory_info(bool ignore_loglevel = false);
|
extern std::string log_memory_info(bool ignore_loglevel = false);
|
||||||
extern void disable_multi_threading();
|
extern void enforce_thread_count(std::size_t count);
|
||||||
// Returns the size of physical memory (RAM) in bytes.
|
// Returns the size of physical memory (RAM) in bytes.
|
||||||
extern size_t total_physical_memory();
|
extern size_t total_physical_memory();
|
||||||
|
|
||||||
|
@ -123,15 +123,15 @@ unsigned get_logging_level()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void disable_multi_threading()
|
void enforce_thread_count(const std::size_t count)
|
||||||
{
|
{
|
||||||
// Disable parallelization to simplify debugging.
|
// Disable parallelization to simplify debugging.
|
||||||
#ifdef TBB_HAS_GLOBAL_CONTROL
|
#ifdef TBB_HAS_GLOBAL_CONTROL
|
||||||
{
|
{
|
||||||
static tbb::global_control gc(tbb::global_control::max_allowed_parallelism, 1);
|
static tbb::global_control gc(tbb::global_control::max_allowed_parallelism, count);
|
||||||
}
|
}
|
||||||
#else // TBB_HAS_GLOBAL_CONTROL
|
#else // TBB_HAS_GLOBAL_CONTROL
|
||||||
static tbb::task_scheduler_init *tbb_init = new tbb::task_scheduler_init(1);
|
static tbb::task_scheduler_init *tbb_init = new tbb::task_scheduler_init(count);
|
||||||
UNUSED(tbb_init);
|
UNUSED(tbb_init);
|
||||||
#endif // TBB_HAS_GLOBAL_CONTROL
|
#endif // TBB_HAS_GLOBAL_CONTROL
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user