From 797a6471422d9b2f44eed7f9dd8122fc8ef7243e Mon Sep 17 00:00:00 2001 From: Aleksandr Cherenkov Date: Mon, 11 Mar 2024 15:49:20 +0000 Subject: [PATCH] parallelize table printing for multiprover case #569 --- bin/assigner/src/main.cpp | 44 ++++++++++++++++++++++++++++++++------- 1 file changed, 36 insertions(+), 8 deletions(-) diff --git a/bin/assigner/src/main.cpp b/bin/assigner/src/main.cpp index c37c22ba..24a12ec9 100644 --- a/bin/assigner/src/main.cpp +++ b/bin/assigner/src/main.cpp @@ -484,6 +484,25 @@ struct ParametersPolicy { constexpr static const std::size_t LookupSelectorColumns = LOOKUP_SELECTOR_COLUMNS; }; +template +void assignment_table_printer( + std::ofstream& otable, + std::uint32_t idx, + nil::blueprint::assigner &assigner_instance, + const std::size_t &ComponentConstantColumns, + const std::size_t &ComponentSelectorColumns +) { + auto multi_table_print_start = std::chrono::high_resolution_clock::now(); + + print_assignment_table( + assigner_instance.assignments[idx], print_table_kind::MULTI_PROVER, ComponentConstantColumns, + ComponentSelectorColumns, otable); + + otable.close(); + auto multi_table_print_duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - multi_table_print_start); + BOOST_LOG_TRIVIAL(info) << "multi_table_print_duration: " << multi_table_print_duration.count() << "ms"; +} + template int curve_dependent_main(std::string bytecode_file_name, std::string public_input_file_name, @@ -641,10 +660,12 @@ int curve_dependent_main(std::string bytecode_file_name, (target_prover < assigner_instance.assignments.size() || target_prover == invalid_target_prover)) { std::uint32_t start_idx = (target_prover == invalid_target_prover) ? 0 : target_prover; std::uint32_t end_idx = (target_prover == invalid_target_prover) ? assigner_instance.assignments.size() : target_prover + 1; + + std::vector threads = {}; + for (std::uint32_t idx = start_idx; idx < end_idx; idx++) { // print assignment table if (gen_mode.has_assignments()) { - auto multi_table_print_start = std::chrono::high_resolution_clock::now(); std::ofstream otable; otable.open(assignment_table_file_name + std::to_string(idx), std::ios_base::binary | std::ios_base::out); @@ -654,13 +675,14 @@ int curve_dependent_main(std::string bytecode_file_name, return 1; } - print_assignment_table( - assigner_instance.assignments[idx], print_table_kind::MULTI_PROVER, ComponentConstantColumns, - ComponentSelectorColumns, otable); - - otable.close(); - auto multi_table_print_duration = std::chrono::duration_cast(std::chrono::high_resolution_clock::now() - multi_table_print_start); - BOOST_LOG_TRIVIAL(info) << "multi_table_print_duration: " << multi_table_print_duration.count() << "ms"; + threads.emplace_back( + assignment_table_printer, + std::ref(otable), + idx, + std::ref(assigner_instance), + std::ref(ComponentConstantColumns), + std::ref(ComponentSelectorColumns) + ); } // print circuit @@ -679,6 +701,12 @@ int curve_dependent_main(std::string bytecode_file_name, ocircuit.close(); } } + for (auto& thread : threads) { + if (thread.joinable()) { + thread.join(); + } + } + } else { std::cout << "No data for print: target prover " << target_prover << ", actual number of provers " << assigner_instance.assignments.size() << std::endl;