Illegal Instruction Error in Mac terminal

In summary, The speaker is having trouble with their code on a Mac OS X system. They are trying to run a Fortran code but keep receiving the message "Illegal Instruction". They have tried troubleshooting by altering the code and believe the issue may be with the arrays they have declared. They are advised to use STOP and PRINT commands to debug their code.
  • #1
skockler8
3
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
  • #2
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!
 
  • #3
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.
 

FAQ: Illegal Instruction Error in Mac terminal

What is an "Illegal Instruction Error" in Mac terminal?

An "Illegal Instruction Error" in Mac terminal is an error that occurs when the computer tries to execute a command or instruction that is not recognized or allowed by the processor. This can happen if the command is outdated, corrupted, or incompatible with the processor's architecture.

2. How do I fix an "Illegal Instruction Error" in Mac terminal?

To fix an "Illegal Instruction Error" in Mac terminal, you can try updating the command or application that is causing the error. You can also check for any available software updates for your operating system. If the error persists, it may be necessary to seek technical support or consult online forums for further troubleshooting steps.

3. Can a virus or malware cause an "Illegal Instruction Error" in Mac terminal?

Yes, a virus or malware can potentially cause an "Illegal Instruction Error" in Mac terminal. These malicious software can corrupt or alter system files and commands, leading to errors and malfunctions. It is important to have a reliable antivirus software and regularly scan your system to prevent and detect any potential threats.

4. Are there any preventative measures I can take to avoid "Illegal Instruction Errors" in Mac terminal?

To prevent "Illegal Instruction Errors" in Mac terminal, it is important to regularly update your operating system and software. You should also be cautious when downloading and installing new applications, as they may contain outdated or incompatible commands. It is also a good practice to have a backup of your important files in case of any system errors or malfunctions.

5. Can a hardware issue cause an "Illegal Instruction Error" in Mac terminal?

Yes, a hardware issue can potentially cause an "Illegal Instruction Error" in Mac terminal. This can happen if there is a malfunction or compatibility issue with the processor or other hardware components. If you suspect a hardware issue, it is best to seek professional help for diagnosis and repair.

Similar threads

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