Actual source code: ex5.c


  2: static char help[] = "Tests retrieving unused PETSc options.\n\n";

  4: #include <petscsys.h>

  6: int main(int argc, char **argv)
  7: {
  8:   PetscInt  i, N, M;
  9:   char    **names, **values;
 10:   PetscBool set;

 12:   PetscFunctionBeginUser;
 13:   PetscCall(PetscInitialize(&argc, &argv, (char *)0, help));

 15:   PetscCall(PetscOptionsGetInt(NULL, NULL, "-get_an_integer", &M, &set));
 16:   if (set) PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option used: name:-get_an_integer value: %" PetscInt_FMT "\n", M));
 17:   PetscCall(PetscOptionsLeftGet(NULL, &N, &names, &values));
 18:   for (i = 0; i < N; i++) {
 19:     if (values[i]) {
 20:       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option left: name:-%s value: %s\n", names[i], values[i]));
 21:     } else {
 22:       PetscCall(PetscPrintf(PETSC_COMM_WORLD, "Option left: name:-%s (no value)\n", names[i]));
 23:     }
 24:   }
 25:   PetscCall(PetscOptionsLeftRestore(NULL, &N, &names, &values));

 27:   PetscCall(PetscFinalize());
 28:   return 0;
 29: }

 31: /*TEST

 33:    test:
 34:       suffix: debug
 35:       requires: defined(PETSC_USE_DEBUG)
 36:       args: -unused_petsc_option_1 -unused_petsc_option_2 -get_an_integer 10 -options_left no

 38:    test:
 39:       suffix: opt
 40:       requires: !defined(PETSC_USE_DEBUG)
 41:       args: -unused_petsc_option_1 -unused_petsc_option_2 -get_an_integer 10 -options_left no

 43:  TEST*/