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 12, 2024
1 parent d929594 commit 797a647
Showing 1 changed file with 36 additions and 8 deletions.
44 changes: 36 additions & 8 deletions bin/assigner/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,25 @@ struct ParametersPolicy {
constexpr static const std::size_t LookupSelectorColumns = LOOKUP_SELECTOR_COLUMNS;
};

template<typename ArithmetizationType, typename BlueprintFieldType>
void assignment_table_printer(
std::ofstream& otable,
std::uint32_t idx,
nil::blueprint::assigner<BlueprintFieldType> &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<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(info) << "multi_table_print_duration: " << multi_table_print_duration.count() << "ms";
}

template<typename BlueprintFieldType>
int curve_dependent_main(std::string bytecode_file_name,
std::string public_input_file_name,
Expand Down Expand Up @@ -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<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);
Expand All @@ -654,13 +675,14 @@ int curve_dependent_main(std::string bytecode_file_name,
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(info) << "multi_table_print_duration: " << multi_table_print_duration.count() << "ms";
threads.emplace_back(
assignment_table_printer<ArithmetizationType, BlueprintFieldType>,
std::ref(otable),
idx,
std::ref(assigner_instance),
std::ref(ComponentConstantColumns),
std::ref(ComponentSelectorColumns)
);
}

// print circuit
Expand All @@ -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;
Expand Down

0 comments on commit 797a647

Please sign in to comment.