From 11ed7bd843867ed8a32473955d10728ee61e663a Mon Sep 17 00:00:00 2001 From: Paul Leroy Date: Tue, 13 Feb 2024 09:22:50 +0100 Subject: [PATCH] use ccQtHelpers::GetMaxThreadCount --- ContextBasedFeature.cpp | 5 ++++- PointFeature.cpp | 5 ++++- q3DMASCClassifier.cpp | 5 +++-- q3DMASCTools.cpp | 10 +++++++--- 4 files changed, 18 insertions(+), 7 deletions(-) diff --git a/ContextBasedFeature.cpp b/ContextBasedFeature.cpp index 9471118..eb158d5 100644 --- a/ContextBasedFeature.cpp +++ b/ContextBasedFeature.cpp @@ -23,6 +23,9 @@ //qCC_db #include +//CCPluginAPI +#include + //Qt #include @@ -194,7 +197,7 @@ bool ContextBasedFeature::prepare( const CorePoints& corePoints, bool cancelled = false; #ifndef _DEBUG #if defined(_OPENMP) -#pragma omp parallel for num_threads(std::max(1, omp_get_max_threads() - 2)) +#pragma omp parallel for num_threads(ccQtHelpers::GetMaxThreadCount(omp_get_max_threads())) #endif #endif for (int i = 0; i < static_cast(pointCount); ++i) diff --git a/PointFeature.cpp b/PointFeature.cpp index b73bd46..0017b69 100644 --- a/PointFeature.cpp +++ b/PointFeature.cpp @@ -89,6 +89,9 @@ constexpr const char* LAS_FIELD_NAMES[22] = {"X", //CCLib #include +//CCPluginAPI +#include + //system #include @@ -424,7 +427,7 @@ static bool ComputeMathOpWithNearestNeighbor( const CorePoints& corePoints, error.clear(); #ifndef _DEBUG #if defined(_OPENMP) -#pragma omp parallel for num_threads(std::max(1, omp_get_max_threads() - 2)) +#pragma omp parallel for num_threads(ccQtHelpers::GetMaxThreadCount(omp_get_max_threads())) #endif #endif for (int i = 0; i < static_cast(pointCount); ++i) diff --git a/q3DMASCClassifier.cpp b/q3DMASCClassifier.cpp index 8b09c47..ea3356e 100644 --- a/q3DMASCClassifier.cpp +++ b/q3DMASCClassifier.cpp @@ -30,8 +30,9 @@ //qPDALIO #include "../../../core/IO/qPDALIO/include/LASFields.h" -//qCC_plugins +//CCPluginAPI #include +#include //Qt #include @@ -209,7 +210,7 @@ bool Classifier::classify( const Feature::Source::Set& featureSources, int numberOfTrees = static_cast(m_rtrees->getRoots().size()); #ifndef _DEBUG #if defined(_OPENMP) -#pragma omp parallel for num_threads(std::max(1, omp_get_max_threads() - 2)) +#pragma omp parallel for num_threads(ccQtHelpers::GetMaxThreadCount(omp_get_max_threads())) #endif #endif for (int i = 0; i < static_cast(cloud->size()); ++i) diff --git a/q3DMASCTools.cpp b/q3DMASCTools.cpp index d8deeec..32833dd 100644 --- a/q3DMASCTools.cpp +++ b/q3DMASCTools.cpp @@ -30,6 +30,9 @@ #include #include +//CCPluginAPI +#include + //qPDALIO #include "../../../core/IO/qPDALIO/include/LASFields.h" @@ -1229,15 +1232,16 @@ bool Tools::PrepareFeatures(const CorePoints& corePoints, Feature::Set& features progressCb->setMethodTitle("Compute features"); progressCb->setInfo(qPrintable(logMessage)); } - ccLog::Print(logMessage + " , nb threads " + QString::number(omp_get_max_threads() - 2) + ", nb points " + QString::number(pointCount)); + ccLog::Print(logMessage + ", nb points " + QString::number(pointCount)); CCCoreLib::NormalizedProgress nProgress(progressCb, pointCount); - nProgress.reset(); QMutex mutex; #ifndef _DEBUG #if defined(_OPENMP) -#pragma omp parallel for num_threads(std::max(1, omp_get_max_threads() - 2)) + int num_threads = ccQtHelpers::GetMaxThreadCount(omp_get_max_threads()); + ccLog::Print("Using OpenMP with " + QString::number(num_threads) + " threads "); +#pragma omp parallel for num_threads(num_threads) #endif #endif for (int i = 0; i < static_cast(pointCount); ++i)