barretenberg
Loading...
Searching...
No Matches
thread.hpp
1#pragma once
2#include <atomic>
3#include <barretenberg/env/hardware_concurrency.hpp>
4#include <barretenberg/numeric/bitop/get_msb.hpp>
5#include <functional>
6#include <iostream>
7#include <thread>
8#include <vector>
9
10inline size_t get_num_cpus()
11{
12#ifdef NO_MULTITHREADING
13 return 1;
14#else
15 return env_hardware_concurrency();
16#endif
17}
18
19// For algorithms that need to be divided amongst power of 2 threads.
20inline size_t get_num_cpus_pow2()
21{
22 return static_cast<size_t>(1ULL << numeric::get_msb(get_num_cpus()));
23}
24
25void parallel_for(size_t num_iterations, const std::function<void(size_t)>& func);