diff --git a/src/main/fart.cc b/src/main/fart.cc index 3ceb2f2..7797bad 100644 --- a/src/main/fart.cc +++ b/src/main/fart.cc @@ -96,11 +96,16 @@ static void * render_thread(void * varg) static void renderThreaded(Scene & scene, unsigned char * data, int width, - int height) + int height, + int num_threads) { - int num_threads = sysconf(_SC_NPROCESSORS_ONLN); + /* a non-positive override means auto-detect the available cores */ if (num_threads < 1) - num_threads = 1; + { + num_threads = sysconf(_SC_NPROCESSORS_ONLN); + if (num_threads < 1) + num_threads = 1; + } render_thread_state_t state; state.scene = &scene; @@ -132,6 +137,7 @@ void usage(const char * progname) cout << " -d|--max-depth " << endl; cout << " -a|--ambient-occlusion " << endl; cout << " -p|--preview (means -w400 -h300 -m1 -d8 -a0)" << endl; + cout << " -j|--threads (default: number of cores)" << endl; cout << " --hosts " << endl; exit(42); } @@ -194,6 +200,7 @@ int main(int argc, char * argv[]) unsigned char * data = NULL; const char * output_file_name = "fart.bmp"; bool child = false; + int num_threads = 0; /* 0 means auto-detect available cores */ static const struct option long_options[] = { { "ambient-occlusion", required_argument, NULL, 'a' }, @@ -204,6 +211,7 @@ int main(int argc, char * argv[]) { "field-of-view", required_argument, NULL, 'f' }, { "max-depth", required_argument, NULL, 'd' }, { "preview", no_argument, NULL, 'p' }, + { "threads", required_argument, NULL, 'j' }, { "help", no_argument, NULL, 256 }, { "host", required_argument, NULL, 257 }, { "port", required_argument, NULL, 258 }, @@ -212,7 +220,7 @@ int main(int argc, char * argv[]) { NULL, 0, NULL, 0 } }; - while ((opt = getopt_long(argc, argv, "a:o:w:h:m:f:d:p", + while ((opt = getopt_long(argc, argv, "a:o:w:h:m:f:d:pj:", long_options, &option_index)) != -1) { switch (opt) @@ -258,6 +266,9 @@ int main(int argc, char * argv[]) scene_options["max-depth"] = "8"; client_options.push_back("--preview"); break; + case 'j': + num_threads = atoi(optarg); + break; case 256: usage(argv[0]); break; @@ -378,8 +389,8 @@ int main(int argc, char * argv[]) } else { - /* local multithreaded render using all available cores */ - renderThreaded(scene, data, width, height); + /* local multithreaded render; num_threads of 0 auto-detects cores */ + renderThreaded(scene, data, width, height, num_threads); } gettimeofday(&after, NULL); /* stop timing */