Barretenberg
The ZK-SNARK library at the core of Aztec
Loading...
Searching...
No Matches
parallel_for_queued.cpp
Go to the documentation of this file.
1#ifndef NO_MULTITHREADING
2#include "log.hpp"
3#include "thread.hpp"
4#include "thread_pool.hpp"
5#include <atomic>
6#include <condition_variable>
7#include <functional>
8#include <mutex>
9#include <queue>
10#include <thread>
11#include <vector>
12
13namespace bb {
19void parallel_for_queued(size_t num_iterations, const std::function<void(size_t)>& func)
20{
21 static ThreadPool pool(get_num_cpus());
22
23 // info("wait for pool enter");
24 pool.wait();
25 for (size_t i = 0; i < num_iterations; ++i) {
26 // info("enqueing iteration ", i);
27 pool.enqueue([=]() { func(i); });
28 }
29 // info("wait for pool exit");
30 pool.wait();
31 // info("pool finished work");
32}
33} // namespace bb
34#endif
void enqueue(const std::function< void()> &task)
Entry point for Barretenberg command-line interface.
void parallel_for_queued(size_t num_iterations, const std::function< void(size_t)> &func)
size_t get_num_cpus()
Definition thread.hpp:12