diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/threading/local_executor/tbb_local_executor.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/threading/local_executor/tbb_local_executor.cpp')
-rw-r--r-- | library/cpp/threading/local_executor/tbb_local_executor.cpp | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/library/cpp/threading/local_executor/tbb_local_executor.cpp b/library/cpp/threading/local_executor/tbb_local_executor.cpp new file mode 100644 index 0000000000..65d6659443 --- /dev/null +++ b/library/cpp/threading/local_executor/tbb_local_executor.cpp @@ -0,0 +1,53 @@ +#include "tbb_local_executor.h" + +template <bool RespectTls> +void NPar::TTbbLocalExecutor<RespectTls>::SubmitAsyncTasks(TLocallyExecutableFunction exec, int firstId, int lastId) { + for (int i = firstId; i < lastId; ++i) { + Group.run([=] { exec(i); }); + } +} + +template <bool RespectTls> +int NPar::TTbbLocalExecutor<RespectTls>::GetThreadCount() const noexcept { + return NumberOfTbbThreads - 1; +} + +template <bool RespectTls> +int NPar::TTbbLocalExecutor<RespectTls>::GetWorkerThreadId() const noexcept { + return TbbArena.execute([] { + return tbb::this_task_arena::current_thread_index(); + }); +} + +template <bool RespectTls> +void NPar::TTbbLocalExecutor<RespectTls>::Exec(TIntrusivePtr<ILocallyExecutable> exec, int id, int flags) { + if (flags & WAIT_COMPLETE) { + exec->LocalExec(id); + } else { + TbbArena.execute([=] { + SubmitAsyncTasks([=] (int id) { exec->LocalExec(id); }, id, id + 1); + }); + } +} + +template <bool RespectTls> +void NPar::TTbbLocalExecutor<RespectTls>::ExecRange(TIntrusivePtr<ILocallyExecutable> exec, int firstId, int lastId, int flags) { + if (flags & WAIT_COMPLETE) { + TbbArena.execute([=] { + if (RespectTls) { + tbb::this_task_arena::isolate([=]{ + tbb::parallel_for(firstId, lastId, [=] (int id) { exec->LocalExec(id); }); + }); + } else { + tbb::parallel_for(firstId, lastId, [=] (int id) { exec->LocalExec(id); }); + } + }); + } else { + TbbArena.execute([=] { + SubmitAsyncTasks([=] (int id) { exec->LocalExec(id); }, firstId, lastId); + }); + } +} + +template class NPar::TTbbLocalExecutor<true>; +template class NPar::TTbbLocalExecutor<false>; |