Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Support TSeq with step in TThreadExecutor
  • Loading branch information
xvallspl committed Mar 23, 2017
commit 771defb9f130602f555f319fb4fcb4e91b7faa11
8 changes: 5 additions & 3 deletions core/thread/inc/ROOT/TThreadExecutor.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ namespace ROOT {
/// sequence as argument.
template<class F, class INTEGER>
void TThreadExecutor::Foreach(F func, ROOT::TSeq<INTEGER> args) {
ParallelFor(*args.begin(), *args.end(), 1, [&](unsigned int i){func(i);});
ParallelFor(*args.begin(), *args.end(), args.step(), [&](unsigned int i){func(i);});
}

/// \cond
Expand Down Expand Up @@ -165,14 +165,15 @@ namespace ROOT {
auto TThreadExecutor::Map(F func, ROOT::TSeq<INTEGER> args) -> std::vector<typename std::result_of<F(INTEGER)>::type> {
unsigned start = *args.begin();
unsigned end = *args.end();
unsigned seqStep = args.step();

using retType = decltype(func(start));
std::vector<retType> reslist(end - start);
auto lambda = [&](unsigned int i)
{
reslist[i] = func(i);
};
ParallelFor(start, end, 1, lambda);
ParallelFor(start, end, seqStep, lambda);

return reslist;
}
Expand Down Expand Up @@ -241,14 +242,15 @@ namespace ROOT {

unsigned start = *args.begin();
unsigned end = *args.end();
unsigned seqStep = args.step();
unsigned step = (end - start + nChunks - 1) / nChunks; //ceiling the division

using retType = decltype(func(start));
std::vector<retType> reslist(nChunks);
auto lambda = [&](unsigned int i)
{
std::vector<retType> partialResults(step);
for (unsigned j = 0; j < step && (i + j) < end; j++) {
for (unsigned j = 0; j < step && (i + j) < end; j+=seqStep) {
partialResults[j] = func(i + j);
}
reslist[i / step] = redfunc(partialResults);
Expand Down