dstocco
(Diego Stocco)
March 31, 2020, 12:51pm
1
Dear core experts,
I’m trying to parallelise part of my code using the C++17 feature:
std::for_each(std::execution::par,...)
However, the code breaks as soon as I do:
#include <execution>
with the error:
fatal error: 'execution' file not found
I think that the parallel execution is not implemented in clang, apple clang, or even gcc 7 (?).
Is there an equivalent way to write some parallel code in O2?
Thanks in advance,
cheers,
Diego
eulisse
(Giulio Eulisse)
March 31, 2020, 1:21pm
2
You’ll need GCC 9 for this and even in that case you will need a backend library (e.g. TBB). I guess openmp is the best we can hope for, for now.
shahoian
(Ruben Shahoyan)
March 31, 2020, 1:39pm
3
In the ITS tracking @iouribelikov use std::async:
if (!numOfClusters) {
return {0, 0};
}
std::vector<std::future<std::vector<TrackITSExt>>> futures(mNumOfThreads);
std::vector<std::vector<TrackITSExt>> seedArray(mNumOfThreads);
for (Int_t t = 0, first = 0; t < mNumOfThreads; t++) {
Int_t rem = t < (numOfClusters % mNumOfThreads) ? 1 : 0;
Int_t last = first + (numOfClusters / mNumOfThreads) + rem;
futures[t] = std::async(std::launch::async, &CookedTracker::trackInThread, this, first, last);
first = last;
}
Int_t nSeeds = 0, ngood = 0;
int nAllTracks = 0, nTracks = 0;
for (Int_t t = 0; t < mNumOfThreads; t++) {
seedArray[t] = futures[t].get();
nSeeds += seedArray[t].size();
for (auto& track : seedArray[t]) {
if (track.getNumberOfClusters() < kminNumberOfClusters)
continue;
dstocco
(Diego Stocco)
April 1, 2020, 6:30am
4
Dear @eulisse and @shahoian ,
thanks a lot for the suggestions. I’ll give a try to the async command.
Thanks!
Cheers,
Diego