From 6cd64c4ddcf1962ee079a4a89d07c41d50f2d4bc Mon Sep 17 00:00:00 2001 From: Marco de Abreu Date: Sat, 15 May 2021 06:39:06 +0200 Subject: [PATCH] Add parallel reads to GetFullProof --- src/prover_disk.hpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/prover_disk.hpp b/src/prover_disk.hpp index 45f96257b..b429b13b8 100644 --- a/src/prover_disk.hpp +++ b/src/prover_disk.hpp @@ -22,6 +22,7 @@ #include // std::min #include +#include #include #include #include @@ -218,7 +219,7 @@ class DiskProver { } // Gets the 64 leaf x values, concatenated together into a k*64 bit string. - std::vector xs = GetInputs(disk_file, p7_entries[index], 6); + std::vector xs = GetInputs(p7_entries[index], 6); // Sorts them according to proof ordering, where // f1(x0) m= f1(x1), f2(x0, x1) m= f2(x2, x3), etc. On disk, they are not stored in @@ -634,8 +635,10 @@ class DiskProver { // all of the leaves (x values). For example, for depth=5, it fetches the position-th // entry in table 5, reading the two back pointers from the line point, and then // recursively calling GetInputs for table 4. - std::vector GetInputs(std::ifstream& disk_file, uint64_t position, uint8_t depth) + std::vector GetInputs(uint64_t position, uint8_t depth) { + // Create individual file handles to allow parallel processing + std::ifstream disk_file(filename, std::ios::in | std::ios::binary); uint128_t line_point = ReadLinePoint(disk_file, depth, position); std::pair xy = Encoding::LinePointToSquare(line_point); @@ -646,8 +649,10 @@ class DiskProver { ret.emplace_back(xy.first, k); // x return ret; } else { - std::vector left = GetInputs(disk_file, xy.second, depth - 1); // y - std::vector right = GetInputs(disk_file, xy.first, depth - 1); // x + auto left_fut=std::async(std::launch::async, &DiskProver::GetInputs,this, (uint64_t)xy.second, (uint8_t)(depth - 1)); + auto right_fut=std::async(std::launch::async, &DiskProver::GetInputs,this, (uint64_t)xy.first, (uint8_t)(depth - 1)); + std::vector left = left_fut.get(); // y + std::vector right = right_fut.get(); // x left.insert(left.end(), right.begin(), right.end()); return left; }