3

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.

bob.sacamento
  • 6,283
  • 10
  • 56
  • 115
  • 1
    Is `get_command_argument` available in Cray? It seems to be the root of your problem. – JAlex Nov 17 '21 at 15:46
  • Yes. Compiles just fine. And, to reiterate, Cray does understand (in some sense) the value of `n` once it reads it. – bob.sacamento Nov 17 '21 at 15:48
  • If you print `cmdarg` before reading it into `n`, what do you get? – veryreverie Nov 17 '21 at 15:51
  • 1
    This seems related to this question: [Fortran code executes under Intel and GNU, fails under Cray](https://stackoverflow.com/questions/65998609/fortran-code-executes-under-intel-and-gnu-fails-under-cray) – veryreverie Nov 17 '21 at 15:52
  • 1
    `get_command_argument` was implemented in 2003 standard. What compiler standard does Cray support? Try **`GETARG`** instead? - https://stackoverflow.com/a/13844047/13813219 – JAlex Nov 17 '21 at 15:53
  • 1
    What is the `flush` subroutine and what does it do with the Cray compiler? – francescalus Nov 17 '21 at 15:53
  • Also, what version of Cray are you using? – veryreverie Nov 17 '21 at 15:54
  • 2
    Can you tell us *exactly* how you compiled this, and whether the architecture of the login nodes on your Cray is the same as the compute nodes. It's possible you've compiled for the compute nodes but are running on the login, or *vice versa* – Ian Bush Nov 17 '21 at 15:56
  • @veryreverie `cmdarg` prints out just fine before read into `n`. And you are right, the questions are related. Heck that other question is mine! So embarrassed! But you'll notice that other question never got an answer. – bob.sacamento Nov 17 '21 at 16:03
  • @francescalus flush is just a "strong hint" to the executable to write any buffered output to disk immediately. I just put it in to make sure I got output before it crashed. As it turns out, taking it out of the code makes no difference. – bob.sacamento Nov 17 '21 at 16:09
  • 2
    `ftn` is the generic fortran compiler driver on Crays - so I am afraid what you have edited into the question tells us nothing. You need to tell us what modules you loaded beforehand. You also need to tell us where you are running the code - it looks like on the front end but by default on all Crays I know `ftn` builds for the compute nodes. Are you running on the login nodes? What is the architecture of your compute nodes? – Ian Bush Nov 17 '21 at 16:17
  • 1
    It may be worth simplifying the example a little further (e.g. removing the flush, deallocate and prints, reducing the dimension of `a`), and then having a look at the assembly to see what's actually going on. – veryreverie Nov 17 '21 at 16:21
  • @IanBush Building and running on login nodes. ftn -V gives `Cray Fortran : Version 12.0.3 Wed Nov 17, 2021 10:32:01`. Relevant modules are PrgEnv-cray/6.0.9, craype/2.7.10, and craype-broadwell (and am indeed running on broadwell chips). – bob.sacamento Nov 17 '21 at 16:33
  • What happens if you run it on the compute nodes via a batch script? What happens if you compile as recommended for the login nodes and run it there? The later I think used to be done by the `crayftn` command, but it is a long, long time since I did it and you should check your local documentation. – Ian Bush Nov 17 '21 at 16:41
  • 1
    BTW it works on our AMD based machine with `Cray Fortran : Version 10.0.4` and `Cray Fortran : Version 11.0.3` – Ian Bush Nov 17 '21 at 16:44

0 Answers0