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