Skip to content

Commit

Permalink
parallelize table printing for multiprover case #569
Browse files Browse the repository at this point in the history
  • Loading branch information
CblPOK-git committed Mar 28, 2024
1 parent 2c99b45 commit 21636d6
Showing 1 changed file with 40 additions and 16 deletions.
56 changes: 40 additions & 16 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
#include <llvm/Support/Signals.h>

#include <thread>
#include <chrono>

using namespace nil;
using namespace nil::crypto3;
Expand Down Expand Up @@ -456,6 +457,27 @@ struct ParametersPolicy {
constexpr static const std::size_t LookupSelectorColumns = LOOKUP_SELECTOR_COLUMNS;
};

template<typename ArithmetizationType, typename BlueprintFieldType>
void assignment_table_printer(
std::string assignment_table_file_name,
std::uint32_t idx,
nil::blueprint::assigner<BlueprintFieldType> &assigner_instance,
const std::size_t &ComponentConstantColumns,
const std::size_t &ComponentSelectorColumns
) {
BOOST_LOG_TRIVIAL(info) << "start thread " << idx;
std::ofstream otable;
otable.open(assignment_table_file_name + std::to_string(idx),
std::ios_base::binary | std::ios_base::out);
if (!otable) {
std::cout << "Something wrong with output " << assignment_table_file_name + std::to_string(idx)
<< std::endl;
std::abort();
}

otable.close();
}

template<typename BlueprintFieldType>
int curve_dependent_main(std::string bytecode_file_name,
std::string public_input_file_name,
Expand Down Expand Up @@ -623,26 +645,21 @@ 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<std::thread> 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);
if (!otable) {
std::cout << "Something wrong with output " << assignment_table_file_name + std::to_string(idx)
<< std::endl;
return 1;
}

print_assignment_table<nil::marshalling::option::big_endian, ArithmetizationType, BlueprintFieldType>(
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::milliseconds>(std::chrono::high_resolution_clock::now() - multi_table_print_start);
BOOST_LOG_TRIVIAL(debug) << "multi_table_print_duration: " << multi_table_print_duration.count() << "ms";
threads.emplace_back(
assignment_table_printer<ArithmetizationType, BlueprintFieldType>,
assignment_table_file_name,
idx,
std::ref(assigner_instance),
std::ref(ComponentConstantColumns),
std::ref(ComponentSelectorColumns)
);
}

// print circuit
Expand All @@ -661,6 +678,13 @@ 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;
Expand Down

0 comments on commit 21636d6

Please sign in to comment.