Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional phase completion callback argument #294

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions python-bindings/chiapos.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using std::experimental::optional;
#error "an implementation of optional is required!"
#endif

#include <pybind11/functional.h>
#include <pybind11/operators.h>
#include <pybind11/pybind11.h>
#include <pybind11/stl.h>
Expand Down Expand Up @@ -49,7 +50,8 @@ PYBIND11_MODULE(chiapos, m)
uint32_t num_buckets,
uint32_t stripe_size,
uint8_t num_threads,
bool nobitfield) {
bool nobitfield,
py::object phase_completion_callback) {
std::string memo_str(memo);
const uint8_t *memo_ptr = reinterpret_cast<const uint8_t *>(memo_str.data());
std::string id_str(id);
Expand All @@ -68,7 +70,8 @@ PYBIND11_MODULE(chiapos, m)
num_buckets,
stripe_size,
num_threads,
nobitfield ? 0 : ENABLE_BITFIELD);
nobitfield ? 0 : ENABLE_BITFIELD,
[&phase_completion_callback](uint8_t phase) { phase_completion_callback(phase); });
} catch (const std::exception &e) {
std::cout << "Caught plotting error: " << e.what() << std::endl;
throw e;
Expand Down
10 changes: 9 additions & 1 deletion src/plotter_disk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ class DiskPlotter {
uint32_t num_buckets_input = 0,
uint64_t stripe_size_input = 0,
uint8_t num_threads_input = 0,
uint8_t phases_flags = ENABLE_BITFIELD)
uint8_t phases_flags = ENABLE_BITFIELD,
std::function<void(uint8_t)> phase_completion_callback = [](uint8_t) {})
{
// Increases the open file limit, we will open a lot of files.
#ifndef _WIN32
Expand Down Expand Up @@ -231,6 +232,7 @@ class DiskPlotter {
num_threads,
phases_flags);
p1.PrintElapsed("Time for phase 1 =");
phase_completion_callback(1);

uint64_t finalsize=0;

Expand All @@ -257,6 +259,7 @@ class DiskPlotter {
log_num_buckets,
phases_flags);
p2.PrintElapsed("Time for phase 2 =");
phase_completion_callback(2);

// Now we open a new file, where the final contents of the plot will be stored.
uint32_t header_size = WriteHeader(tmp2_disk, k, id, memo, memo_len);
Expand All @@ -280,13 +283,15 @@ class DiskPlotter {
log_num_buckets,
phases_flags);
p3.PrintElapsed("Time for phase 3 =");
phase_completion_callback(3);

std::cout << std::endl
<< "Starting phase 4/4: Write Checkpoint tables into " << tmp_2_filename
<< " ... " << Timer::GetNow();
Timer p4;
b17RunPhase4(k, k + 1, tmp2_disk, res, phases_flags, 16);
p4.PrintElapsed("Time for phase 4 =");
phase_completion_callback(4);
finalsize = res.final_table_begin_pointers[11];
}
else {
Expand All @@ -307,6 +312,7 @@ class DiskPlotter {
log_num_buckets,
phases_flags);
p2.PrintElapsed("Time for phase 2 =");
phase_completion_callback(2);

// Now we open a new file, where the final contents of the plot will be stored.
uint32_t header_size = WriteHeader(tmp2_disk, k, id, memo, memo_len);
Expand All @@ -328,13 +334,15 @@ class DiskPlotter {
log_num_buckets,
phases_flags);
p3.PrintElapsed("Time for phase 3 =");
phase_completion_callback(3);

std::cout << std::endl
<< "Starting phase 4/4: Write Checkpoint tables into " << tmp_2_filename
<< " ... " << Timer::GetNow();
Timer p4;
RunPhase4(k, k + 1, tmp2_disk, res, phases_flags, 16);
p4.PrintElapsed("Time for phase 4 =");
phase_completion_callback(4);
finalsize = res.final_table_begin_pointers[11];
}

Expand Down