Skip to content

Commit a44bfac

Browse files
alexbruynyalldawson
authored andcommittedApr 24, 2023
use threads number setting in algorithms which support multiple CPUs
1 parent 8011030 commit a44bfac

18 files changed

+48
-37
lines changed
 

‎python/plugins/processing/algs/qgis/TilesXYZ.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ def generate(self, writer, parameters, context, feedback):
252252
self.tile_format = self.formats[self.parameterAsEnum(parameters, self.TILE_FORMAT, context)]
253253
self.quality = self.parameterAsInt(parameters, self.QUALITY, context)
254254
self.metatilesize = self.parameterAsInt(parameters, self.METATILESIZE, context)
255-
self.maxThreads = int(ProcessingConfig.getSetting(ProcessingConfig.MAX_THREADS))
255+
self.maxThreads = context.numThreads()
256256
try:
257257
self.tile_width = self.parameterAsInt(parameters, self.TILE_WIDTH, context)
258258
self.tile_height = self.parameterAsInt(parameters, self.TILE_HEIGHT, context)

‎src/analysis/processing/pdal/qgsalgorithmpdalboundary.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ QStringList QgsPdalBoundaryAlgorithm::createArgumentLists( const QVariantMap &pa
101101
}
102102

103103
applyCommonParameters( args, layer->crs(), parameters, context );
104-
applyThreadsParameter( args );
104+
applyThreadsParameter( args, context );
105105
return args;
106106
}
107107

‎src/analysis/processing/pdal/qgsalgorithmpdalbuildvpc.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ QStringList QgsPdalBuildVpcAlgorithm::createArgumentLists( const QVariantMap &pa
115115
args << "--overview";
116116
}
117117

118-
applyThreadsParameter( args );
118+
applyThreadsParameter( args, context );
119119

120120
for ( const QgsMapLayer *layer : std::as_const( layers ) )
121121
{

‎src/analysis/processing/pdal/qgsalgorithmpdalclip.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ QStringList QgsPdalClipAlgorithm::createArgumentLists( const QVariantMap &parame
9090
};
9191

9292
applyCommonParameters( args, layer->crs(), parameters, context );
93-
applyThreadsParameter( args );
93+
applyThreadsParameter( args, context );
9494
return args;
9595
}
9696

‎src/analysis/processing/pdal/qgsalgorithmpdalconvertformat.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ QStringList QgsPdalConvertFormatAlgorithm::createArgumentLists( const QVariantMa
7979
QStringLiteral( "--output=%1" ).arg( outputFile )
8080
};
8181

82-
applyThreadsParameter( args );
82+
applyThreadsParameter( args, context );
8383
return args;
8484
}
8585

‎src/analysis/processing/pdal/qgsalgorithmpdaldensity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ QStringList QgsPdalDensityAlgorithm::createArgumentLists( const QVariantMap &par
111111
}
112112

113113
applyCommonParameters( args, layer->crs(), parameters, context );
114-
applyThreadsParameter( args );
114+
applyThreadsParameter( args, context );
115115
return args;
116116
}
117117

‎src/analysis/processing/pdal/qgsalgorithmpdalexportraster.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ QStringList QgsPdalExportRasterAlgorithm::createArgumentLists( const QVariantMap
114114
}
115115

116116
applyCommonParameters( args, layer->crs(), parameters, context );
117-
applyThreadsParameter( args );
117+
applyThreadsParameter( args, context );
118118
return args;
119119
}
120120

‎src/analysis/processing/pdal/qgsalgorithmpdalexportrastertin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ QStringList QgsPdalExportRasterTinAlgorithm::createArgumentLists( const QVariant
111111
}
112112

113113
applyCommonParameters( args, layer->crs(), parameters, context );
114-
applyThreadsParameter( args );
114+
applyThreadsParameter( args, context );
115115
return args;
116116
}
117117

‎src/analysis/processing/pdal/qgsalgorithmpdalexportvector.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ QStringList QgsPdalExportVectorAlgorithm::createArgumentLists( const QVariantMap
9191
}
9292

9393
applyCommonParameters( args, layer->crs(), parameters, context );
94-
applyThreadsParameter( args );
94+
applyThreadsParameter( args, context );
9595
return args;
9696
}
9797

‎src/analysis/processing/pdal/qgsalgorithmpdalfilter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ QStringList QgsPdalFilterAlgorithm::createArgumentLists( const QVariantMap &para
112112
}
113113
}
114114

115-
applyThreadsParameter( args );
115+
applyThreadsParameter( args, context );
116116
return args;
117117
}
118118

‎src/analysis/processing/pdal/qgsalgorithmpdalfixprojection.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ QStringList QgsPdalFixProjectionAlgorithm::createArgumentLists( const QVariantMa
8383
QStringLiteral( "--assign-crs=%1" ).arg( crs.authid() )
8484
};
8585

86-
applyThreadsParameter( args );
86+
applyThreadsParameter( args, context );
8787
return args;
8888
}
8989

‎src/analysis/processing/pdal/qgsalgorithmpdalmerge.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ QStringList QgsPdalMergeAlgorithm::createArgumentLists( const QVariantMap &param
8484
<< QStringLiteral( "--output=%1" ).arg( outputFile );
8585

8686
applyCommonParameters( args, layers.at( 0 )->crs(), parameters, context );
87-
applyThreadsParameter( args );
87+
applyThreadsParameter( args, context );
8888

8989
for ( const QgsMapLayer *layer : std::as_const( layers ) )
9090
{

‎src/analysis/processing/pdal/qgsalgorithmpdalreproject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ QStringList QgsPdalReprojectAlgorithm::createArgumentLists( const QVariantMap &p
9595
args << QStringLiteral( "--transform-coord-op=%1" ).arg( coordOp );
9696
}
9797

98-
applyThreadsParameter( args );
98+
applyThreadsParameter( args, context );
9999
return args;
100100
}
101101

‎src/analysis/processing/pdal/qgsalgorithmpdalthin.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ QStringList QgsPdalThinAlgorithm::createArgumentLists( const QVariantMap &parame
8989
};
9090

9191
applyCommonParameters( args, layer->crs(), parameters, context );
92-
applyThreadsParameter( args );
92+
applyThreadsParameter( args, context );
9393
return args;
9494
}
9595

‎src/analysis/processing/pdal/qgsalgorithmpdaltile.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ QStringList QgsPdalTileAlgorithm::createArgumentLists( const QVariantMap &parame
101101
args << QStringLiteral( "--a_srs=%1" ).arg( crs.authid() );
102102
}
103103

104-
applyThreadsParameter( args );
104+
applyThreadsParameter( args, context );
105105

106106
for ( const QgsMapLayer *layer : std::as_const( layers ) )
107107
{

‎src/analysis/processing/pdal/qgspdalalgorithmbase.cpp

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,13 @@ void QgsPdalAlgorithmBase::applyCommonParameters( QStringList &arguments, QgsCoo
8888
}
8989
}
9090

91-
void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments )
91+
void QgsPdalAlgorithmBase::applyThreadsParameter( QStringList &arguments, QgsProcessingContext &context )
9292
{
93-
QgsSettings settings;
94-
int threads = settings.value( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 0 ).toInt();
93+
const int numThreads = context.numberOfThreads();
9594

96-
if ( threads )
95+
if ( numThreads )
9796
{
98-
arguments << QStringLiteral( "--threads=%1" ).arg( threads );
97+
arguments << QStringLiteral( "--threads=%1" ).arg( numThreads );
9998
}
10099
}
101100

‎src/analysis/processing/pdal/qgspdalalgorithmbase.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ class QgsPdalAlgorithmBase : public QgsProcessingAlgorithm
5555
/**
5656
* Adds "--threads"parameter to the pdal_wrench command line.
5757
*/
58-
void applyThreadsParameter( QStringList &arguments );
58+
void applyThreadsParameter( QStringList &arguments, QgsProcessingContext &context );
5959

6060
/**
6161
* "Fixes" output file name by changing suffix to .vpc if input file

‎tests/src/analysis/testqgsprocessingpdalalgs.cpp

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,6 @@ void TestQgsProcessingPdalAlgs::cleanupTestCase()
8080

8181
void TestQgsProcessingPdalAlgs::init()
8282
{
83-
// set max threads to 0 by default
84-
QgsSettings().setValue( "/Processing/Configuration/MAX_THREADS", 0 );
8583
}
8684

8785
void TestQgsProcessingPdalAlgs::info()
@@ -109,6 +107,7 @@ void TestQgsProcessingPdalAlgs::convertFormat()
109107

110108
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
111109
context->setProject( QgsProject::instance() );
110+
context->setNumberOfThreads( 0 );
112111

113112
QgsProcessingFeedback feedback;
114113

@@ -125,7 +124,7 @@ void TestQgsProcessingPdalAlgs::convertFormat()
125124
);
126125

127126
// set max threads to 2, a --threads argument should be added
128-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
127+
context->setNumberOfThreads( 2 );
129128
args = alg->createArgumentLists( parameters, *context, &feedback );
130129
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
131130
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -140,6 +139,7 @@ void TestQgsProcessingPdalAlgs::reproject()
140139

141140
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
142141
context->setProject( QgsProject::instance() );
142+
context->setNumberOfThreads( 0 );
143143

144144
QgsProcessingFeedback feedback;
145145

@@ -158,7 +158,7 @@ void TestQgsProcessingPdalAlgs::reproject()
158158
);
159159

160160
// set max threads to 2, a --threads argument should be added
161-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
161+
context->setNumberOfThreads( 2 );
162162
args = alg->createArgumentLists( parameters, *context, &feedback );
163163
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
164164
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -174,6 +174,7 @@ void TestQgsProcessingPdalAlgs::fixProjection()
174174

175175
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
176176
context->setProject( QgsProject::instance() );
177+
context->setNumberOfThreads( 0 );
177178

178179
QgsProcessingFeedback feedback;
179180

@@ -192,7 +193,7 @@ void TestQgsProcessingPdalAlgs::fixProjection()
192193
);
193194

194195
// set max threads to 2, a --threads argument should be added
195-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
196+
context->setNumberOfThreads( 2 );
196197
args = alg->createArgumentLists( parameters, *context, &feedback );
197198
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
198199
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -208,6 +209,7 @@ void TestQgsProcessingPdalAlgs::thin()
208209

209210
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
210211
context->setProject( QgsProject::instance() );
212+
context->setNumberOfThreads( 0 );
211213

212214
QgsProcessingFeedback feedback;
213215

@@ -270,7 +272,7 @@ void TestQgsProcessingPdalAlgs::thin()
270272
);
271273

272274
// set max threads to 2, a --threads argument should be added
273-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
275+
context->setNumberOfThreads( 2 );
274276
args = alg->createArgumentLists( parameters, *context, &feedback );
275277
QCOMPARE( args, QStringList() << QStringLiteral( "thin" )
276278
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -289,6 +291,7 @@ void TestQgsProcessingPdalAlgs::boundary()
289291

290292
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
291293
context->setProject( QgsProject::instance() );
294+
context->setNumberOfThreads( 0 );
292295

293296
QgsProcessingFeedback feedback;
294297

@@ -342,7 +345,7 @@ void TestQgsProcessingPdalAlgs::boundary()
342345

343346

344347
// set max threads to 2, a --threads argument should be added
345-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
348+
context->setNumberOfThreads( 2 );
346349
args = alg->createArgumentLists( parameters, *context, &feedback );
347350
QCOMPARE( args, QStringList() << QStringLiteral( "boundary" )
348351
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -361,6 +364,7 @@ void TestQgsProcessingPdalAlgs::density()
361364

362365
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
363366
context->setProject( QgsProject::instance() );
367+
context->setNumberOfThreads( 0 );
364368

365369
QgsProcessingFeedback feedback;
366370

@@ -449,7 +453,7 @@ void TestQgsProcessingPdalAlgs::density()
449453
);
450454

451455
// set max threads to 2, a --threads argument should be added
452-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
456+
context->setNumberOfThreads( 2 );
453457
args = alg->createArgumentLists( parameters, *context, &feedback );
454458
QCOMPARE( args, QStringList() << QStringLiteral( "density" )
455459
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -470,6 +474,7 @@ void TestQgsProcessingPdalAlgs::exportRasterTin()
470474

471475
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
472476
context->setProject( QgsProject::instance() );
477+
context->setNumberOfThreads( 0 );
473478

474479
QgsProcessingFeedback feedback;
475480

@@ -558,7 +563,7 @@ void TestQgsProcessingPdalAlgs::exportRasterTin()
558563
);
559564

560565
// set max threads to 2, a --threads argument should be added
561-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
566+
context->setNumberOfThreads( 2 );
562567
args = alg->createArgumentLists( parameters, *context, &feedback );
563568
QCOMPARE( args, QStringList() << QStringLiteral( "to_raster_tin" )
564569
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -579,6 +584,7 @@ void TestQgsProcessingPdalAlgs::tile()
579584

580585
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
581586
context->setProject( QgsProject::instance() );
587+
context->setNumberOfThreads( 0 );
582588

583589
QgsProcessingFeedback feedback;
584590

@@ -631,7 +637,7 @@ void TestQgsProcessingPdalAlgs::tile()
631637
);
632638

633639
// set max threads to 2, a --threads argument should be added
634-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
640+
context->setNumberOfThreads( 2 );
635641
args = alg->createArgumentLists( parameters, *context, &feedback );
636642
QCOMPARE( args, QStringList() << QStringLiteral( "tile" )
637643
<< QStringLiteral( "--length=150" )
@@ -649,6 +655,7 @@ void TestQgsProcessingPdalAlgs::exportRaster()
649655

650656
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
651657
context->setProject( QgsProject::instance() );
658+
context->setNumberOfThreads( 0 );
652659

653660
QgsProcessingFeedback feedback;
654661

@@ -754,7 +761,7 @@ void TestQgsProcessingPdalAlgs::exportRaster()
754761
);
755762

756763
// set max threads to 2, a --threads argument should be added
757-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
764+
context->setNumberOfThreads( 2 );
758765
args = alg->createArgumentLists( parameters, *context, &feedback );
759766
QCOMPARE( args, QStringList() << QStringLiteral( "to_raster" )
760767
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -776,6 +783,7 @@ void TestQgsProcessingPdalAlgs::exportVector()
776783

777784
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
778785
context->setProject( QgsProject::instance() );
786+
context->setNumberOfThreads( 0 );
779787

780788
QgsProcessingFeedback feedback;
781789

@@ -823,7 +831,7 @@ void TestQgsProcessingPdalAlgs::exportVector()
823831
);
824832

825833
// set max threads to 2, a --threads argument should be added
826-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
834+
context->setNumberOfThreads( 2 );
827835
args = alg->createArgumentLists( parameters, *context, &feedback );
828836
QCOMPARE( args, QStringList() << QStringLiteral( "to_vector" )
829837
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -841,6 +849,7 @@ void TestQgsProcessingPdalAlgs::merge()
841849

842850
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
843851
context->setProject( QgsProject::instance() );
852+
context->setNumberOfThreads( 0 );
844853

845854
QgsProcessingFeedback feedback;
846855

@@ -890,7 +899,7 @@ void TestQgsProcessingPdalAlgs::merge()
890899
);
891900

892901
// set max threads to 2, a --threads argument should be added
893-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
902+
context->setNumberOfThreads( 2 );
894903
args = alg->createArgumentLists( parameters, *context, &feedback );
895904
QCOMPARE( args, QStringList() << QStringLiteral( "merge" )
896905
<< QStringLiteral( "--output=%1" ).arg( outputFile )
@@ -908,6 +917,7 @@ void TestQgsProcessingPdalAlgs::buildVpc()
908917

909918
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
910919
context->setProject( QgsProject::instance() );
920+
context->setNumberOfThreads( 0 );
911921

912922
QgsProcessingFeedback feedback;
913923

@@ -969,7 +979,7 @@ void TestQgsProcessingPdalAlgs::buildVpc()
969979
);
970980

971981
// set max threads to 2, a --threads argument should be added
972-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
982+
context->setNumberOfThreads( 2 );
973983
args = alg->createArgumentLists( parameters, *context, &feedback );
974984
QCOMPARE( args, QStringList() << QStringLiteral( "build_vpc" )
975985
<< QStringLiteral( "--output=%1" ).arg( outputFile )
@@ -988,6 +998,7 @@ void TestQgsProcessingPdalAlgs::clip()
988998

989999
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
9901000
context->setProject( QgsProject::instance() );
1001+
context->setNumberOfThreads( 0 );
9911002

9921003
QgsProcessingFeedback feedback;
9931004

@@ -1028,7 +1039,7 @@ void TestQgsProcessingPdalAlgs::clip()
10281039
);
10291040

10301041
// set max threads to 2, a --threads argument should be added
1031-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
1042+
context->setNumberOfThreads( 2 );
10321043
args = alg->createArgumentLists( parameters, *context, &feedback );
10331044
QCOMPARE( args, QStringList() << QStringLiteral( "clip" )
10341045
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )
@@ -1046,6 +1057,7 @@ void TestQgsProcessingPdalAlgs::filter()
10461057

10471058
std::unique_ptr< QgsProcessingContext > context = std::make_unique< QgsProcessingContext >();
10481059
context->setProject( QgsProject::instance() );
1060+
context->setNumberOfThreads( 0 );
10491061

10501062
QgsProcessingFeedback feedback;
10511063

@@ -1079,7 +1091,7 @@ void TestQgsProcessingPdalAlgs::filter()
10791091
);
10801092

10811093
// set max threads to 2, a --threads argument should be added
1082-
QgsSettings().setValue( QStringLiteral( "/Processing/Configuration/MAX_THREADS" ), 2 );
1094+
context->setNumberOfThreads( 2 );
10831095
args = alg->createArgumentLists( parameters, *context, &feedback );
10841096
QCOMPARE( args, QStringList() << QStringLiteral( "translate" )
10851097
<< QStringLiteral( "--input=%1" ).arg( mPointCloudLayerPath )

0 commit comments

Comments
 (0)
Please sign in to comment.