Actual source code: ex55.c

  1: static char help[] = "Tests options database monitoring and precedence.\n\n";

  3: #include <petscsys.h>
  4: #include <petscviewer.h>

  6: PetscErrorCode PetscOptionsMonitorCustom(const char name[], const char value[], PetscOptionSource source, void *ctx)
  7: {
  8:   PetscViewer viewer = (PetscViewer)ctx;

 10:   PetscFunctionBegin;
 11:   if (!value) {
 12:     PetscCall(PetscViewerASCIIPrintf(viewer, "* Removing option: %s\n", name));
 13:   } else if (!value[0]) {
 14:     PetscCall(PetscViewerASCIIPrintf(viewer, "* Setting option: %s (no value)\n", name));
 15:   } else {
 16:     PetscCall(PetscViewerASCIIPrintf(viewer, "* Setting option: %s = %s\n", name, value));
 17:   }
 18:   PetscFunctionReturn(PETSC_SUCCESS);
 19: }

 21: int main(int argc, char **argv)
 22: {
 23:   PetscViewer       viewer = NULL;
 24:   PetscViewerFormat format;

 26:   PetscFunctionBeginUser;
 27:   PetscCall(PetscInitialize(&argc, &argv, "ex55options", help));
 28:   PetscCall(PetscOptionsInsertString(NULL, "-option1 1 -option2 -option3 value3"));
 29:   PetscCall(PetscOptionsCreateViewer(PETSC_COMM_WORLD, NULL, NULL, "-options_monitor_viewer", &viewer, &format, NULL));
 30:   if (viewer) {
 31:     PetscCall(PetscViewerPushFormat(viewer, format));
 32:     PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorCustom, viewer, NULL));
 33:     PetscCall(PetscViewerPopFormat(viewer));
 34:     PetscCall(PetscViewerDestroy(&viewer));
 35:   }
 36:   PetscCall(PetscOptionsInsertString(NULL, "-option4 value4 -option5"));
 37:   PetscCall(PetscOptionsClearValue(NULL, "-option5"));
 38:   PetscCall(PetscFinalize());
 39:   return 0;
 40: }

 42: /*TEST

 44:    testset:
 45:       localrunfiles: ex55options .petscrc petscrc
 46:       args: -options_left 0 -options_view -options_monitor_viewer ascii
 47:       args: -skip_petscrc {{0 1}separate output} -options_monitor_cancel {{0 1}separate output}
 48:       test:
 49:         suffix: 1
 50:       test:
 51:         suffix: 2
 52:         args: -options_monitor
 53:       test:
 54:         suffix: 3
 55:         args: -options_monitor -option_cmd_1 option_cmd_1_val -option_cmd_2
 56:    test:
 57:       # test effect of -skip_petscrc in ex55options file
 58:       suffix: 4
 59:       localrunfiles: ex55options .petscrc petscrc
 60:       args: -options_left 0 -options_view -options_monitor
 61:    testset:
 62:       # test -help / -help intro / -version from command line
 63:       localrunfiles: ex55options .petscrc petscrc
 64:       filter: grep -E -e "(version|help|^See)"
 65:       args: -options_left -options_view -options_monitor
 66:       test:
 67:         suffix: 5a
 68:         args: -help
 69:       test:
 70:         suffix: 5b
 71:         args: -help intro
 72:       test:
 73:         suffix: 5c
 74:         args: -version
 75:    testset:
 76:       # test -help / -help intro / -version from file
 77:       localrunfiles: ex55options rc_help rc_help_intro rc_version
 78:       filter: grep -E -e "(version|help|^See)"
 79:       args: -skip_petscrc
 80:       args: -options_left -options_view -options_monitor
 81:       test:
 82:         suffix: 6a
 83:         args: -options_file rc_help
 84:       test:
 85:         suffix: 6b
 86:         args: -options_file rc_help_intro
 87:       test:
 88:         suffix: 6c
 89:         args: -options_file rc_version

 91:    test:
 92:      localrunfiles: ex55options .petscrc petscrc
 93:      suffix: 7
 94:      args: -options_monitor -options_left 0

 96: TEST*/