From: Wolfgang Bangerth Date: Tue, 29 Nov 2022 22:56:41 +0000 (-0700) Subject: Add Threads::TaskGroup::return_values(). X-Git-Tag: v9.5.0-rc1~785^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=455578ddc13ee634554dfce142adea1785eded30;p=dealii.git Add Threads::TaskGroup::return_values(). --- diff --git a/include/deal.II/base/thread_management.h b/include/deal.II/base/thread_management.h index b6e85a446f..45fe38cb67 100644 --- a/include/deal.II/base/thread_management.h +++ b/include/deal.II/base/thread_management.h @@ -1667,6 +1667,30 @@ namespace Threads return tasks.size(); } + /** + * Return a vector of objects that contain the return values of + * the tasks contained in this group. This function can obviously + * only return once all tasks are completed. + * + * The returned vector contains the returned values of tasks in + * the same order in which these tasks were added to the task + * group. + * + * @note This function only makes sense if `RT` is an actual data + * type, rather than `void`. If the TaskGroup stores tasks that have + * no return value, then you should simply call `join_all()`, which + * also waits for all tasks to finish. + */ + std::vector + return_values() + { + std::vector results; + results.reserve(size()); + for (auto &t : tasks) + results.emplace_back(std::move(t.return_value())); + return results; + } + /** * Wait for all tasks in the collection to finish. It is not a problem if