I’m trying to compile an f90 code, which defines the dimensions of arrays using MAXVAL. I cannot copy the code itself as it is copyrighted. I tried to replicate the problematic part of the original code as shown below, however the replicated code works. I know the problem is with MAXVAL since if I replace the MAXVAL function with its integer value, the original code works fine. The original code works fine with Intel Fortran Compiler, but not with HPC. When I run the executable with valgrind, I get these error at the line where the replicated TRY subroutine is called in the original code:
==15593== Use of uninitialised value of size 8
==15593== Invalid read of size 4
==15593== Process terminating with default action of signal 11 (SIGSEGV)
==15593== Access not within mapped region at address 0x26FB8038
PROGRAM MAIN IMPLICIT NONE INTEGER A(3) INTEGER II(0:0) INTEGER, ALLOCATABLE :: B(:,:) A=(/0,0,2/) II(1)=1 ALLOCATE(B(1,0:MAXVAL(A))) WRITE(*,*) SIZE(B) WRITE(*,*) B CALL TRY(B,A) END SUBROUTINE TRY(B,A) IMPLICIT NONE INTEGER A(3) INTEGER B(1,0:MAXVAL(A)) INTEGER, ALLOCATABLE :: C(:,:) B(1,0)=5 ALLOCATE(C(1,0:MAXVAL(B))) WRITE(*,*) B END
I’m sure I am missing something that there must be a difference between my replicated code and the original code, but can anyone guess what might be the problem?
Thanks in advance.