4#include <gtest/gtest.h>
30 constexpr size_t num_iterations = 100;
33 parallel_for(num_iterations, [&](
size_t i) { flags[i] = 1; });
36 for (
size_t i = 0; i < num_iterations; ++i) {
37 EXPECT_TRUE(flags[i]);
90 EXPECT_EQ(counter, 0);
103 EXPECT_EQ(counter, 1);
109 constexpr size_t num_points = 100;
113 for (
size_t i = start; i < end; ++i) {
119 for (
size_t i = 0; i < num_points; ++i) {
120 EXPECT_TRUE(flags[i]);
127 constexpr size_t num_points = 10;
130 std::atomic<size_t> call_count{ 0 };
135 [&](
size_t start,
size_t end) {
137 for (
size_t i = start; i < end; ++i) {
144 for (
size_t i = 0; i < num_points; ++i) {
145 EXPECT_TRUE(flags[i]);
149 EXPECT_EQ(call_count, 1);
198 constexpr size_t num_outer = 2;
199 constexpr size_t num_inner = 100;
202 auto worker = [&](
size_t outer_idx) {
204 parallel_for(num_inner, [&](
size_t inner_idx) { results[outer_idx][inner_idx] = 1; });
207 std::vector<std::thread> threads;
208 for (
size_t i = 0; i < num_outer; ++i) {
209 threads.emplace_back(worker, i);
211 for (
auto& t : threads) {
216 for (
size_t i = 0; i < num_outer; ++i) {
217 for (
size_t j = 0; j < num_inner; ++j) {
218 EXPECT_TRUE(results[i][j]);
size_t original_concurrency
Entry point for Barretenberg command-line interface.
TEST_F(IPATest, ChallengesAreZero)
size_t get_num_cpus_pow2()
size_t calculate_num_threads(size_t num_iterations, size_t min_iterations_per_thread)
calculates number of threads to create based on minimum iterations per thread
size_t calculate_num_threads_pow2(size_t num_iterations, size_t min_iterations_per_thread)
calculates number of threads to create based on minimum iterations per thread, guaranteed power of 2
void set_parallel_for_concurrency(size_t num_cores)
void parallel_for(size_t num_iterations, const std::function< void(size_t)> &func)
void parallel_for_range(size_t num_points, const std::function< void(size_t, size_t)> &func, size_t no_multhreading_if_less_or_equal)
Split a loop into several loops running in parallel.
constexpr decltype(auto) get(::tuplet::tuple< T... > &&t) noexcept