Hello
I am writing a monte carlo simulation fortran 90 code. The code reads data from a file then uses these data to simulate particle transport in a meduim using random number generator. I am using fortran power station 4 (old compiler) given to me by my professor so help is limited.
The code runs fine with low number of histories. But for large number of histories it terminates without any explainations why.
The code was crashing for several reasons:
1) Flaws in the logic where wrong data is looked up --> I fixed.
2) Asking for array element that does not exist. --> fixed.
3) Rounding values. Was easily detected and fixed.
I looked for ways to trap the floating point exceptions and debug the code using FPS and sure enought it has some help. For floating point error traping and debuging It instructed me the code below:
! Exception handler routine hand_fpe
FUNCTION hand_fpe (signum, excnum)
!MS$ATTRIBUTES C :: hand_fpe
USE MSFLIB
INTEGER(2) signum, excnum
WRITE(*,*) 'In signal handler for SIG$FPE'
WRITE(*,*) 'signum = ', signum
WRITE(*,*) 'exception = ', excnum
SELECT CASE(excnum)
CASE(FPE$INVALID )
STOP ' Floating point exception: Invalid number'
CASE( FPE$DENORMAL )
STOP ' Floating point exception: Denormalized number'
CASE( FPE$ZERODIVIDE )
STOP ' Floating point exception: Zero divide'
CASE( FPE$OVERFLOW )
STOP ' Floating point exception: Overflow'
CASE( FPE$UNDERFLOW )
STOP ' Floating point exception: Underflow'
CASE( FPE$INEXACT )
STOP ' Floating point exception: Inexact precision'
CASE DEFAULT
STOP ' Floating point exception: Non-IEEE type'
END SELECT
hand_fpe = 1
END
to use this code I needed to set the error handeling handle early on the program
iret = SIGNALQQ(SIG$FPE, hand_fpe)
using this code intreduced the default error ' Floating point exception: Non-IEEE type' I can seem to know why. tracing the error lead me to the following code:
Do jj = 1, UsableNumGroups, 1
Read(FreeFile1,231) GXS(jj)
231 Format(66X, E13.5)
End Do
The only way to clear this error if I declare the GXS(jj) as double precision-Real(8). I am trying to read a set of numbers that look like " 1.96607E-03" arranged in columns. I can read them fine if I exchange the E13.5 with a13 and GXS with a character variable.
Does any one know what I am doing wrong and why???
Any help well be greatly appreciated.
Mat M Al-Tamimi
mtamimi@netzero.net
I am writing a monte carlo simulation fortran 90 code. The code reads data from a file then uses these data to simulate particle transport in a meduim using random number generator. I am using fortran power station 4 (old compiler) given to me by my professor so help is limited.
The code runs fine with low number of histories. But for large number of histories it terminates without any explainations why.
The code was crashing for several reasons:
1) Flaws in the logic where wrong data is looked up --> I fixed.
2) Asking for array element that does not exist. --> fixed.
3) Rounding values. Was easily detected and fixed.
I looked for ways to trap the floating point exceptions and debug the code using FPS and sure enought it has some help. For floating point error traping and debuging It instructed me the code below:
! Exception handler routine hand_fpe
FUNCTION hand_fpe (signum, excnum)
!MS$ATTRIBUTES C :: hand_fpe
USE MSFLIB
INTEGER(2) signum, excnum
WRITE(*,*) 'In signal handler for SIG$FPE'
WRITE(*,*) 'signum = ', signum
WRITE(*,*) 'exception = ', excnum
SELECT CASE(excnum)
CASE(FPE$INVALID )
STOP ' Floating point exception: Invalid number'
CASE( FPE$DENORMAL )
STOP ' Floating point exception: Denormalized number'
CASE( FPE$ZERODIVIDE )
STOP ' Floating point exception: Zero divide'
CASE( FPE$OVERFLOW )
STOP ' Floating point exception: Overflow'
CASE( FPE$UNDERFLOW )
STOP ' Floating point exception: Underflow'
CASE( FPE$INEXACT )
STOP ' Floating point exception: Inexact precision'
CASE DEFAULT
STOP ' Floating point exception: Non-IEEE type'
END SELECT
hand_fpe = 1
END
to use this code I needed to set the error handeling handle early on the program
iret = SIGNALQQ(SIG$FPE, hand_fpe)
using this code intreduced the default error ' Floating point exception: Non-IEEE type' I can seem to know why. tracing the error lead me to the following code:
Do jj = 1, UsableNumGroups, 1
Read(FreeFile1,231) GXS(jj)
231 Format(66X, E13.5)
End Do
The only way to clear this error if I declare the GXS(jj) as double precision-Real(8). I am trying to read a set of numbers that look like " 1.96607E-03" arranged in columns. I can read them fine if I exchange the E13.5 with a13 and GXS with a character variable.
Does any one know what I am doing wrong and why???
Any help well be greatly appreciated.
Mat M Al-Tamimi
mtamimi@netzero.net