Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
address review
  • Loading branch information
alexbruy authored and nyalldawson committed Apr 24, 2023
1 parent a44bfac commit 1c1e460
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 56 deletions.
24 changes: 17 additions & 7 deletions python/core/auto_generated/processing/qgsprocessingcontext.sip.in
Expand Up @@ -611,28 +611,38 @@ for all temporary files created during algorithm execution.
.. versionadded:: 3.32
%End

int numberOfThreads() const;
int maximumThreads() const;
%Docstring
Returns the (optional) number of threads to use when running algorithms.

If set, this overrides the standard global Processing number of threads setting.
Note that if algorithm implementation does not support multhreaded execution, this
setting will be ignored.
.. warning::

.. seealso:: :py:func:`setNumberOfThreads`
Not all algorithms which support multithreaded execution will
respect this setting, depending on the multi-threading framework in use.
Multithreaded algorithms must check this value and adapt their thread
handling accordingly -- the setting will not be automatically applied.

.. seealso:: :py:func:`setMaximumThreads`

.. versionadded:: 3.32
%End

void setNumberOfThreads( int threads );
void setMaximumThreads( int threads );
%Docstring
Sets the (optional) number of ``threads`` to use when running algorithms.

If set, this overrides the standard global Processing number of threads setting.
Note that if algorithm implementation does not support multhreaded execution, this
setting will be ignored.

.. seealso:: :py:func:`numberOfThreads`
.. warning::

Not all algorithms which support multithreaded execution will
respect this setting, depending on the multi-threading framework in use.
Multithreaded algorithms must check this value and adapt their thread
handling accordingly -- the setting will not be automatically applied.

.. seealso:: :py:func:`maximumThreads`

.. versionadded:: 3.32
%End
Expand Down
2 changes: 1 addition & 1 deletion python/plugins/processing/algs/qgis/TilesXYZ.py
Expand Up @@ -252,7 +252,7 @@ def generate(self, writer, parameters, context, feedback):
self.tile_format = self.formats[self.parameterAsEnum(parameters, self.TILE_FORMAT, context)]
self.quality = self.parameterAsInt(parameters, self.QUALITY, context)
self.metatilesize = self.parameterAsInt(parameters, self.METATILESIZE, context)
self.maxThreads = context.numThreads()
self.maxThreads = context.maximumThreads()
try:
self.tile_width = self.parameterAsInt(parameters, self.TILE_WIDTH, context)
self.tile_height = self.parameterAsInt(parameters, self.TILE_HEIGHT, context)
Expand Down
2 changes: 1 addition & 1 deletion src/analysis/processing/pdal/qgspdalalgorithmbase.cpp
Expand Up @@ -90,7 +90,7 @@ void QgsPdalAlgorithmBase::applyCommonParameters( QStringList &arguments, QgsCoo

void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments, QgsProcessingContext &context )
{
const int numThreads = context.numberOfThreads();
const int numThreads = context.maximumThreads();

if ( numThreads )
{
Expand Down
8 changes: 4 additions & 4 deletions src/core/processing/qgsprocessingcontext.cpp
Expand Up @@ -157,14 +157,14 @@ void QgsProcessingContext::setTemporaryFolder( const QString &folder )
mTemporaryFolderOverride = folder;
}

int QgsProcessingContext::numberOfThreads() const
int QgsProcessingContext::maximumThreads() const
{
return mThreadsToUse;
return mMaximumThreads;
}

void QgsProcessingContext::setNumberOfThreads( int threads )
void QgsProcessingContext::setMaximumThreads( int threads )
{
mThreadsToUse = threads;
mMaximumThreads = threads;
}

QVariantMap QgsProcessingContext::exportToMap() const
Expand Down
24 changes: 15 additions & 9 deletions src/core/processing/qgsprocessingcontext.h
Expand Up @@ -101,7 +101,7 @@ class CORE_EXPORT QgsProcessingContext
mAreaUnit = other.mAreaUnit;
mLogLevel = other.mLogLevel;
mTemporaryFolderOverride = other.mTemporaryFolderOverride;
mThreadsToUse = other.mThreadsToUse;
mMaximumThreads = other.mMaximumThreads;
}

/**
Expand Down Expand Up @@ -684,14 +684,15 @@ class CORE_EXPORT QgsProcessingContext
/**
* Returns the (optional) number of threads to use when running algorithms.
*
* If set, this overrides the standard global Processing number of threads setting.
* Note that if algorithm implementation does not support multhreaded execution, this
* setting will be ignored.
* \warning Not all algorithms which support multithreaded execution will
* respect this setting, depending on the multi-threading framework in use.
* Multithreaded algorithms must check this value and adapt their thread
* handling accordingly -- the setting will not be automatically applied.
*
* \see setNumberOfThreads()
* \see setMaximumThreads()
* \since QGIS 3.32
*/
int numberOfThreads() const;
int maximumThreads() const;

/**
* Sets the (optional) number of \a threads to use when running algorithms.
Expand All @@ -700,10 +701,15 @@ class CORE_EXPORT QgsProcessingContext
* Note that if algorithm implementation does not support multhreaded execution, this
* setting will be ignored.
*
* \see numberOfThreads()
* \warning Not all algorithms which support multithreaded execution will
* respect this setting, depending on the multi-threading framework in use.
* Multithreaded algorithms must check this value and adapt their thread
* handling accordingly -- the setting will not be automatically applied.
*
* \see maximumThreads()
* \since QGIS 3.32
*/
void setNumberOfThreads( int threads );
void setMaximumThreads( int threads );

/**
* Exports the context's settings to a variant map.
Expand Down Expand Up @@ -762,7 +768,7 @@ class CORE_EXPORT QgsProcessingContext
LogLevel mLogLevel = DefaultLevel;

QString mTemporaryFolderOverride;
int mThreadsToUse = QThread::idealThreadCount();
int mMaximumThreads = QThread::idealThreadCount();

#ifdef SIP_RUN
QgsProcessingContext( const QgsProcessingContext &other );
Expand Down
8 changes: 4 additions & 4 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.cpp
Expand Up @@ -160,7 +160,7 @@ QgsProcessingAlgorithmDialogBase::QgsProcessingAlgorithmDialogBase( QWidget *par
mDistanceUnits = mContextOptionsWidget->distanceUnit();
mAreaUnits = mContextOptionsWidget->areaUnit();
mTemporaryFolderOverride = mContextOptionsWidget->temporaryFolder();
mNumberOfThreads = mContextOptionsWidget->numberOfThreads();
mMaximumThreads = mContextOptionsWidget->maximumThreads();
} );
}
}
Expand Down Expand Up @@ -870,7 +870,7 @@ void QgsProcessingAlgorithmDialogBase::applyContextOverrides( QgsProcessingConte
context->setDistanceUnit( mDistanceUnits );
context->setAreaUnit( mAreaUnits );
context->setTemporaryFolder( mTemporaryFolderOverride );
context->setNumberOfThreads( mNumberOfThreads );
context->setMaximumThreads( mMaximumThreads );
}
}

Expand Down Expand Up @@ -1027,7 +1027,7 @@ void QgsProcessingContextOptionsWidget::setFromContext( const QgsProcessingConte
whileBlocking( mDistanceUnitsCombo )->setCurrentIndex( mDistanceUnitsCombo->findData( QVariant::fromValue( context->distanceUnit() ) ) );
whileBlocking( mAreaUnitsCombo )->setCurrentIndex( mAreaUnitsCombo->findData( QVariant::fromValue( context->areaUnit() ) ) );
whileBlocking( mTemporaryFolderWidget )->setFilePath( context->temporaryFolder() );
whileBlocking( mThreadsSpinBox )->setValue( context->numberOfThreads() );
whileBlocking( mThreadsSpinBox )->setValue( context->maximumThreads() );
}

QgsFeatureRequest::InvalidGeometryCheck QgsProcessingContextOptionsWidget::invalidGeometryCheck() const
Expand All @@ -1050,7 +1050,7 @@ QString QgsProcessingContextOptionsWidget::temporaryFolder()
return mTemporaryFolderWidget->filePath();
}

int QgsProcessingContextOptionsWidget::numberOfThreads() const
int QgsProcessingContextOptionsWidget::maximumThreads() const
{
return mThreadsSpinBox->value();
}
Expand Down
4 changes: 2 additions & 2 deletions src/gui/processing/qgsprocessingalgorithmdialogbase.h
Expand Up @@ -477,7 +477,7 @@ class GUI_EXPORT QgsProcessingAlgorithmDialogBase : public QDialog, public QgsPr
Qgis::DistanceUnit mDistanceUnits = Qgis::DistanceUnit::Unknown;
Qgis::AreaUnit mAreaUnits = Qgis::AreaUnit::Unknown;
QString mTemporaryFolderOverride;
int mNumberOfThreads = QThread::idealThreadCount();
int mMaximumThreads = QThread::idealThreadCount();

QString formatHelp( QgsProcessingAlgorithm *algorithm );
void scrollToBottomOfLog();
Expand Down Expand Up @@ -570,7 +570,7 @@ class GUI_EXPORT QgsProcessingContextOptionsWidget : public QgsPanelWidget, priv
/**
* Returns the number of threads to use selected in the widget.
*/
int numberOfThreads() const;
int maximumThreads() const;
};

#endif
Expand Down

0 comments on commit 1c1e460

Please sign in to comment.