Mesh: replace QtConcurrent::run with std::async

This commit is contained in:
wmayer
2024-03-11 13:05:05 +01:00
committed by wwmayer
parent 33cacc3fb0
commit 053d0fa047
3 changed files with 19 additions and 13 deletions

View File

@@ -369,7 +369,7 @@ void MeshFastBuilder::Finish()
}
// std::sort(verts.begin(), verts.end());
int threads = QThread::idealThreadCount();
int threads = int(std::thread::hardware_concurrency());
MeshCore::parallel_sort(verts.begin(), verts.end(), std::less<>(), threads);
QVector<FacetIndex> indices(ulCtPts);

View File

@@ -991,7 +991,7 @@ void MeshKernel::RebuildNeighbours(FacetIndex index)
// sort the edges
// std::sort(edges.begin(), edges.end(), Edge_Less());
int threads = QThread::idealThreadCount();
int threads = int(std::thread::hardware_concurrency());
MeshCore::parallel_sort(edges.begin(), edges.end(), Edge_Less(), threads);
PointIndex p0 = POINT_INDEX_MAX, p1 = POINT_INDEX_MAX;

View File

@@ -23,9 +23,8 @@
#ifndef MESH_FUNCTIONAL_H
#define MESH_FUNCTIONAL_H
#include <QFuture>
#include <QtConcurrentRun>
#include <algorithm>
#include <future>
namespace MeshCore
@@ -39,18 +38,25 @@ static void parallel_sort(Iter begin, Iter end, Pred comp, int threads)
else {
Iter mid = begin + (end - begin) / 2;
if (threads == 2) {
QFuture<void> future =
QtConcurrent::run(parallel_sort<Iter, Pred>, begin, mid, comp, threads / 2);
auto future = std::async(parallel_sort<Iter, Pred>, begin, mid, comp, threads / 2);
std::sort(mid, end, comp);
future.waitForFinished();
future.wait();
}
else {
QFuture<void> a =
QtConcurrent::run(parallel_sort<Iter, Pred>, begin, mid, comp, threads / 2);
QFuture<void> b =
QtConcurrent::run(parallel_sort<Iter, Pred>, mid, end, comp, threads / 2);
a.waitForFinished();
b.waitForFinished();
auto a = std::async(std::launch::async,
parallel_sort<Iter, Pred>,
begin,
mid,
comp,
threads / 2);
auto b = std::async(std::launch::async,
parallel_sort<Iter, Pred>,
mid,
end,
comp,
threads / 2);
a.wait();
b.wait();
}
std::inplace_merge(begin, mid, end, comp);
}