Illegal Instruction Error in Mac terminal

AI Thread Summary
The discussion centers on troubleshooting a Fortran program running on Mac OS X 10.7 that returns an "Illegal Instruction" error when executed. The code aims to compute approximations of the exponential function, pi, and the Euler constant, but issues arise during execution. Key points include potential problems with array bounds, specifically the DF array, which is declared with 102 elements but is accessed beyond its limit in a loop that runs from 1 to 201. Additionally, there are concerns about mixing integer and real types in calculations, which could lead to unexpected results. Debugging strategies suggested include using STOP commands and simplifying the code to isolate the source of the error.
skockler8
Messages
3
Reaction score
0
I am running a mac os x 10.7 system I am writing a fortran code which compiles, however, whenever I run my code (./file.out) all I receive in return is the message "Illegal Instruction". I have tried messing with my code and I continue to receive this message. Any help with this would be great. My code is as follows:

!
PROGRAM HomeWorkOne_ProbOne

IMPLICIT NONE

! Computes an estimation of the exponential function, pi, and the Euler Constant

! Declare all variables
INTEGER(8) :: n
INTEGER, PARAMETER :: max = 100
REAL(8), DIMENSION (max + 2) :: f, DF, p, pi, gamma, e

! Set initial values of variables to approximate
pi = 0.0
gamma = 0.0
e = 0.0

! Calculation of n factorial set equal to f(n)
DO n=1, max
f(1) = 1.0
f(n+1) = f(n)*n
END DO

! Calculation of (2n+1)! set equal to DF(n)
DO n=1, (2*max+1)
DF(1) = 1.0
DF(2) = 1.0
DF(n+2) = DF(n+1)*(2*n+1)
END DO

! Calculation of F/DF set equal to p(n)
DO n=0, max
p(n+1) = f(n+1)/DF(n+1)
END DO

! Loop that will calculate approximation values
DO n=1, max
e(n+2) = (1.0/f(n+1)) + e(n+1)
gamma(n+2) = gamma(n+1) + ((1.0/n)-LOG((n+1.0)/n))
pi(n+2) = p(n+1) + pi(n+1)
END DO

PRINT *, "Approximate values of:"
PRINT *, "e =", e(32)
PRINT *, "gamma =", gamma(32)
PRINT *, "Pi =", pi(32)
PRINT *, "Actual values of :"
PRINT *, "e =", 2.71828182
PRINT *, "gamma =", 0.57721566
PRINT *, "Pi =", 3.14159265

END PROGRAM HomeWorkOne_ProbOne
 
Technology news on Phys.org
My guesses would either be that you're going beyond the allocated range of your arrays (DF seems a possible candidate) or that you're dividing by zero or taking the log of a non-positive number.

Also, you're still mixing integers and reals (eg, at "1.0/n", etc) which might cause values to be other than you expect.

Try putting STOP commands in your program or temporarily deleting parts of your program until you find which part is causing the error.

When debugging, breaking the code down into small bits and using STOP and PRINT commands is a really useful way to check it - it is the only way, really.

Good luck!
 
I agree that there's a problem with DF. You have declared it to be an array with 102 elements, but your loop is attempting to store values in 201 elements, since n in that particular loop ranges from 1 to 201.
 
Thread 'Star maps using Blender'
Blender just recently dropped a new version, 4.5(with 5.0 on the horizon), and within it was a new feature for which I immediately thought of a use for. The new feature was a .csv importer for Geometry nodes. Geometry nodes are a method of modelling that uses a node tree to create 3D models which offers more flexibility than straight modeling does. The .csv importer node allows you to bring in a .csv file and use the data in it to control aspects of your model. So for example, if you...
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
4
Views
2K
Replies
4
Views
2K
Replies
15
Views
2K
Replies
6
Views
3K
Replies
3
Views
2K
Replies
9
Views
3K
Replies
3
Views
2K
Replies
16
Views
2K
Back
Top