[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnuastro-commits] master 8f84b2b 2/4: Automaticly read number of thread
From: |
Mohammad Akhlaghi |
Subject: |
[gnuastro-commits] master 8f84b2b 2/4: Automaticly read number of threads when --numthreads=0 |
Date: |
Sun, 1 Oct 2017 21:51:33 -0400 (EDT) |
branch: master
commit 8f84b2b723b16d5b2851d13beb9b5a0b4100f977
Author: Mohammad Akhlaghi <address@hidden>
Commit: Mohammad Akhlaghi <address@hidden>
Automaticly read number of threads when --numthreads=0
When a later configuration file has a fixed value for `--numthreads', until
now there was no way to over-write it with the maximum number of threads
available to the system (which changes from system to system). Also until
now, a value of `0' was unacceptable for this option.
With this commit, when this option has a value of `0', the maximum number
of threads available to the system will be read at the end of
option-parsing and will be used. This will allow you to over-write a fixed
value in a configuration file.
---
NEWS | 3 +++
bin/crop/ui.c | 3 ++-
doc/gnuastro.texi | 29 ++++++++++++++++-------------
lib/gnuastro-internal/commonopts.h | 2 +-
lib/options.c | 6 ++++++
5 files changed, 28 insertions(+), 15 deletions(-)
diff --git a/NEWS b/NEWS
index a5b711b..04e9a28 100644
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,9 @@ GNU Astronomy Utilities NEWS -*-
outline -*-
** New features
+ All programs: a value of `0' to the `--numthreads' option will use the
+ number of threads available to the system at run time.
+
Fits: when an extension/HDU is identified on the command-line with the
`--hdu' option and no operation is requested, the full list of header
keywords in that HDU will be printed (as if only `--printallkeys' was
diff --git a/bin/crop/ui.c b/bin/crop/ui.c
index 9c72b7a..c4336f1 100644
--- a/bin/crop/ui.c
+++ b/bin/crop/ui.c
@@ -379,7 +379,8 @@ ui_read_check_only_options(struct cropparams *p)
if(p->section && p->mode!=IMGCROP_MODE_IMG)
error(EXIT_FAILURE, 0, "The `--section' option is only available in "
"image coordinate mode, currently it doesn't work with WCS mode. "
- "Please run with `--mode=img' and change the values accordingly");
+ "Please run with `--mode=img' and if necessary, change the "
+ "values accordingly");
/* Sanity checks and mode setting based on the desired crop. */
diff --git a/doc/gnuastro.texi b/doc/gnuastro.texi
index 1bcd7d6..c2ce490 100644
--- a/doc/gnuastro.texi
+++ b/doc/gnuastro.texi
@@ -4931,10 +4931,13 @@ ignored.
@item -N INT
@itemx --numthreads=INT
Use @option{INT} CPU threads when running a Gnuastro program (see
address@hidden operations}). Note that multi-threaded programming is only
-relevant to some programs. In others, this option will be ignored. If this
-option is not specified on the command-line or any configuration file, the
-number of threads will be determined by the programs at configuration time.
address@hidden operations}). If the value is zero (@code{0}), or this
+option is not given on the command-line or any configuration file, the
+value will be determined at run-time: the maximum number of threads
+available to the system when you run a Gnuastro program.
+
+Note that multi-threaded programming is only relevant to some programs. In
+others, this option will be ignored.
@end vtable
@@ -4973,15 +4976,15 @@ necessary parameters are not given through any of these
methods, the
program will print a missing option error and abort. The only exception to
this is @option{--numthreads}, whose default value is determined at
run-time using the number of threads available to your system, see
address@hidden operations}. Of course, you can still provide a default value
-for the number of threads at any of the levels below, but if you don't, the
-program will not abort. Also note that through automatic output name
-generation, the value to the @option{--output} option is also not mandatory
-on the command-line or in the configuration files for all programs which
-don't rely on that value as an address@hidden example of a program
-which uses the value given to @option{--output} as an input is ConvertType,
-this value specifies the type of the output through the value to
address@hidden, see @ref{Invoking astconvertt}.}, see @ref{Automatic
address@hidden operations}. Of course, you can still provide a default
+value for the number of threads at any of the levels below, but if you
+don't, the program will not abort. Also note that through automatic output
+name generation, the value to the @option{--output} option is also not
+mandatory on the command-line or in the configuration files for all
+programs which don't rely on that value as an address@hidden example of
+a program which uses the value given to @option{--output} as an input is
+ConvertType, this value specifies the type of the output through the value
+to @option{--output}, see @ref{Invoking astconvertt}.}, see @ref{Automatic
output}.
diff --git a/lib/gnuastro-internal/commonopts.h
b/lib/gnuastro-internal/commonopts.h
index be69dee..735ac5c 100644
--- a/lib/gnuastro-internal/commonopts.h
+++ b/lib/gnuastro-internal/commonopts.h
@@ -306,7 +306,7 @@ struct argp_option gal_commonopts_options[] =
GAL_OPTIONS_GROUP_OPERATING_MODE,
&cp->numthreads,
GAL_TYPE_SIZE_T,
- GAL_OPTIONS_RANGE_GT_0,
+ GAL_OPTIONS_RANGE_GE_0,
GAL_OPTIONS_NOT_MANDATORY,
GAL_OPTIONS_NOT_SET
},
diff --git a/lib/options.c b/lib/options.c
index 6b0b202..edde624 100644
--- a/lib/options.c
+++ b/lib/options.c
@@ -34,6 +34,7 @@ along with Gnuastro. If not, see
<http://www.gnu.org/licenses/>.
#include <gnuastro/data.h>
#include <gnuastro/table.h>
#include <gnuastro/blank.h>
+#include <gnuastro/threads.h>
#include <gnuastro/arithmetic.h>
#include <gnuastro-internal/timing.h>
@@ -1601,6 +1602,11 @@ gal_options_read_config_set(struct
gal_options_common_params *cp)
/* Abort if any of the mandatory options are not set. */
gal_options_abort_if_mandatory_missing(cp);
+
+ /* If `numthreads' is 0, use the number of threads available to the
+ system. */
+ if(cp->numthreads==0)
+ cp->numthreads=gal_threads_number();
}