I’m running an older Fortran code on MacOS Big Sur with apple silicon. There is a compiler bug that I can not identify specifically. I’d like to find it, so I can make sure the GNU developers know about it.
Here is the code: GitHub - Nicholaswogan/ImpactAtmosphere at dev
compile with cmake in the standard way:
mkdir build cd build cmake .. make
Run the test
With Gfortran on Apple silicon I get
(base) nicholas@Nicholass-MacBook-Air build % ./test PRINT1: 1.6867517999999999E+028 PRINT2: 2.5579538487363607E-013 PRINT3: 2.5579538487363607E-013
This is wrong! The value should never change. When I run with Intel Fortran or gfortran on a x86 machine I get
(base) nicholas@ build % ./test PRINT1: 1.6867517999999999E+028 PRINT2: 1.6867517999999999E+028 PRINT3: 1.6867517999999999E+028
Here are the print statements in context:
double precision, dimension(10), intent(in) :: y double precision, dimension(10), target :: N double precision, pointer :: N_ptr(:) ! more code here .... do i=1,nspecies N(i) = max(y(i),0.d0) enddo N_ptr => N NNN = N ! global NNN x(1) = dlog(tau_uv_init) ! intial condtions print*,'PRINT1: ',N_ptr(1) ! solve nonlinear system call lmdif2(fcn2,1,1,x,fvec,tol,info,iwa,wa,lwa,10000) print*,'PRINT2: ',N_ptr(1) if ((info.ne.1) .and. (info.ne.2) .and. (info.ne.3) .and. (info.ne.4)) then print*,'Non-linear solver failed in subroutine rhs ',info ierr = .true. endif tau_uv_init = dexp(x(1)) print*,'PRINT3: ',N_ptr(1)
The subroutine takes
y as input.
y is copied to
N_ptr points to
N is copied to
NNN, which a is a global module variable. This is done to “pass”
N to another function. Then the code makes a call to MINPACK (
The confusing thing is that
N is local to this function (so is
N_ptr), so it should not be affected by the call to MINPACK. But it is!!
I am not able to reproduce this behavior with a simpler code. Hoping someone knows this bug or can spot it, so we can send it to those who know how to fix these things.
This bug persists for MacOS ARM and for a ARM Ubuntu virtual machine run on MacOS ARM.
(base) nicholas@ build % gfortran --version GNU Fortran (Homebrew GCC 11.2.0_3) 11.2.0
Thanks for any ideas!