Clean up and fix the documentation of ForkJoin.h

This commit is contained in:
William Kong 2025-01-27 23:12:17 +00:00 committed by Antonio Sánchez
parent dc1126e762
commit bc67025ba7

View File

@ -48,11 +48,11 @@ namespace Eigen {
// Example usage #2 (asynchronous): // Example usage #2 (asynchronous):
// ``` // ```
// ThreadPool thread_pool(num_threads); // ThreadPool thread_pool(num_threads);
// Barrier barrier(num_completions); // Barrier barrier(num_tasks * num_async_calls);
// auto done = [&](){barrier.Notify();}; // auto done = [&](){barrier.Notify();};
// for (int k=0; k<num_async_calls; ++k) { // for (int k=0; k<num_async_calls; ++k) {
// thread_pool.Schedule([&](){ // thread_pool.Schedule([&](){
// ForkJoinScheduler::ParallelFor(0, num_tasks, granularity, parallel_task, done, &thread_pool); // ForkJoinScheduler::ParallelForAsync(0, num_tasks, granularity, parallel_task, done, &thread_pool);
// }); // });
// } // }
// barrier.Wait(); // barrier.Wait();
@ -73,7 +73,7 @@ class ForkJoinScheduler {
ForkJoinScheduler::RunParallelForAsync(start, end, granularity, do_func, done, thread_pool); ForkJoinScheduler::RunParallelForAsync(start, end, granularity, do_func, done, thread_pool);
} }
// Synchronous variant of Async::ParallelFor. // Synchronous variant of ParallelForAsync.
template <typename DoFnType> template <typename DoFnType>
static void ParallelFor(int start, int end, int granularity, DoFnType do_func, Eigen::ThreadPool* thread_pool) { static void ParallelFor(int start, int end, int granularity, DoFnType do_func, Eigen::ThreadPool* thread_pool) {
if (start >= end) return; if (start >= end) return;
@ -87,8 +87,7 @@ class ForkJoinScheduler {
} }
private: private:
// Schedules `right_thunk`, runs `left_thunk` and runs other tasks until // Schedules `right_thunk`, runs `left_thunk`, and runs other tasks until `right_thunk` has finished.
// `right_thunk` has finished.
template <typename LeftType, typename RightType> template <typename LeftType, typename RightType>
static void ForkJoin(LeftType&& left_thunk, RightType&& right_thunk, Eigen::ThreadPool* thread_pool) { static void ForkJoin(LeftType&& left_thunk, RightType&& right_thunk, Eigen::ThreadPool* thread_pool) {
std::atomic<bool> right_done(false); std::atomic<bool> right_done(false);