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