Add -j option
This commit is contained in:
parent
36e12d1e90
commit
1a5b1292ee
@ -96,11 +96,16 @@ static void * render_thread(void * varg)
|
|||||||
static void renderThreaded(Scene & scene,
|
static void renderThreaded(Scene & scene,
|
||||||
unsigned char * data,
|
unsigned char * data,
|
||||||
int width,
|
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 = sysconf(_SC_NPROCESSORS_ONLN);
|
||||||
if (num_threads < 1)
|
if (num_threads < 1)
|
||||||
num_threads = 1;
|
num_threads = 1;
|
||||||
|
}
|
||||||
|
|
||||||
render_thread_state_t state;
|
render_thread_state_t state;
|
||||||
state.scene = &scene;
|
state.scene = &scene;
|
||||||
@ -132,6 +137,7 @@ void usage(const char * progname)
|
|||||||
cout << " -d|--max-depth <max-recursion-depth>" << endl;
|
cout << " -d|--max-depth <max-recursion-depth>" << endl;
|
||||||
cout << " -a|--ambient-occlusion <ambient-occlusion-level>" << endl;
|
cout << " -a|--ambient-occlusion <ambient-occlusion-level>" << endl;
|
||||||
cout << " -p|--preview (means -w400 -h300 -m1 -d8 -a0)" << endl;
|
cout << " -p|--preview (means -w400 -h300 -m1 -d8 -a0)" << endl;
|
||||||
|
cout << " -j|--threads <num-threads> (default: number of cores)" << endl;
|
||||||
cout << " --hosts <hosts-file>" << endl;
|
cout << " --hosts <hosts-file>" << endl;
|
||||||
exit(42);
|
exit(42);
|
||||||
}
|
}
|
||||||
@ -194,6 +200,7 @@ int main(int argc, char * argv[])
|
|||||||
unsigned char * data = NULL;
|
unsigned char * data = NULL;
|
||||||
const char * output_file_name = "fart.bmp";
|
const char * output_file_name = "fart.bmp";
|
||||||
bool child = false;
|
bool child = false;
|
||||||
|
int num_threads = 0; /* 0 means auto-detect available cores */
|
||||||
|
|
||||||
static const struct option long_options[] = {
|
static const struct option long_options[] = {
|
||||||
{ "ambient-occlusion", required_argument, NULL, 'a' },
|
{ "ambient-occlusion", required_argument, NULL, 'a' },
|
||||||
@ -204,6 +211,7 @@ int main(int argc, char * argv[])
|
|||||||
{ "field-of-view", required_argument, NULL, 'f' },
|
{ "field-of-view", required_argument, NULL, 'f' },
|
||||||
{ "max-depth", required_argument, NULL, 'd' },
|
{ "max-depth", required_argument, NULL, 'd' },
|
||||||
{ "preview", no_argument, NULL, 'p' },
|
{ "preview", no_argument, NULL, 'p' },
|
||||||
|
{ "threads", required_argument, NULL, 'j' },
|
||||||
{ "help", no_argument, NULL, 256 },
|
{ "help", no_argument, NULL, 256 },
|
||||||
{ "host", required_argument, NULL, 257 },
|
{ "host", required_argument, NULL, 257 },
|
||||||
{ "port", required_argument, NULL, 258 },
|
{ "port", required_argument, NULL, 258 },
|
||||||
@ -212,7 +220,7 @@ int main(int argc, char * argv[])
|
|||||||
{ NULL, 0, NULL, 0 }
|
{ 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)
|
long_options, &option_index)) != -1)
|
||||||
{
|
{
|
||||||
switch (opt)
|
switch (opt)
|
||||||
@ -258,6 +266,9 @@ int main(int argc, char * argv[])
|
|||||||
scene_options["max-depth"] = "8";
|
scene_options["max-depth"] = "8";
|
||||||
client_options.push_back("--preview");
|
client_options.push_back("--preview");
|
||||||
break;
|
break;
|
||||||
|
case 'j':
|
||||||
|
num_threads = atoi(optarg);
|
||||||
|
break;
|
||||||
case 256:
|
case 256:
|
||||||
usage(argv[0]);
|
usage(argv[0]);
|
||||||
break;
|
break;
|
||||||
@ -378,8 +389,8 @@ int main(int argc, char * argv[])
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* local multithreaded render using all available cores */
|
/* local multithreaded render; num_threads of 0 auto-detects cores */
|
||||||
renderThreaded(scene, data, width, height);
|
renderThreaded(scene, data, width, height, num_threads);
|
||||||
}
|
}
|
||||||
|
|
||||||
gettimeofday(&after, NULL); /* stop timing */
|
gettimeofday(&after, NULL); /* stop timing */
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user