MCPcopy Create free account
hub / github.com/NatronGitHub/Natron / adjustNumberOfThreads

Method adjustNumberOfThreads

Engine/OutputSchedulerThread.cpp:1503–1549  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1501
1502#ifndef NATRON_PLAYBACK_USES_THREAD_POOL
1503void
1504OutputSchedulerThread::adjustNumberOfThreads(int* newNThreads,
1505 int *lastNThreads)
1506{
1507 ///////////
1508 /////If we were analysing the CPU activity, now set the appropriate number of threads to render.
1509 int optimalNThreads;
1510
1511 ///How many parallel renders the user wants
1512 int userSettingParallelThreads = appPTR->getCurrentSettings()->getNumberOfParallelRenders();
1513
1514 ///How many threads are running in the application
1515 int runningThreads = appPTR->getNRunningThreads() + QThreadPool::globalInstance()->activeThreadCount();
1516
1517 ///How many current threads are used by THIS renderer
1518 int currentParallelRenders = getNRenderThreads();
1519
1520 *lastNThreads = currentParallelRenders;
1521
1522 if (userSettingParallelThreads == 0) {
1523 ///User wants it to be automatically computed, do a simple heuristic: launch as many parallel renders
1524 ///as there are cores
1525 optimalNThreads = appPTR->getHardwareIdealThreadCount();
1526 } else {
1527 optimalNThreads = userSettingParallelThreads;
1528 }
1529 optimalNThreads = std::max(1, optimalNThreads);
1530
1531
1532 if ( ( (runningThreads < optimalNThreads) && (currentParallelRenders < optimalNThreads) ) || (currentParallelRenders == 0) ) {
1533 ////////
1534 ///Launch 1 thread
1535 QMutexLocker l(&_imp->renderThreadsMutex);
1536
1537 _imp->appendRunnable( createRunnable() );
1538 *newNThreads = currentParallelRenders + 1;
1539 } else if ( (runningThreads > optimalNThreads) && (currentParallelRenders > optimalNThreads) ) {
1540 ////////
1541 ///Stop 1 thread
1542 stopRenderThreads(1);
1543 *newNThreads = currentParallelRenders - 1;
1544 } else {
1545 /////////
1546 ///Keep the current count
1547 *newNThreads = std::max(1, currentParallelRenders);
1548 }
1549}
1550
1551#endif // ifndef NATRON_PLAYBACK_USES_THREAD_POOL
1552

Callers

nothing calls this directly

Calls 6

maxFunction · 0.85
getCurrentSettingsMethod · 0.80
getNRunningThreadsMethod · 0.80
appendRunnableMethod · 0.80

Tested by

no test coverage detected