Add -j flag for job count
This commit is contained in:
parent
5ca12e6a0c
commit
d218af9c4a
21
src/main.cpp
21
src/main.cpp
|
@ -18,10 +18,11 @@ struct month_info {
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
unsigned int distance = 2'000;
|
unsigned int distance = 2'000;
|
||||||
std::string fire_dir = "fires";
|
std::string fire_dir = "fires";
|
||||||
|
unsigned int wc = 0;
|
||||||
std::filesystem::path out_dir = "out";
|
std::filesystem::path out_dir = "out";
|
||||||
auto do_sort = false;
|
auto do_sort = false;
|
||||||
int c;
|
int c;
|
||||||
while ((c = getopt(argc, argv, "d:f:o:s")) != -1) {
|
while ((c = getopt(argc, argv, "d:f:j:o:s")) != -1) {
|
||||||
switch (c) {
|
switch (c) {
|
||||||
case 'd':
|
case 'd':
|
||||||
distance = atoi(optarg);
|
distance = atoi(optarg);
|
||||||
|
@ -29,6 +30,9 @@ int main(int argc, char *argv[]) {
|
||||||
case 'f':
|
case 'f':
|
||||||
fire_dir = optarg;
|
fire_dir = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
wc = atoi(optarg);
|
||||||
|
break;
|
||||||
case 'o':
|
case 'o':
|
||||||
out_dir = optarg;
|
out_dir = optarg;
|
||||||
break;
|
break;
|
||||||
|
@ -47,6 +51,15 @@ int main(int argc, char *argv[]) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (wc == 0) {
|
||||||
|
wc = std::thread::hardware_concurrency();
|
||||||
|
if (wc == 0) {
|
||||||
|
wc = 1;
|
||||||
|
} else if (wc > 1) {
|
||||||
|
wc--;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
char *res_loc;
|
char *res_loc;
|
||||||
switch (argc - optind) {
|
switch (argc - optind) {
|
||||||
case 0: {
|
case 0: {
|
||||||
|
@ -166,12 +179,6 @@ int main(int argc, char *argv[]) {
|
||||||
auto it = all_fires.begin();
|
auto it = all_fires.begin();
|
||||||
unsigned int n_done = 0;
|
unsigned int n_done = 0;
|
||||||
std::mutex it_lock;
|
std::mutex it_lock;
|
||||||
auto wc = std::thread::hardware_concurrency();
|
|
||||||
if (wc == 0) {
|
|
||||||
wc = 1;
|
|
||||||
} else if (wc > 1) {
|
|
||||||
wc--;
|
|
||||||
}
|
|
||||||
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, &n_done, &it_lock, &all_fires,
|
workers.push_back(std::thread([&it, &n_done, &it_lock, &all_fires,
|
||||||
|
|
Loading…
Reference in a new issue