commit 9774260ae8e1784fb1da25f6ad3b98ed19bab19f
parent b178f1023eceed4600b5a026b32c2ba07dd23551
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 25 Jan 2017 16:19:22 +0100
Add the -t option
Control how many threads are used by the solver.
Diffstat:
4 files changed, 24 insertions(+), 12 deletions(-)
diff --git a/doc/cli b/doc/cli
@@ -8,6 +8,7 @@ solstice
-n INTEGER # Realisations count
-r <rendering> # Switch in rendering mode
-R FILE # receivers
+ -t INTEGER # Threads count
INPUT # Input scene in YAML
solstice -r img=1280x720:pos=0,100,0:tgt=0,0,0:up=0,1,0:fov=70
diff --git a/src/solstice.c b/src/solstice.c
@@ -353,8 +353,7 @@ solstice_init
solstice->allocator = allocator ? allocator : &mem_default_allocator;
- res = ssol_device_create
- (NULL, allocator, SSOL_NTHREADS_DEFAULT, 0, &solstice->ssol);
+ res = ssol_device_create(NULL, allocator, args->nthreads, 0, &solstice->ssol);
if(res != RES_OK) {
fprintf(stderr, "Could not create the Solstice Solver device.\n");
goto error;
diff --git a/src/solstice_args.c b/src/solstice_args.c
@@ -42,24 +42,27 @@ print_help(const char* program)
"not define, the solar facility is read from standard input.\n\n",
program);
printf(
-" -D <dirs> list of sun directions.\n");
+" -D <dirs> list of sun directions.\n");
printf(
-" -H output the per receiver hit data.\n");
+" -H output the per receiver hit data.\n");
printf(
-" -h display this help and exit.\n");
+" -h display this help and exit.\n");
printf(
-" -n number of realisation. Default is %lu.\n",
+" -n REALISATIONS number of realisation. Default is %lu.\n",
SOLSTICE_ARGS_DEFAULT.nrealisations);
printf(
-" -o write results to OUTPUT. If not define, write results to\n");
+" -o write results to OUTPUT. If not define, write results to\n");
printf(
-" standard output.\n");
+" standard output.\n");
printf(
-" -q do not print the helper message when no FILE is submitted.\n");
+" -q do not print the helper message when no FILE is submitted.\n");
printf(
-" -R RECEIVERS define the file from which the list of receivers are read.\n");
+" -R RECEIVERS define the file from which the list of receivers are read.\n");
printf(
-" -r <rendering> switch in rendering mode and configure it.\n");
+" -r <rendering> switch in rendering mode and configure it.\n");
+ printf(
+" -t THREADS hint on the number of threads to use. By default use as\n"
+" many threads as CPU cores.\n");
printf("\n");
printf(
"Solstice (C) 2016-2017 CNRS. This is a free software released under the GNU GPL\n"
@@ -314,6 +317,7 @@ error:
res_T
solstice_args_init(struct solstice_args* args, const int argc, char** argv)
{
+ unsigned long ul = 0;
int opt;
res_T res = RES_OK;
ASSERT(args && argc && argv);
@@ -321,7 +325,7 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
*args = SOLSTICE_ARGS_DEFAULT;
optind = 1;
- while((opt = getopt(argc, argv, "D:Hhn:o:qR:r:")) != -1) {
+ while((opt = getopt(argc, argv, "D:Hhn:o:qR:r:t:")) != -1) {
switch(opt) {
case 'D':
res = parse_sun_dir_list(optarg, args);
@@ -340,6 +344,11 @@ solstice_args_init(struct solstice_args* args, const int argc, char** argv)
case 'q': args->quiet = 1; break;
case 'R': args->receivers_filename = optarg; break;
case 'r': res = parse_rendering_options(optarg, args); break;
+ case 't':
+ res = cstr_to_ulong(optarg, &ul);
+ if(res != RES_OK && !ul) res = RES_BAD_ARG;
+ args->nthreads = (unsigned)MMIN(ul, UINT_MAX);
+ break;
default: res = RES_BAD_ARG; break;
}
if(res != RES_OK) {
diff --git a/src/solstice_args.h.in b/src/solstice_args.h.in
@@ -17,6 +17,7 @@
#define SOLSTICE_ARGS_H
#include <rsys/math.h>
+#include <solstice/ssol.h>
struct solstice_args_spherical {
double azimuth; /* In radians */
@@ -28,6 +29,7 @@ struct solstice_args {
const char* input_filename; /* May be NULL <=> read data from stdin */
const char* receivers_filename;
unsigned long nrealisations; /* #realisations */
+ unsigned nthreads; /* #threads */
/* List of sun directions */
struct solstice_args_spherical* sun_dirs;
@@ -59,6 +61,7 @@ static const struct solstice_args SOLSTICE_ARGS_NULL = SOLSTICE_ARGS_NULL__;
NULL, /* input_filename */ \
NULL, /* receivers_filename */ \
@SOLSTICE_ARGS_DEFAULT_NREALISATIONS@, \
+ SSOL_NTHREADS_DEFAULT, \
\
NULL, /* sun_dirs */ \
0, /* # nsun_dirs */ \