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 30 Because this example may produce different output on different machines we filter out everything. 31 This makes the test ineffective but currently we don't have a good way to know which machines should handle 32 the floating point exceptions properly. 33 34 */ 35 /*TEST 36 37 test: 38 args: -fp_trap -error_output_stdout 39 filter: Error: true 40 41 TEST*/ 42