PaStiX Handbook  6.3.2
get_options.c
Go to the documentation of this file.
1 /**
2  *
3  * @file get_options.c
4  *
5  * @copyright 2006-2023 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6  * Univ. Bordeaux. All rights reserved.
7  *
8  * @version 6.3.2
9  * @author Mathieu Faverge
10  * @author Pierre Ramet
11  * @author Xavier Lacoste
12  * @author Esragul Korkmaz
13  * @author Gregoire Pichon
14  * @author Tony Delarue
15  * @author Alycia Lisito
16  * @date 2023-10-23
17  *
18  */
19 #include "common.h"
20 #include <unistd.h>
21 #if defined(HAVE_GETOPT_H)
22 #include <getopt.h>
23 #endif /* defined(HAVE_GETOPT_H) */
24 #include <string.h>
25 
26 /**
27  * @brief Print default usage for PaStiX binaries
28  */
29 static inline void
31 {
32  fprintf(stderr,
33  "Matrix input (mandatory):\n"
34  " -0 --rsa : RSA/Matrix Market Fortran driver (only real)\n"
35  " -1 --hb : Harwell Boeing C driver\n"
36  " -2 --ijv : IJV coordinate C driver\n"
37  " -3 --mm : Matrix Market C driver\n"
38  " -4 --spm : SPM Matrix driver\n"
39  " -9 --lap : Generate a Laplacian (5-points stencil)\n"
40  " -x --xlap : Generate an extended Laplacian (9-points stencil)\n"
41  " -G --graph : SCOTCH Graph file\n"
42  "\n"
43  "Architecture arguments:\n"
44  " -a --scatter : Scatter the spm when PaStiX is with MPI (default: 0)\n"
45  " 0: Replicate the spm, 1: Scatter the spm\n"
46  " -t --threads : Number of threads per node (default: -1 to use the number of cores available)\n"
47  " -g --gpus : Number of gpus per node (default: 0)\n"
48  " -s --sched : Set the default scheduler (default: 4)\n"
49  " 0: Sequential, 1: Static, 2: PaRSEC, 3: StarPU, 4: Dynamic\n"
50  "\n"
51  "Optional arguments:\n"
52  " -f --fact : Choose factorization method (default: LU)\n"
53  " 0: Cholesky / LL^[th], 1: sytrf / LDL^t, 2: getrf / LU, 3: LL^t, 4: hetrf / LDL^h\n"
54  " 3 and 4 are for complex matrices only\n"
55  " -c --check : Choose the level of check to perform (default: 1)\n"
56  " 0: None, 1: Backward error, 2: Backward and forward errors\n"
57  " -o --ord : Choose between ordering libraries (default: scotch)\n"
58  " scotch, ptscotch, metis, parmetis\n"
59  " -i --iparm <IPARM_ID> <value> : set any given integer parameter\n"
60  " -d --dparm <DPARM_ID> <value> : set any given floating parameter\n"
61  "\n"
62  " -v --verbose[=lvl] : extra verbose output\n"
63  " -h --help : this message\n"
64  "\n"
65  );
66 }
67 
68 /**
69  * @brief Define the options and their requirement used by PaStiX
70  */
71 #define GETOPT_STRING "0:1:2:3:4:9:x:G:a:t:g:s:o:f:c:i:d:v::h"
72 
73 #if defined(HAVE_GETOPT_LONG)
74 /**
75  * @brief Define the long options when getopt_long is available
76  */
77 static struct option long_options[] =
78 {
79  {"rsa", required_argument, 0, '0'},
80  {"hb", required_argument, 0, '1'},
81  {"ijv", required_argument, 0, '2'},
82  {"mm", required_argument, 0, '3'},
83  {"spm", required_argument, 0, '4'},
84  {"lap", required_argument, 0, '9'},
85  {"xlap", required_argument, 0, 'x'},
86  {"graph", required_argument, 0, 'G'},
87 
88  {"scatter", required_argument, 0, 'a'},
89  {"threads", required_argument, 0, 't'},
90  {"gpus", required_argument, 0, 'g'},
91  {"sched", required_argument, 0, 's'},
92 
93  {"ord", required_argument, 0, 'o'},
94  {"fact", required_argument, 0, 'f'},
95  {"check", required_argument, 0, 'c'},
96  {"iparm", required_argument, 0, 'i'},
97  {"dparm", required_argument, 0, 'd'},
98 
99  {"verbose", optional_argument, 0, 'v'},
100  {"help", no_argument, 0, 'h'},
101  {0, 0, 0, 0}
102 };
103 #endif /* defined(HAVE_GETOPT_LONG) */
104 
105 /**
106  *******************************************************************************
107  *
108  * @ingroup pastix_examples
109  *
110  * @brief PaStiX helper function to read command line options in examples.
111  *
112  * This function takes the command line arguments, and read the given parameters
113  * (integers and doubles), as well as the matrix filename and the driver to read
114  * it.
115  *
116  *******************************************************************************
117  *
118  * @param[in] argc
119  * The number of input parameters
120  *
121  * @param[in] argv
122  * The NULL terminated list of parameters
123  *
124  * @param[inout] iparam
125  * The integer array of parameters.
126  * On entry, must be initialized to the default value with pastixInitParam(),
127  * On exit, is updated with any option that matches the pastix parameters.
128  *
129  * @param[inout] dparam
130  * The double array of parameters.
131  * On entry, must be initialized to the default value with pastixInitParam(),
132  * On exit, is updated with any option that matches the pastix parameters.
133  *
134  * @param[inout] check
135  * On exit, the value is updated by the value of the -c option.
136  *
137  * @param[inout] scatter
138  * On exit, the value is updated by the value of the -a option.
139  *
140  * @param[inout] driver
141  * On exit, contains the driver type give as option. -1, if no driver
142  * is specified.
143  *
144  * @param[out] filename
145  * The allocated string of the filename given with the driver.
146  *
147  *******************************************************************************/
148 void
149 pastixGetOptions( int argc, char **argv,
150  pastix_int_t *iparam, double *dparam,
151  int *check, int *scatter, spm_driver_t *driver, char **filename )
152 {
153  int c;
154  (void)dparam;
155 
156  if (argc == 1) {
157  pastix_usage(); exit(0);
158  }
159 
160  *driver = -1;
161  do
162  {
163 #if defined(HAVE_GETOPT_LONG)
164  c = getopt_long( argc, argv, GETOPT_STRING,
165  long_options, NULL );
166 #else
167  c = getopt( argc, argv, GETOPT_STRING );
168 #endif /* defined(HAVE_GETOPT_LONG) */
169 
170  switch(c)
171  {
172  case '0':
173  fprintf(stderr, "RSA driver is no longer supported and is replaced by the HB driver\n");
174  pastix_attr_fallthrough;
175 
176  case '1':
177  *driver = SpmDriverHB;
178  *filename = strdup( optarg );
179  break;
180 
181  case '2':
182  *driver = SpmDriverIJV;
183  *filename = strdup( optarg );
184  break;
185 
186  case '3':
187  *driver = SpmDriverMM;
188  *filename = strdup( optarg );
189  break;
190 
191  case '4':
192  *driver = SpmDriverSPM;
193  *filename = strdup( optarg );
194  break;
195 
196  case '9':
197  *driver = SpmDriverLaplacian;
198  *filename = strdup( optarg );
199  break;
200 
201  case 'x':
202  *driver = SpmDriverXLaplacian;
203  *filename = strdup( optarg );
204  break;
205 
206  case 'G':
207  *driver = SpmDriverGraph;
208  *filename = strdup( optarg );
209  break;
210 
211  case 'a': {
212  int scattervalue = atoi( optarg );
213  if ( (scattervalue >= 0) && (scattervalue < 6) ) {
214  if ( scatter != NULL ) {
215  *scatter = scattervalue;
216  }
217  }
218  else {
219  fprintf(stderr, "\nInvalid value for scatter option: %s\n\n", optarg);
220  goto unknown_option;
221  }
222  }
223  break;
224 
225  case 't': iparam[IPARM_THREAD_NBR] = atoi(optarg); break;
226  case 'g': iparam[IPARM_GPU_NBR] = atoi(optarg); break;
227 
228  case 'o':
229  if (strncasecmp(optarg, "scotch", 6) == 0)
230  {
232  }
233  else if (strncasecmp(optarg, "metis", 5) == 0)
234  {
236  }
237  else if (strncasecmp(optarg, "ptscotch", 8) == 0)
238  {
240  }
241  else if (strncasecmp(optarg, "parmetis", 8) == 0)
242  {
244  }
245  else if (strncasecmp(optarg, "personal", 8) == 0)
246  {
248  }
249  else {
250  fprintf(stderr, "\nInvalid value for ordering option: %s\n\n", optarg);
251  goto unknown_option;
252  }
253  break;
254 
255  case 'f': {
256  int factotype = atoi( optarg );
257  if ( (factotype >= 0) && (factotype <= 4)){
258  iparam[IPARM_FACTORIZATION] = factotype;
259  }
260  else {
261  fprintf(stderr, "\nInvalid value for factorization option: %s\n\n", optarg);
262  goto unknown_option;
263  }
264  }
265  break;
266 
267  case 'c': {
268  int checkvalue = atoi( optarg );
269  if ( (checkvalue >= 0) && (checkvalue < 6) ) {
270  if ( check != NULL ) {
271  *check = checkvalue;
272  }
273  }
274  else {
275  fprintf(stderr, "\nInvalid value for check option: %s\n\n", optarg);
276  goto unknown_option;
277  }
278  }
279  break;
280 
281  case 's': {
282  int schedtype = atoi( optarg );
283  if ( (schedtype >= 0) && (schedtype <= 4) ){
284  iparam[IPARM_SCHEDULER] = schedtype;
285  }
286  else {
287  fprintf(stderr, "\nInvalid value for scheduler option: %s\n\n", optarg);
288  goto unknown_option;
289  }
290  }
291  break;
292 
293  case 'i':
294  {
295  pastix_iparm_t iparm_idx;
296  int iparm_val;
297 
298  /* Get iparm index */
299  iparm_idx = parse_iparm( optarg );
300  if ( iparm_idx == (pastix_iparm_t)-1 ) {
301  fprintf(stderr, "\n%s is not a correct iparm parameter\n\n", optarg );
302  goto unknown_option;
303  }
304 
305  /* Get iparm value */
306  iparm_val = parse_enums( argv[optind] );
307  if ( iparm_val == -1 ){
308  fprintf(stderr, "\n%s is not a correct value for the iparm parameters\n\n", argv[optind] );
309  goto unknown_option;
310  }
311  iparam[iparm_idx] = iparm_val;
312  }
313  break;
314 
315  case 'd':
316  {
317  pastix_dparm_t dparm_idx;
318  double dparm_val;
319 
320  /* Get iparm index */
321  dparm_idx = parse_dparm( optarg );
322  if ( dparm_idx == (pastix_dparm_t)-1 ) {
323  fprintf(stderr, "\n%s is not a correct dparm parameter\n\n", optarg );
324  goto unknown_option;
325  }
326 
327  /* Get iparm value */
328  dparm_val = atof( argv[optind] );
329  dparam[dparm_idx] = dparm_val;
330  }
331  break;
332 
333  case 'v':
334  if(optarg) iparam[IPARM_VERBOSE] = atoi(optarg);
335  else iparam[IPARM_VERBOSE] = 2;
336  break;
337 
338  case 'h':
339  pastix_usage(); exit(EXIT_FAILURE);
340 
341  case ':':
342  fprintf(stderr, "\nOption %c is missing an argument\n\n", c );
343  goto unknown_option;
344 
345  case '?': /* getopt_long already printed an error message. */
346  pastix_usage(); exit(EXIT_FAILURE);
347  default:
348  break;
349  }
350  } while(-1 != c);
351 
352  return;
353 
354  unknown_option:
355  pastix_usage(); exit(EXIT_FAILURE);
356 }
BEGIN_C_DECLS typedef int pastix_int_t
Definition: datatypes.h:51
static void pastix_usage(void)
Print default usage for PaStiX binaries.
Definition: get_options.c:30
#define GETOPT_STRING
Define the options and their requirement used by PaStiX.
Definition: get_options.c:71
BEGIN_C_DECLS enum pastix_iparm_e pastix_iparm_t
Integer parameters.
enum pastix_dparm_e pastix_dparm_t
Float parameters.
@ IPARM_FACTORIZATION
Definition: api.h:99
@ IPARM_GPU_NBR
Definition: api.h:123
@ IPARM_SCHEDULER
Definition: api.h:117
@ IPARM_ORDERING
Definition: api.h:50
@ IPARM_VERBOSE
Definition: api.h:36
@ IPARM_THREAD_NBR
Definition: api.h:118
@ PastixOrderPersonal
Definition: api.h:347
@ PastixOrderParMetis
Definition: api.h:349
@ PastixOrderScotch
Definition: api.h:345
@ PastixOrderMetis
Definition: api.h:346
@ PastixOrderPtScotch
Definition: api.h:348
void pastixGetOptions(int argc, char **argv, pastix_int_t *iparam, double *dparam, int *check, int *scatter, spm_driver_t *driver, char **filename)
PaStiX helper function to read command line options in examples.
Definition: get_options.c:149