-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
LLVM codegen error: example_lmdif1.f90 #12
Comments
@@ -52,7 +55,7 @@ m = size(fvec)
n = size(x)
allocate(wa(m*n + 5*n + m))
call lmdif1(fcn, size(fvec), size(x), x, fvec, tol, info, iwa, wa, size(wa))
-print 1000, enorm(size(fvec), fvec), info, x
+print 1000, enorm(size(fvec), fvec), info
1000 format(5x, 'FINAL L2 NORM OF THE RESIDUALS', d15.7 // &
5x, 'EXIT PARAMETER', 16x, i10 // &
5x, 'FINAL APPROXIMATE SOLUTION' // & OR @@ -52,7 +55,7 @@ m = size(fvec)
n = size(x)
allocate(wa(m*n + 5*n + m))
call lmdif1(fcn, size(fvec), size(x), x, fvec, tol, info, iwa, wa, size(wa))
-print 1000, enorm(size(fvec), fvec), info, x
+print 1000, enorm(size(fvec), fvec), info
+print *, x
1000 format(5x, 'FINAL L2 NORM OF THE RESIDUALS', d15.7 // &
5x, 'EXIT PARAMETER', 16x, i10 // &
5x, 'FINAL APPROXIMATE SOLUTION' // & |
Values are good till a few iterations then it begins to diverge For diff diff --git a/examples/example_lmdif1.f90 b/examples/example_lmdif1.f90
index 7da6b75..24b27b3 100644
--- a/examples/example_lmdif1.f90
+++ b/examples/example_lmdif1.f90
@@ -13,6 +13,7 @@ real(dp), intent(in) :: x(n)
real(dp), intent(out) :: fvec(m)
integer :: i
+integer :: j = 0
real(dp) :: tmp1, tmp2, tmp3, y(15)
! Suppress compiler warning:
y(1) = iflag
@@ -25,7 +26,12 @@ do i = 1, 15
tmp3 = tmp1
if (i .gt. 8) tmp3 = tmp2
fvec(i) = y(i) - (x(1) + tmp1/(x(2)*tmp2 + x(3)*tmp3))
+
+ print *, "fvec(", i, ") :", fvec(i)
+ if ( i .eq. 15 ) j = j + 1
+
end do
+print * , "j :", j
end subroutine
end module GFortran
LFortran
|
Okay so, I investigated more and found out that the following might be cause of divergence For following diff diff --git a/src/lmdif.f b/src/lmdif.f
index fcb61d1..78927e4 100644
--- a/src/lmdif.f
+++ b/src/lmdif.f
@@ -198,7 +198,11 @@ c **********
c
c epsmch is the machine precision.
c
+ print *, "factor in lmdif: ", factor
+
epsmch = dpmpar(1)
+
+ print *, "factor in lmdif here :", factor
c
info = 0
iflag = 0 and index 6f28ed2..8c43db6 100644
--- a/src/lmdif1.f
+++ b/src/lmdif1.f
@@ -124,6 +124,8 @@ c
mode = 1
nprint = 0
mp5n = m + 5*n
+ print *, 'lmdif1: calling lmdif'
+ print *, "factor: ", factor
call lmdif(fcn,m,n,x,fvec,ftol,xtol,gtol,maxfev,epsfcn,wa(1),
* mode,factor,nprint,info,nfev,wa(mp5n+1),m,iwa,
* wa(n+1),wa(2*n+1),wa(3*n+1),wa(4*n+1),wa(5*n+1))
Value of |
diff --git a/src/lmdif.f b/src/lmdif.f
index fcb61d1..f1bfc73 100644
--- a/src/lmdif.f
+++ b/src/lmdif.f
@@ -193,12 +193,18 @@ c **********
* one,par,pnorm,prered,p1,p5,p25,p75,p0001,ratio,
* sum,temp,temp1,temp2,xnorm,zero
double precision dpmpar,enorm
+ factor = 100.00
+ print *, "factor in lmdif here2: ", factor
data one,p1,p5,p25,p75,p0001,zero
* /1.0d0,1.0d-1,5.0d-1,2.5d-1,7.5d-1,1.0d-4,0.0d0/ The above given diff complies |
Variable |
The bug is mentioned at lfortran/lfortran#1118. |
Okay so with lfortran/lfortran#1119, I get the following output
3.0000000000000000
9.0635960339045418E-002 1
8.2410575864368327E-002 1.1330366265378435 2.3436946649075865
3.00000000000000000e+00
9.06359603390341356e-02 6
8.24105600064365257e-02
1.13303609732462451e+00
2.34369517380158099e+00 |
The value that diverges is With the following diff we can see cause of divergence diff --git a/examples/example_lmdif1.f90 b/examples/example_lmdif1.f90
index 7da6b75..73d595f 100644
--- a/examples/example_lmdif1.f90
+++ b/examples/example_lmdif1.f90
@@ -43,6 +43,7 @@ real(dp), allocatable :: wa(:)
! The following starting values provide a rough fit.
x = [1._dp, 1._dp, 1._dp]
+print *, dabs(3.0_8)
! Set tol to the square root of the machine precision. Unless high precision
! solutions are required, this is the recommended setting.
@@ -51,8 +52,11 @@ tol = sqrt(epsilon(1._dp))
m = size(fvec)
n = size(x)
allocate(wa(m*n + 5*n + m))
+print *, "tol: ", tol
call lmdif1(fcn, size(fvec), size(x), x, fvec, tol, info, iwa, wa, size(wa))
-print 1000, enorm(size(fvec), fvec), info, x
+print *, enorm(size(fvec), fvec)
+print *, "info: ", info
+print *, x
1000 format(5x, 'FINAL L2 NORM OF THE RESIDUALS', d15.7 // &
5x, 'EXIT PARAMETER', 16x, i10 // &
3.0000000000000000
tol: 1.4901161193847656E-008
9.0635960339045418E-002
info: 1
8.2410575864368327E-002 1.1330366265378435 2.3436946649075865
3.00000000000000000e+00
tol: 1.49166814624004135e-154
9.06359603390341356e-02
info: 6
8.24105600064365257e-02
1.13303609732462451e+00
2.34369517380158099e+00 |
On using the following diff, the output of GFortran and LFortran matches upto 1e-11 / 1e-12. diff --git a/examples/example_lmdif1.f90 b/examples/example_lmdif1.f90
index 7da6b75..8ef8a04 100644
--- a/examples/example_lmdif1.f90
+++ b/examples/example_lmdif1.f90
@@ -43,16 +43,21 @@ real(dp), allocatable :: wa(:)
! The following starting values provide a rough fit.
x = [1._dp, 1._dp, 1._dp]
+print *, dabs(3.0_8)
! Set tol to the square root of the machine precision. Unless high precision
! solutions are required, this is the recommended setting.
tol = sqrt(epsilon(1._dp))
+tol = 1.4901161193847656E-008
3.0000000000000000
tol: 1.4901161193847656E-008
9.0635960339045418E-002
info: 1
8.2410575864368327E-002 1.1330366265378435 2.3436946649075865
3.00000000000000000e+00
tol: 1.49011611938476562e-08
9.06359603390454183e-02
info: 1
8.24105758643683267e-02
1.13303662653784354e+00
2.34369466490758649e+00 |
Error comes from
@examples/example_lmdif1.f90#L55
.This is same as
comment
.Error:
On commenting line,
example_lmdif1.f90
compiles, and output is exact same as gfortran.The text was updated successfully, but these errors were encountered: