diff --git a/src/app/qgsoptions.cpp b/src/app/qgsoptions.cpp index ecb43859297..0c372a8c7ec 100644 --- a/src/app/qgsoptions.cpp +++ b/src/app/qgsoptions.cpp @@ -548,6 +548,10 @@ QgsOptions::QgsOptions( QWidget *parent, Qt::WindowFlags fl ) : chkUseRenderCaching->setChecked( settings.value( "/qgis/enable_render_caching", false ).toBool() ); chkParallelRendering->setChecked( settings.value( "/qgis/parallel_rendering", false ).toBool() ); spinMapUpdateInterval->setValue( settings.value( "/qgis/map_update_interval", 250 ).toInt() ); + chkMaxCores->setChecked( settings.value( "/qgis/max_cores", 0 ).toInt() != 0 ); + spinMaxCores->setEnabled( chkMaxCores->isChecked() ); + spinMaxCores->setRange( 1, QThread::idealThreadCount() ); + spinMaxCores->setValue( settings.value( "/qgis/max_cores", QThread::idealThreadCount() ).toInt() ); // Default simplify drawing configuration mSimplifyDrawingGroupBox->setChecked( settings.value( "/qgis/simplifyDrawingHints", ( int )QgsVectorSimplifyMethod::GeometrySimplification ).toInt() != QgsVectorSimplifyMethod::NoSimplification ); @@ -1072,6 +1076,10 @@ void QgsOptions::saveOptions() settings.setValue( "/qgis/enable_anti_aliasing", chkAntiAliasing->isChecked() ); settings.setValue( "/qgis/enable_render_caching", chkUseRenderCaching->isChecked() ); settings.setValue( "/qgis/parallel_rendering", chkParallelRendering->isChecked() ); + if ( chkMaxCores->isChecked() ) + settings.setValue( "/qgis/max_cores", int( spinMaxCores->value() ) ); + else + settings.remove( "/qgis/max_cores" ); settings.setValue( "/qgis/map_update_interval", spinMapUpdateInterval->value() ); settings.setValue( "/qgis/legendDoubleClickAction", cmbLegendDoubleClickAction->currentIndex() ); bool legendLayersCapitalise = settings.value( "/qgis/capitaliseLayerName", false ).toBool(); diff --git a/src/core/qgsmaprendererjob.cpp b/src/core/qgsmaprendererjob.cpp index 3ffe21390cd..8642a39d93c 100644 --- a/src/core/qgsmaprendererjob.cpp +++ b/src/core/qgsmaprendererjob.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include "qgscrscache.h" #include "qgslogger.h" @@ -731,6 +732,14 @@ void QgsMapRendererParallelJob::start() mLayerJobs = prepareJobs( 0, mLabelingEngine ); + // set max thread count + QSettings settings; + int max_cores = settings.value( "/qgis/max_cores", 0 ).toInt(); + if ( max_cores <= 0 || max_cores > QThread::idealThreadCount() ) + max_cores = QThread::idealThreadCount(); + QThreadPool::globalInstance()->setMaxThreadCount( max_cores ); + qDebug( "set max thread count to %d", QThreadPool::globalInstance()->maxThreadCount() ); + // start async job connect( &mFutureWatcher, SIGNAL( finished() ), SLOT( renderLayersFinished() ) ); @@ -829,6 +838,10 @@ QImage QgsMapRendererParallelJob::renderedImage() void QgsMapRendererParallelJob::renderLayersFinished() { + // restore max thread count + QThreadPool::globalInstance()->setMaxThreadCount( QThread::idealThreadCount() ); + qDebug( "restored max thread count to ideal (%d)", QThreadPool::globalInstance()->maxThreadCount() ); + Q_ASSERT( mStatus == RenderingLayers ); // compose final image diff --git a/src/ui/qgsoptionsbase.ui b/src/ui/qgsoptionsbase.ui index c4229db442b..c4c0fe23d04 100644 --- a/src/ui/qgsoptionsbase.ui +++ b/src/ui/qgsoptionsbase.ui @@ -1629,11 +1629,45 @@ - - - Render layers in parallel using all available CPU cores - - + + + + + Render layers in parallel using many CPU cores + + + + + + + Qt::Vertical + + + + + + + Max cores to use: + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + @@ -4598,5 +4632,21 @@ + + chkMaxCores + toggled(bool) + spinMaxCores + setEnabled(bool) + + + 589 + 110 + + + 689 + 110 + + +