PaStiX Handbook 6.4.0
Loading...
Searching...
No Matches
get_options.c
Go to the documentation of this file.
1/**
2 *
3 * @file get_options.c
4 *
5 * @copyright 2006-2025 Bordeaux INP, CNRS (LaBRI UMR 5800), Inria,
6 * Univ. Bordeaux. All rights reserved.
7 *
8 * @version 6.4.0
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 2024-07-05
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 */
29static 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 */
77static 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 *******************************************************************************/
148void
149pastixGetOptions( 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 ( driver ) {
157 *driver = -1;
158 }
159
160 do
161 {
162#if defined(HAVE_GETOPT_LONG)
163 c = getopt_long( argc, argv, GETOPT_STRING,
164 long_options, NULL );
165#else
166 c = getopt( argc, argv, GETOPT_STRING );
167#endif /* defined(HAVE_GETOPT_LONG) */
168
169 switch(c)
170 {
171 case '0':
172 fprintf(stderr, "RSA driver is no longer supported and is replaced by the HB driver\n");
173 pastix_attr_fallthrough;
174
175 case '1':
176 if ( driver ) {
177 *driver = SpmDriverHB;
178 }
179 if ( filename ) {
180 *filename = strdup( optarg );
181 }
182 break;
183
184 case '2':
185 if ( driver ) {
186 *driver = SpmDriverIJV;
187 }
188 if ( filename ) {
189 *filename = strdup( optarg );
190 }
191 break;
192
193 case '3':
194 if ( driver ) {
195 *driver = SpmDriverMM;
196 }
197 if ( filename ) {
198 *filename = strdup( optarg );
199 }
200 break;
201
202 case '4':
203 if ( driver ) {
204 *driver = SpmDriverSPM;
205 }
206 if ( filename ) {
207 *filename = strdup( optarg );
208 }
209 break;
210
211 case '9':
212 if ( driver ) {
213 *driver = SpmDriverLaplacian;
214 }
215 if ( filename ) {
216 *filename = strdup( optarg );
217 }
218 break;
219
220 case 'x':
221 if ( driver ) {
222 *driver = SpmDriverXLaplacian;
223 }
224 if ( filename ) {
225 *filename = strdup( optarg );
226 }
227 break;
228
229 case 'G':
230 if ( driver ) {
231 *driver = SpmDriverGraph;
232 }
233 if ( filename ) {
234 *filename = strdup( optarg );
235 }
236 break;
237
238 case 'a': {
239 int scattervalue = atoi( optarg );
240 if ( (scattervalue >= 0) && (scattervalue < 6) ) {
241 if ( scatter != NULL ) {
242 *scatter = scattervalue;
243 }
244 }
245 else {
246 fprintf(stderr, "\nInvalid value for scatter option: %s\n\n", optarg);
247 goto unknown_option;
248 }
249 }
250 break;
251
252 case 't': iparam[IPARM_THREAD_NBR] = atoi(optarg); break;
253 case 'g': iparam[IPARM_GPU_NBR] = atoi(optarg); break;
254
255 case 'o':
256 if (strncasecmp(optarg, "scotch", 6) == 0)
257 {
259 }
260 else if (strncasecmp(optarg, "metis", 5) == 0)
261 {
263 }
264 else if (strncasecmp(optarg, "ptscotch", 8) == 0)
265 {
267 }
268 else if (strncasecmp(optarg, "parmetis", 8) == 0)
269 {
271 }
272 else if (strncasecmp(optarg, "personal", 8) == 0)
273 {
275 }
276 else {
277 fprintf(stderr, "\nInvalid value for ordering option: %s\n\n", optarg);
278 goto unknown_option;
279 }
280 break;
281
282 case 'f': {
283 int factotype = atoi( optarg );
284 if ( (factotype >= 0) && (factotype <= 4)){
285 iparam[IPARM_FACTORIZATION] = factotype;
286 }
287 else {
288 fprintf(stderr, "\nInvalid value for factorization option: %s\n\n", optarg);
289 goto unknown_option;
290 }
291 }
292 break;
293
294 case 'c': {
295 int checkvalue = atoi( optarg );
296 if ( (checkvalue >= 0) && (checkvalue < 6) ) {
297 if ( check != NULL ) {
298 *check = checkvalue;
299 }
300 }
301 else {
302 fprintf(stderr, "\nInvalid value for check option: %s\n\n", optarg);
303 goto unknown_option;
304 }
305 }
306 break;
307
308 case 's': {
309 int schedtype = atoi( optarg );
310 if ( (schedtype >= 0) && (schedtype <= 4) ){
311 iparam[IPARM_SCHEDULER] = schedtype;
312 }
313 else {
314 fprintf(stderr, "\nInvalid value for scheduler option: %s\n\n", optarg);
315 goto unknown_option;
316 }
317 }
318 break;
319
320 case 'i':
321 {
322 pastix_iparm_t iparm_idx;
323 int iparm_val;
324
325 /* Get iparm index */
326 iparm_idx = parse_iparm( optarg );
327 if ( iparm_idx == (pastix_iparm_t)-1 ) {
328 fprintf(stderr, "\n%s is not a correct iparm parameter\n\n", optarg );
329 goto unknown_option;
330 }
331
332 /* Get iparm value */
333 iparm_val = parse_enums( argv[optind] );
334 if ( iparm_val == -1 ){
335 fprintf(stderr, "\n%s is not a correct value for the iparm parameters\n\n", argv[optind] );
336 goto unknown_option;
337 }
338 iparam[iparm_idx] = iparm_val;
339 }
340 break;
341
342 case 'd':
343 {
344 pastix_dparm_t dparm_idx;
345 double dparm_val;
346
347 /* Get iparm index */
348 dparm_idx = parse_dparm( optarg );
349 if ( dparm_idx == (pastix_dparm_t)-1 ) {
350 fprintf(stderr, "\n%s is not a correct dparm parameter\n\n", optarg );
351 goto unknown_option;
352 }
353
354 /* Get iparm value */
355 dparm_val = atof( argv[optind] );
356 dparam[dparm_idx] = dparm_val;
357 }
358 break;
359
360 case 'v':
361 if(optarg) iparam[IPARM_VERBOSE] = atoi(optarg);
362 else iparam[IPARM_VERBOSE] = 2;
363 break;
364
365 case 'h':
366 pastix_usage(); exit(EXIT_FAILURE);
367
368 case ':':
369 fprintf(stderr, "\nOption %c is missing an argument\n\n", c );
370 goto unknown_option;
371
372 case '?': /* getopt_long already printed an error message. */
373 pastix_usage(); exit(EXIT_FAILURE);
374 default:
375 break;
376 }
377 } while(-1 != c);
378
379
380 if ( driver && ( (int)(*driver) == -1 ) ) {
381 pastix_usage(); exit(0);
382 }
383
384 return;
385
386 unknown_option:
387 pastix_usage(); exit(EXIT_FAILURE);
388}
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.