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::filesystem::create_directory(out_dir);
|
||||||
|
|
||||||
std::vector<std::thread> workers;
|
std::vector<std::thread> workers;
|
||||||
std::mutex it_lock;
|
|
||||||
auto it = all_fires.begin();
|
auto it = all_fires.begin();
|
||||||
|
unsigned int n_done = 0;
|
||||||
|
std::mutex it_lock;
|
||||||
auto wc = std::thread::hardware_concurrency();
|
auto wc = std::thread::hardware_concurrency();
|
||||||
if (wc == 0) {
|
if (wc == 0) {
|
||||||
wc = 1;
|
wc = 1;
|
||||||
|
@ -173,12 +174,13 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
std::cout << "Starting " << wc << " worker threads..." << std::endl;
|
std::cout << "Starting " << wc << " worker threads..." << std::endl;
|
||||||
for (unsigned int w = 1; w <= wc; w++) {
|
for (unsigned int w = 1; w <= wc; w++) {
|
||||||
workers.push_back(std::thread([&it, &it_lock, &all_fires, &residentials,
|
workers.push_back(std::thread([&it, &n_done, &it_lock, &all_fires,
|
||||||
&out_dir, w, distance]() {
|
&residentials, &out_dir, w, distance]() {
|
||||||
for (;;) {
|
for (;;) {
|
||||||
it_lock.lock();
|
it_lock.lock();
|
||||||
if (it == all_fires.end()) {
|
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();
|
it_lock.unlock();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -186,7 +188,9 @@ int main(int argc, char *argv[]) {
|
||||||
const auto& month_data = *(it++);
|
const auto& month_data = *(it++);
|
||||||
auto& month = month_data.name;
|
auto& month = month_data.name;
|
||||||
auto& month_fires = month_data.days;
|
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();
|
it_lock.unlock();
|
||||||
|
|
||||||
std::ofstream outf(out_dir / (month + ".csv"));
|
std::ofstream outf(out_dir / (month + ".csv"));
|
||||||
|
@ -213,6 +217,12 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
outf << '\n';
|
outf << '\n';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
{
|
||||||
|
std::lock_guard<std::mutex> lk(it_lock);
|
||||||
|
|
||||||
|
n_done++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue