Does Qt has an equivalent of C# parallel.foreach?
Solved
General and Desktop
-
wrote on 16 Jul 2018, 18:06 last edited by
C# has a very easy way to run a block in parallel, like this:
Parallel.ForEach(arr, item => { doSomethingWith(item); });
C#'s doc: https://msdn.microsoft.com/en-us/library/system.threading.tasks.parallel.foreach(v=vs.110).aspx
Is there an equivalente in Qt?
-
Hi,
You are likely looking for the QtConcurrent module.
-
wrote on 17 Jul 2018, 14:18 last edited by
I just found omp header in Qt:
#pragma omp parallel for for(int i = 1; i < size; ++i) { // ... }
-
wrote on 17 Jul 2018, 15:54 last edited by VRonin
Use
QtConcurrent::blockingMapped(std::begin(arr),std::end(arr),doSomethingWith)
orstd::for_each(std::execution::par,std::begin(arr),std::end(arr),doSomethingWith)
(C++17 onward)
3/4