Add a numerical progress tracker
This commit is contained in:
parent
79e628055a
commit
5ca12e6a0c
20
src/main.cpp
20
src/main.cpp
|
@ -163,8 +163,9 @@ int main(int argc, char *argv[]) {
|
|||
std::filesystem::create_directory(out_dir);
|
||||
|
||||
std::vector<std::thread> 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<std::mutex> lk(it_lock);
|
||||
|
||||
n_done++;
|
||||
}
|
||||
}
|
||||
}));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue