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 PetscFunctionBegin; 9 x = 1.0/x; 10 CHKERRQ(PetscPrintf(PETSC_COMM_SELF,"x = %g\n",(double)x)); 11 PetscFunctionReturn(0); 12 } 13 14 int main(int argc,char **argv) 15 { 16 PetscErrorCode ierr; 17 ierr = PetscInitialize(&argc,&argv,(char*)0,help);if (ierr) return ierr; 18 CHKERRQ(PetscPrintf(PETSC_COMM_SELF,"This is a contrived example to test floating pointing\n")); 19 CHKERRQ(PetscPrintf(PETSC_COMM_SELF,"It is not a true error.\n")); 20 CHKERRQ(PetscPrintf(PETSC_COMM_SELF,"Run with -fp_trap to catch the floating point error\n")); 21 CHKERRQ(CreateError(0.0)); 22 return 0; 23 } 24 25 /* 26 27 Because this example may produce different output on different machines we filter out everything. 28 This makes the test ineffective but currently we don't have a good way to know which machines should handle 29 the floating point exceptions properly. 30 31 */ 32 /*TEST 33 34 test: 35 args: -fp_trap -error_output_stdout 36 filter: Error: true 37 38 TEST*/ 39