xref: /petsc/src/sys/tests/ex5.c (revision 0baf8eba40dbc839082666f9f7396a225d6f663c)
1 static char help[] = "Tests retrieving unused PETSc options.\n\n";
2 
3 #include <petscsys.h>
4 
5 int main(int argc, char **argv)
6 {
7   PetscInt  i, N, M;
8   char    **names, **values;
9   PetscBool set;
10 
11   PetscFunctionBeginUser;
12   PetscCall(PetscInitialize(&argc, &argv, NULL, help));
13 
14   PetscCall(PetscOptionsGetInt(NULL, NULL, "-get_an_integer", &M, &set));
15   if (set) PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option used: name:-get_an_integer value: %" PetscInt_FMT "\n", M));
16   PetscCall(PetscOptionsLeftGet(NULL, &N, &names, &values));
17   for (i = 0; i < N; i++) {
18     if (values[i]) {
19       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option left: name:-%s value: %s\n", names[i], values[i]));
20     } else {
21       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option left: name:-%s (no value)\n", names[i]));
22     }
23   }
24   PetscCall(PetscOptionsLeftRestore(NULL, &N, &names, &values));
25 
26   PetscCall(PetscFinalize());
27   return 0;
28 }
29 
30 /*TEST
31 
32    test:
33       suffix: debug
34       requires: defined(PETSC_USE_DEBUG)
35       args: -unused_petsc_option_1 -unused_petsc_option_2 -get_an_integer 10 -options_left no
36 
37    test:
38       suffix: opt
39       requires: !defined(PETSC_USE_DEBUG)
40       args: -unused_petsc_option_1 -unused_petsc_option_2 -get_an_integer 10 -options_left no
41 
42  TEST*/
43