Hello, I am developing a R package which calls certain fortran subroutines that I wrote myself. I have been experiencing a pesky problem for a while now that my fortran subroutines result in errors in certain CRAN checks that use different Fortran compilers (e.g., flang, intel). On my own computer I do not get any errors however. I work on a MacBook Pro with M1 chip (Ventura 13.5) using gfortran (GNU Fortran, Homebrew GCC 14.1.0). Because my code is quite long (2000 lines), it is very difficult to find the errors because I cannot debug directly (I work within R). Currently, I am trying to test every single step via rhub_check().
One error that I tend to get is
free(): invalid next size (fast)
Aborted (core dumped)
I already get this error when using the following (mega) simplified subroutine. Maybe somebody can help explaining why this would cause an error on certain Fortran compilers (but not with gfortran on my Mac)? And does anybody perhaps know of an overview that explains the differences between the various Fortran compilers?
subroutine estimate_bct_ordinal(samsize0,numG,P,CDrawsStore)
implicit none
integer, parameter :: i6 = selected_int_kind(6)
integer, parameter :: r15 = selected_real_kind(15)
integer(i6), intent(in) :: P, numG, samsize0
real(r15), intent(out) :: CDrawsStore(samsize0,numG,P,P)
real(r15) :: CCan(P,P)
CCan = 1
CDrawsStore(1,1,:,:) = CCan(:,:)
end subroutine estimate_bct_ordinal
I also get this error more often. So apparently I am doing something wrong with basic declarations which I don’t understand and which are not picked by my own fortran compiler.
Moreover, my subroutine also contains many existing functions, such as from John Burkardt, for getting draws from probability distributions. Maybe somebody has experience with the compatibility of these existing functions in different Fortran compilers available on CRAN?
Any help is greatly appreciated!