Skip to content

Commit

Permalink
add option to set max thread count
Browse files Browse the repository at this point in the history
  • Loading branch information
etiennesky committed May 16, 2014
1 parent 16cc66a commit 9001c47
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/app/qgsoptions.cpp
Expand Up @@ -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 );
Expand Down Expand Up @@ -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();
Expand Down
13 changes: 13 additions & 0 deletions src/core/qgsmaprendererjob.cpp
Expand Up @@ -5,6 +5,7 @@
#include <QTime>
#include <QTimer>
#include <QtConcurrentMap>
#include <QSettings>

#include "qgscrscache.h"
#include "qgslogger.h"
Expand Down Expand Up @@ -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() ) );
Expand Down Expand Up @@ -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
Expand Down
60 changes: 55 additions & 5 deletions src/ui/qgsoptionsbase.ui
Expand Up @@ -1629,11 +1629,45 @@
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkParallelRendering">
<property name="text">
<string>Render layers in parallel using all available CPU cores</string>
</property>
</widget>
<layout class="QHBoxLayout" name="horizontalLayout_26">
<item>
<widget class="QCheckBox" name="chkParallelRendering">
<property name="text">
<string>Render layers in parallel using many CPU cores</string>
</property>
</widget>
</item>
<item>
<widget class="Line" name="line_6">
<property name="orientation">
<enum>Qt::Vertical</enum>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="chkMaxCores">
<property name="text">
<string>Max cores to use:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinMaxCores"/>
</item>
<item>
<spacer name="horizontalSpacer_41">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_4">
Expand Down Expand Up @@ -4598,5 +4632,21 @@
</hint>
</hints>
</connection>
<connection>
<sender>chkMaxCores</sender>
<signal>toggled(bool)</signal>
<receiver>spinMaxCores</receiver>
<slot>setEnabled(bool)</slot>
<hints>
<hint type="sourcelabel">
<x>589</x>
<y>110</y>
</hint>
<hint type="destinationlabel">
<x>689</x>
<y>110</y>
</hint>
</hints>
</connection>
</connections>
</ui>

0 comments on commit 9001c47

Please sign in to comment.