#include "main.h"
#include "md_logging.h"
#include "gromacs/utility/gmxomp.h"
+#include "gromacs/utility/cstringutil.h"
#include "thread_mpi/threads.h"
md_print_info(cr, fplog, "%s\n\n", sbuf);
}
-/* Parse a "plain" GPU ID string which contains a sequence of digits corresponding
- * to GPU IDs; the order will indicate the process/tMPI thread - GPU assignment. */
-static void parse_gpu_id_plain_string(const char *idstr, int *nid, int **idlist)
-{
- int i;
-
- *nid = strlen(idstr);
-
- snew(*idlist, *nid);
-
- for (i = 0; i < *nid; i++)
- {
- if (idstr[i] < '0' || idstr[i] > '9')
- {
- gmx_fatal(FARGS, "Invalid character in GPU ID string: '%c'\n%s\n",
- idstr[i], invalid_gpuid_hint);
- }
- (*idlist)[i] = idstr[i] - '0';
- }
-}
-
-static void parse_gpu_id_csv_string(const char gmx_unused *idstr, int gmx_unused *nid, int gmx_unused *idlist)
-{
- /* XXX implement cvs format to support more than 10 different GPUs in a box. */
- gmx_incons("Not implemented yet");
-}
-
/* Give a suitable fatal error or warning if the build configuration
and runtime CPU do not match. */
static void
/* parse GPU IDs if the user passed any */
if (env != NULL)
{
- parse_gpu_id_plain_string(env,
- &gpu_opt->ncuda_dev_use,
- &gpu_opt->cuda_dev_use);
+ /* Parse a "plain" GPU ID string which contains a sequence of
+ * digits corresponding to GPU IDs; the order will indicate
+ * the process/tMPI thread - GPU assignment. */
+ parse_digits_from_plain_string(env,
+ &gpu_opt->ncuda_dev_use,
+ &gpu_opt->cuda_dev_use);
if (gpu_opt->ncuda_dev_use == 0)
{
return _strtoi64(str, endptr, 10);
#endif
}
+
+void parse_digits_from_plain_string(const char *digitstring, int *ndigits, int **digitlist)
+{
+ int i;
+
+ if (NULL == digitstring)
+ {
+ *ndigits = 0;
+ *digitlist = NULL;
+ return;
+ }
+
+ *ndigits = strlen(digitstring);
+
+ snew(*digitlist, *ndigits);
+
+ for (i = 0; i < *ndigits; i++)
+ {
+ if (digitstring[i] < '0' || digitstring[i] > '9')
+ {
+ gmx_fatal(FARGS, "Invalid character in digit-only string: '%c'\n",
+ digitstring[i]);
+ }
+ (*digitlist)[i] = digitstring[i] - '0';
+ }
+}
+
+static void parse_digits_from_csv_string(const char gmx_unused *digitstring, int gmx_unused *ndigits, int gmx_unused *digitlist)
+{
+ /* TODO Implement csv format to support (e.g.) more than 10
+ different GPUs in a node. */
+ gmx_incons("Not implemented yet");
+}
#define snprintf _snprintf
#endif
+/*! \brief Construct an array of digits found in the input string
+ *
+ * \param[in] digitstring String that must contain only digits
+ * \param[out] ndigits Size of return array with the values of the digits
+ * \param[out] digitlist Array of digits found in
+ * digitstring. Allocated by this function
+ * with size *ndigits. Calling code is
+ * responsible for deallocation.
+ *
+ * If digitstring is NULL, then ndigits is set to zero and digitlist
+ * to NULL. If digitstring contains a non-digit character, a fatal
+ * error results.
+ */
+void parse_digits_from_plain_string(const char *digitstring, int *ndigits, int **digitlist);
+
#ifdef __cplusplus
}
#endif