]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add Threads::TaskGroup::return_values().
authorWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Nov 2022 22:56:41 +0000 (15:56 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Tue, 29 Nov 2022 23:13:46 +0000 (16:13 -0700)
include/deal.II/base/thread_management.h

index b6e85a446f8d119989a1dbb8c8b1ede53264e0e5..45fe38cb6766f0ecdd2f32e20446f0d8e71375da 100644 (file)
@@ -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<RT>
+    return_values()
+    {
+      std::vector<RT> 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

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.