1 static char help[] = "Tests catching of floating point exceptions.\n\n";
2
3 #include <petscsys.h>
4
CreateError(PetscReal x)5 PetscErrorCode CreateError(PetscReal x)
6 {
7 PetscFunctionBegin;
8 x = 1.0 / x;
9 PetscCall(PetscPrintf(PETSC_COMM_SELF, "x = %g\n", (double)x));
10 PetscFunctionReturn(PETSC_SUCCESS);
11 }
12
main(int argc,char ** argv)13 int main(int argc, char **argv)
14 {
15 PetscFunctionBeginUser;
16 PetscCall(PetscInitialize(&argc, &argv, NULL, help));
17 PetscCall(PetscPrintf(PETSC_COMM_SELF, "This is a contrived example to test floating pointing\n"));
18 PetscCall(PetscPrintf(PETSC_COMM_SELF, "It is not a true error.\n"));
19 PetscCall(PetscPrintf(PETSC_COMM_SELF, "Run with -fp_trap to catch the floating point error\n"));
20 PetscCall(CreateError(0.0));
21 return 0;
22 }
23
24 /*
25
26 Because this example may produce different output on different machines we filter out everything.
27 This makes the test ineffective but currently we don't have a good way to know which machines should handle
28 the floating point exceptions properly.
29
30 */
31 /*TEST
32
33 test:
34 args: -fp_trap -error_output_stdout
35 filter: Error: true
36 output_file: output/empty.out
37
38 TEST*/
39