Skip to content

Commit

Permalink
Minor QBdt refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
WrathfulSpatula committed Aug 7, 2023
1 parent da727ac commit 7ec70d6
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/qbdt/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,10 @@ void QBdt::par_for_qbdt(const bitCapInt& end, bitLenInt maxQubit, BdtFunc fn)

std::mutex myMutex;
bitCapInt idx = 0U;
std::vector<std::future<void>> futures(threads);
std::vector<std::future<void>> futures;
futures.reserve(threads);
for (unsigned cpu = 0U; cpu != threads; ++cpu) {
futures[cpu] = std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, fn]() {
futures.push_back(std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, fn]() {
for (;;) {
bitCapInt i;
if (true) {
Expand All @@ -119,10 +120,10 @@ void QBdt::par_for_qbdt(const bitCapInt& end, bitLenInt maxQubit, BdtFunc fn)
}
}
}
});
}));
}

for (unsigned cpu = 0U; cpu != threads; ++cpu) {
for (unsigned cpu = 0U; cpu < futures.size(); ++cpu) {
futures[cpu].get();
}
#else
Expand Down Expand Up @@ -152,9 +153,10 @@ void QBdt::_par_for(const bitCapInt& end, ParallelFuncBdt fn)

std::mutex myMutex;
bitCapInt idx = 0U;
std::vector<std::future<void>> futures(threads);
std::vector<std::future<void>> futures;
futures.reserve(threads);
for (unsigned cpu = 0U; cpu != threads; ++cpu) {
futures[cpu] = std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, cpu, fn]() {
futures.push_back(std::async(std::launch::async, [&myMutex, &idx, &end, &Stride, cpu, fn]() {
for (;;) {
bitCapInt i;
if (true) {
Expand All @@ -170,10 +172,10 @@ void QBdt::_par_for(const bitCapInt& end, ParallelFuncBdt fn)
fn(j + l, cpu);
}
}
});
}));
}

for (unsigned cpu = 0U; cpu != threads; ++cpu) {
for (unsigned cpu = 0U; cpu < futures.size(); ++cpu) {
futures[cpu].get();
}
#else
Expand Down

0 comments on commit 7ec70d6

Please sign in to comment.