From 5ca12e6a0c6ecbe663f57e6415899594bb57ecb4 Mon Sep 17 00:00:00 2001 From: eriedaberrie Date: Mon, 8 Jan 2024 17:35:48 -0800 Subject: [PATCH] Add a numerical progress tracker --- src/main.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 1aaaf43..f6b0d03 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -163,8 +163,9 @@ int main(int argc, char *argv[]) { std::filesystem::create_directory(out_dir); std::vector workers; - std::mutex it_lock; auto it = all_fires.begin(); + unsigned int n_done = 0; + std::mutex it_lock; auto wc = std::thread::hardware_concurrency(); if (wc == 0) { wc = 1; @@ -173,12 +174,13 @@ int main(int argc, char *argv[]) { } std::cout << "Starting " << wc << " worker threads..." << std::endl; for (unsigned int w = 1; w <= wc; w++) { - workers.push_back(std::thread([&it, &it_lock, &all_fires, &residentials, - &out_dir, w, distance]() { + workers.push_back(std::thread([&it, &n_done, &it_lock, &all_fires, + &residentials, &out_dir, w, distance]() { for (;;) { it_lock.lock(); if (it == all_fires.end()) { - std::cout << "Worker " << w << " done!" << std::endl; + std::cout << "Worker " << w << " done! (finished " << n_done + << "/" << all_fires.size() << ")" << std::endl; it_lock.unlock(); return; } @@ -186,7 +188,9 @@ int main(int argc, char *argv[]) { const auto& month_data = *(it++); auto& month = month_data.name; auto& month_fires = month_data.days; - std::cout << "Worker " << w << " processing data from " << month << "..." << std::endl; + std::cout << "Worker " << w << " processing data from " << month + << "... (finished " << n_done << "/" + << all_fires.size() << ")" << std::endl; it_lock.unlock(); std::ofstream outf(out_dir / (month + ".csv")); @@ -213,6 +217,12 @@ int main(int argc, char *argv[]) { } outf << '\n'; } + + { + std::lock_guard lk(it_lock); + + n_done++; + } } })); }