Fortran executable doesn't like command line input of integer

141 Views Asked by At

This code compiles and runs just fine under Intel and GNU:

program simplarray

        implicit none

        real, allocatable, dimension(:,:,:) :: a

        character(len=32) :: cmdarg
        integer :: n = 0

        call get_command_argument(1, cmdarg)
        read(cmdarg,'(i)') n

        print '("n=",i5)', n
        call flush(6)

        allocate(a(n,n,2))
        print '("a is dimensioned  ", 3i5)', shape(a)

        deallocate(a)

end program

Output:

>  ./a.out 50
n=   50
a is dimensioned     50   50    2

But Cray doesn't like it at all:

> ./a.out 10
n=   10
Illegal instruction (core dumped)

Now, here's the kicker: If I replace the command line input with just a simple setting of n, everything is fine:

        integer :: n = 10

!        call get_command_argument(1, cmdarg)
!        read(cmdarg,'(i)') n

Now I get

./a.out
n=   10
a is dimensioned     10   10    2

Update: Tried just reading from a regular text file:

integer :: n

open(unit=11, file='size.txt')
read(11,*) n
close(11)

Cray doesn't like that either. Same problem.

So, if n comes from the command line, Cray can read n. It thinks n is an integer and can even write out its value. But it can't use n in the allocate statement. (BTW, I have experimented in several ways with the format of the read statement, to no avail.) What is going on?

UPDATES in response to some comments:

First, is it possible I have discovered a bug? I moved this to another Cray platform, where it runs just fine. The Cray version on both machines is 12.0.3.

Second, my build was pretty simple, just

ftn simplarray.F90

I am building and compiling on the login nodes, which are Intel Broadwells.

0

There are 0 best solutions below