1 2 static char help[] = "Demonstrates PETSc error handlers.\n"; 3 4 #include <petscsys.h> 5 6 int CreateError(int n) { 7 PetscCheck(n, PETSC_COMM_SELF, PETSC_ERR_USER, "Error Created"); 8 PetscCall(CreateError(n - 1)); 9 return 0; 10 } 11 12 int main(int argc, char **argv) { 13 PetscFunctionBeginUser; 14 PetscCall(PetscInitialize(&argc, &argv, (char *)0, help)); 15 PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "Demonstrates PETSc Error Handlers\n")); 16 PetscCall(PetscFPrintf(PETSC_COMM_WORLD, stdout, "The error is a contrived error to test error handling\n")); 17 PetscCall(PetscSynchronizedFlush(PETSC_COMM_WORLD, PETSC_STDOUT)); 18 PetscCall(CreateError(5)); 19 PetscCall(PetscFinalize()); 20 return 0; 21 } 22 23 /*TEST 24 25 # Testing errors so only look for errors 26 test: 27 args: -error_output_stdout 28 filter: egrep "(PETSC ERROR)" | egrep "(Error Created|CreateError\(\)|main\(\))" | cut -f1,2,3,4,5,6 -d " " 29 TODO: Does not always produce exactly expected output on all systems for all runs 30 31 TEST*/ 32