Troubleshooting Fortran Errors: How to Fix Code Compilation Issues

  • Context: Fortran 
  • Thread starter Thread starter alcantara_20
  • Start date Start date
  • Tags Tags
    Error Fortran
Click For Summary

Discussion Overview

The discussion revolves around troubleshooting compilation errors in Fortran code, specifically focusing on an "integer divide by zero" error message encountered during program execution. Participants explore potential causes and solutions related to code structure, error handling, and compiler settings.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports an "integer divide by zero" error but is unsure how to locate the source of the problem due to a lack of specific line information in the error message.
  • Another participant suggests checking for division operations in the code as a potential cause of the error.
  • Some participants recommend using compiler flags to enhance error reporting and provide more detailed information during runtime.
  • A participant proposes implementing guard statements to prevent division by zero, providing examples for both integer and floating-point divisions.
  • One participant expresses confusion about their code structure and seeks clarification on how to handle conditions for division by zero.
  • Another participant questions the correctness of the subroutine call to dgetrs and suggests that incorrect parameters may be contributing to the error.
  • Several participants share their attempts to follow suggestions and troubleshoot the issue, indicating ongoing difficulties in resolving the error.
  • Tracing statements are recommended by a participant as a method to help localize the source of the error.

Areas of Agreement / Disagreement

Participants do not reach a consensus on the cause of the error, as multiple potential issues are discussed, including code structure, parameter values, and compiler settings. The discussion remains unresolved, with participants continuing to seek solutions.

Contextual Notes

Limitations include incomplete code snippets shared by participants, which may hinder the ability to diagnose the issue fully. There are also unresolved questions regarding variable declarations and the overall structure of the main program.

alcantara_20
Messages
9
Reaction score
0
Dear all,

I'm write code in Fortran language when compile my program I got error message :

forrtl: severe (71): integer divide by zero
Image PC Routine Line Source
f0511 00000000007536A5 Unknown Unknown Unknown
f0511 00000000007538C8 Unknown Unknown Unknown
f0511 000000000040347C Unknown Unknown Unknown
libc.so.6 000000338101ECDD Unknown Unknown Unknown
f0511 0000000000403379 Unknown Unknown Unknown
make: *** [all] Error 71

How I can fix this problem if the error message didn't give the line that indicates error? I don't have idea to solve this.
 
Technology news on Phys.org
alcantara_20 said:
Dear all,

I'm write code in Fortran language when compile my program I got error message :

forrtl: severe (71): integer divide by zero
Image PC Routine Line Source
f0511 00000000007536A5 Unknown Unknown Unknown
f0511 00000000007538C8 Unknown Unknown Unknown
f0511 000000000040347C Unknown Unknown Unknown
libc.so.6 000000338101ECDD Unknown Unknown Unknown
f0511 0000000000403379 Unknown Unknown Unknown
make: *** [all] Error 71

How I can fix this problem if the error message didn't give the line that indicates error? I don't have idea to solve this.

Are you doing any division in your code? That's where I would look.

If you still can't find the problem, post your code and we'll take a look.
 
read the user's manual for the compiler, look for flags to enhance runtime error reporting, like debug, or not removing the symbol table or divide-by-zero...I know that g95, for example, if you have an environment variable declared appropriately, it will tell you about it, etc.
 
Yes I doing any division in my code. I tried to put flags in my code the error messages still same.
 
alcantara_20 said:
Yes I doing any division in my code.
Wherever you are doing division, put in a guard statement to prevent division by zero.
For example, if I'm going to divide by radius (an integer value), I can do this:
Code:
IF radius .neq. 0 THEN
   result = numerator / radius
ELSE
   WRITE *, "Error - Division by zero."
ENDIF

If the denominator is a floating point value, the above won't work, but something like the following will work.
Code:
IF ABS(radius) .leq. 1E-07 THEN
   result = numerator / radius
ELSE
   WRITE *, "Error - Division by zero."
ENDIF

If radius is a number between -.0000001 and +.0000001, the division is not performed. I picked the value to test against somewhat arbitrarily - you can use a smaller value or one that is larger.
alcantara_20 said:
I tried to put flags in my code the error messages still same.
 
Thank Mark44 I will try your solution. :smile:
 
I forgot that I'm not use division. When I try put for if else end if, I still get error. This is my line code:

Factorize A
Factorize A
call cpu_time(start)
CALL dgetrf(n,n,a,lda,ipiv,info)

IF (info==0) THEN
! Compute solution
CALL dgetrs(trans,n,nrhs,a,lda,ipiv,b,ldb,info)
call cpu_time(finish)
! Print solution
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
DO I = 1,N
!print 1000, b(i,nrhs)
END DO
print*,B(5,1)
!print*,B
ELSE
WRITE (nout,*) 'The factor U is singular'
END IF
print *,'time OV=',finish - start

I already use else if for another purpose how I put another branch for condition integer divide by zero ?
 
Your code isn't complete enough to determine what's going wrong, but I would bet that you are not calling dgetrs subroutine correctly or that your Fortran installation is not set up correctly so that the compiler is not able to find the lapack library code.

Here's a link to some documentation for dgetrs - http://www.nag.co.uk/numeric/fl/manual/pdf/F07/f07aef.pdf.
 
I still figure out the error base from your suggestion Mark44
 
  • #10
alcantara_20 said:
I still figure out the error base from your suggestion Mark44
It is apparent to me that English is not your first language. What you said here means that you figured out the problem, but I suspect that is not the case.
 
  • #11
Yes I still figured out the problem. Because I tried check again and I still got the same error massage.
 
  • #12
alcantara_20 said:
Yes I still figured out the problem.
When you "figure out" a problem, you are finding a solution for it.
alcantara_20 said:
Because I tried check again and I still got the same error massage.
So you are still experiencing the problem. You did NOT figure it out.

Did you try the suggestion I made in post #8?
 
  • #13
I tried your suggestion moreover I found the new documentation for f07aef but I still can't find the solution.
 
  • #14
I believe that the error you are seeing is due to incorrect parameters in your call to dgetrs.

Code:
CALL dgetrs(trans,n,nrhs,a,lda,ipiv,b,ldb,info)
What are the values of the parameters you are using when you call dgetrs?
Section 5 Parameters in the documentation in the link I sent explains each parameter.
 
Last edited:
  • #15
I still can't find the solution. I post my code and tried your solution but still can't find the solution of my problem.
This the main program of my code :

READ (nin,*)
READ (nin,*) n, nrhs

lda = n
ldb = n
ALLOCATE (a(lda,n),b(ldb,nrhs),ipiv(n))
ALLOCATE (a1(lda,n),b1(ldb,nrhs))
! Read A and B from data file

! READ (nin,*) (a1(i,1:n),i=1,n)
! READ (nin,*) (b1(i,1:nrhs),i=1,n)
do i = 1,n
do j = 1,n
read (nin,*),a1(i,j)
end do
end do

do i = 1,n
read (nin,*),b1(i,nrhs)
end do

DO I = 1,N
DO J = 1,N
a(I,J) = (a1(I,J),1.1d0)
END DO
END DO
DO I = 1,N
DO J = 1, NRHS
b(I,J) = (b1(I,J),1.0d0)
END DO
END DO
! Factorize A
call cpu_time(start)
CALL dgetrf(n,n,a,lda,ipiv,info)

IF (info==0) THEN
! Compute solution

CALL dgetrs(trans,n,nrhs,a,lda,ipiv,b,ldb,info)
call cpu_time(finish)
! Print solution
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
!CALL x04caf('General',' ',n,nrhs,b,ldb,'Solution(s)',ifail)
DO I = 1,N
!print 1000, b(i,nrhs)
END DO
print*,B(5,1)
!print*,B
ELSE
WRITE (nout,*) 'The factor U is singular'
END IF
print *,'time OV=',finish - start
DEALLOCATE (A,B,IPIV,A1,B1)

1000 FORMAT (F10.4)

SUBROUTINE GET_INPUT(N,NRHS,A,B)
INTEGER ::N, NRHS, I, J, K
DOUBLE PRECISION :: A(N,N), B(N,NRHS)
k = n*n+1
DO I = 1,N
B(I,NRHS) = 1.D0
DO J = 1,N
A(I,J) = ran(k)*(5-(-5)) -5
END DO
END DO
END SUBROUTINE
 
  • #16
Add some tracing statements like

Code:
print *,'I am here!'

or

Code:
print *,'Data read properly'

It will help you localize the line that generates error.
 
  • #17
Your suggestion really help me. Thank you very much
 
  • #18
alcantara_20 said:
I still can't find the solution. I post my code and tried your solution but still can't find the solution of my problem.
This the main program of my code :
You haven't shown us the complete main program, especially where the variables are declared.
alcantara_20 said:
READ (nin,*)
READ (nin,*) n, nrhs

lda = n
ldb = n
ALLOCATE (a(lda,n),b(ldb,nrhs),ipiv(n))
ALLOCATE (a1(lda,n),b1(ldb,nrhs))
! Read A and B from data file

! READ (nin,*) (a1(i,1:n),i=1,n)
! READ (nin,*) (b1(i,1:nrhs),i=1,n)
do i = 1,n
do j = 1,n
read (nin,*),a1(i,j)
end do
end do

do i = 1,n
read (nin,*),b1(i,nrhs)
end do

DO I = 1,N
DO J = 1,N
a(I,J) = (a1(I,J),1.1d0)
END DO
END DO
What are you doing in the loop above? I'm pretty sure it's not allowed.
alcantara_20 said:
DO I = 1,N
DO J = 1, NRHS
b(I,J) = (b1(I,J),1.0d0)
END DO
END DO
Same question as above.
alcantara_20 said:
! Factorize A
call cpu_time(start)
CALL dgetrf(n,n,a,lda,ipiv,info)

IF (info==0) THEN
! Compute solution

CALL dgetrs(trans,n,nrhs,a,lda,ipiv,b,ldb,info)
I don't see a variable named trans anywhere in your code. That variable needs to have a value before you call this function.
alcantara_20 said:
call cpu_time(finish)
! Print solution
! ifail: behaviour on error exit
! =0 for hard exit, =1 for quiet-soft, =-1 for noisy-soft
ifail = 0
!CALL x04caf('General',' ',n,nrhs,b,ldb,'Solution(s)',ifail)
DO I = 1,N
!print 1000, b(i,nrhs)
END DO
print*,B(5,1)
!print*,B
ELSE
WRITE (nout,*) 'The factor U is singular'
END IF
print *,'time OV=',finish - start
DEALLOCATE (A,B,IPIV,A1,B1)

1000 FORMAT (F10.4)
What's the purpose of this subroutine? You don't call it anywhere in the code above.
alcantara_20 said:
SUBROUTINE GET_INPUT(N,NRHS,A,B)
INTEGER ::N, NRHS, I, J, K
DOUBLE PRECISION :: A(N,N), B(N,NRHS)
k = n*n+1
DO I = 1,N
B(I,NRHS) = 1.D0
DO J = 1,N
A(I,J) = ran(k)*(5-(-5)) -5
END DO
END DO
END SUBROUTINE
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
  • · Replies 3 ·
Replies
3
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 7 ·
Replies
7
Views
4K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 17 ·
Replies
17
Views
5K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 2 ·
Replies
2
Views
9K
  • · Replies 3 ·
Replies
3
Views
5K
  • · Replies 3 ·
Replies
3
Views
5K