1 2 static char help[] = "Tests options database monitoring and precedence.\n\n"; 3 4 #include <petscsys.h> 5 #include <petscviewer.h> 6 7 PetscErrorCode PetscOptionsMonitorCustom(const char name[], const char value[], void *ctx) 8 { 9 PetscViewer viewer = (PetscViewer)ctx; 10 11 PetscFunctionBegin; 12 if (!value) { 13 PetscCall(PetscViewerASCIIPrintf(viewer, "* Removing option: %s\n", name)); 14 } else if (!value[0]) { 15 PetscCall(PetscViewerASCIIPrintf(viewer, "* Setting option: %s (no value)\n", name)); 16 } else { 17 PetscCall(PetscViewerASCIIPrintf(viewer, "* Setting option: %s = %s\n", name, value)); 18 } 19 PetscFunctionReturn(0); 20 } 21 22 int main(int argc, char **argv) 23 { 24 PetscViewer viewer = NULL; 25 PetscViewerFormat format; 26 27 PetscFunctionBeginUser; 28 PetscCall(PetscInitialize(&argc, &argv, "ex55options", help)); 29 PetscCall(PetscOptionsInsertString(NULL, "-option1 1 -option2 -option3 value3")); 30 PetscCall(PetscOptionsGetViewer(PETSC_COMM_WORLD, NULL, NULL, "-options_monitor_viewer", &viewer, &format, NULL)); 31 if (viewer) { 32 PetscCall(PetscViewerPushFormat(viewer, format)); 33 PetscCall(PetscOptionsMonitorSet(PetscOptionsMonitorCustom, viewer, NULL)); 34 PetscCall(PetscViewerPopFormat(viewer)); 35 PetscCall(PetscViewerDestroy(&viewer)); 36 } 37 PetscCall(PetscOptionsInsertString(NULL, "-option4 value4 -option5")); 38 PetscCall(PetscFinalize()); 39 return 0; 40 } 41 42 /*TEST 43 44 testset: 45 localrunfiles: ex55options .petscrc petscrc 46 filter: egrep -v -e "(options_left)" 47 args: -options_left 0 -options_view -options_monitor_viewer ascii 48 args: -skip_petscrc {{0 1}separate output} -options_monitor_cancel {{0 1}separate output} 49 test: 50 suffix: 1 51 test: 52 suffix: 2 53 args: -options_monitor 54 test: 55 suffix: 3 56 args: -options_monitor -option_cmd_1 option_cmd_1_val -option_cmd_2 57 test: 58 # test effect of -skip_petscrc in ex55options file 59 suffix: 4 60 localrunfiles: ex55options .petscrc petscrc 61 filter: egrep -v -e "(options_left)" 62 args: -options_left 0 -options_view -options_monitor 63 testset: 64 # test -help / -help intro / -version from command line 65 localrunfiles: ex55options .petscrc petscrc 66 filter: egrep -e "(version|help|^See)" 67 args: -options_left -options_view -options_monitor 68 test: 69 suffix: 5a 70 args: -help 71 test: 72 suffix: 5b 73 args: -help intro 74 test: 75 suffix: 5c 76 args: -version 77 testset: 78 # test -help / -help intro / -version from file 79 localrunfiles: ex55options rc_help rc_help_intro rc_version 80 filter: egrep -e "(version|help|^See)" 81 args: -skip_petscrc 82 args: -options_left -options_view -options_monitor 83 test: 84 suffix: 6a 85 args: -options_file rc_help 86 test: 87 suffix: 6b 88 args: -options_file rc_help_intro 89 test: 90 suffix: 6c 91 args: -options_file rc_version 92 93 TEST*/ 94