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]);
44 constexpr size_t outer_iterations = 4;
45 constexpr size_t inner_iterations = 10;
50 [&](
size_t i) {
parallel_for(inner_iterations, [&](
size_t j) { flags[i][j] = 1; }); });
53 for (
size_t i = 0; i < outer_iterations; ++i) {
54 for (
size_t j = 0; j < inner_iterations; ++j) {
55 EXPECT_TRUE(flags[i][j]);
109 EXPECT_EQ(counter, 0);
122 EXPECT_EQ(counter, 1);
128 constexpr size_t num_points = 100;
132 for (
size_t i = start; i < end; ++i) {
138 for (
size_t i = 0; i < num_points; ++i) {
139 EXPECT_TRUE(flags[i]);
146 constexpr size_t num_points = 10;
149 std::atomic<size_t> call_count{ 0 };
154 [&](
size_t start,
size_t end) {
156 for (
size_t i = start; i < end; ++i) {
163 for (
size_t i = 0; i < num_points; ++i) {
164 EXPECT_TRUE(flags[i]);
168 EXPECT_EQ(call_count, 1);
219 EXPECT_EQ(cpus_before, 8);
227 observed_inner_cpus[outer_idx].store(inner_cpus);
234 for (
size_t i = 0; i < 4; ++i) {
235 EXPECT_GE(observed_inner_cpus[i].load(), 2);
240 EXPECT_EQ(cpus_after, 8);
241 EXPECT_EQ(cpus_before, cpus_after);
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