Using an array constructor in do concurrent

For a simple program

program main

  implicit none
  integer :: i, j, idx(2)

  do concurrent (j=1:5, i=1:5)
    idx = [i, j]
    ! idx(1) = i; idx(2) = j ! This works.
  end do

end program main

Compile and run the program with ifort

ifort -warn all -check all -error-limit 1 -O0 -g -assume byterecl -traceback test.f90 && ./a.out

(same flags with fpm --profile debug --compiler ifort) leaves me an error

Boundary Run-Time Check Failure for variable 'var$12'

forrtl: error (76): Abort trap signal
Image              PC                Routine            Line        Source             
a.out              00000000004048CB  Unknown               Unknown  Unknown
libc.so.6          00007F444EE1A520  Unknown               Unknown  Unknown
libc.so.6          00007F444EE6EA7C  pthread_kill          Unknown  Unknown
libc.so.6          00007F444EE1A476  raise                 Unknown  Unknown
libc.so.6          00007F444EE007F3  abort                 Unknown  Unknown
a.out              000000000047ADE7  Unknown               Unknown  Unknown
a.out              00000000004039FD  MAIN__                     11  test.f90
a.out              00000000004038A2  Unknown               Unknown  Unknown
libc.so.6          00007F444EE01D90  Unknown               Unknown  Unknown
libc.so.6          00007F444EE01E40  __libc_start_main     Unknown  Unknown
a.out              00000000004037A5  Unknown               Unknown  Unknown
Aborted

The Intel Fortran compiler I am using is

$ ifort --version
ifort (IFORT) 2021.6.0 20220226
Copyright (C) 1985-2022 Intel Corporation.  All rights reserved.

I must have done something stupid, but I am struggling to find out…

Pretty sure I reported that one. Its not you. Try this:

program main
  implicit none
  integer :: i, j, idx(2)
  do concurrent (j=1:5, i=1:5)
    write(*,*)[i,j]
  end do
end program main

Note

fpm run --compiler ifort --profile release

will run. Only manifests with specific sompiler switches

Retry without the -check all option.

You may also want to post this at the Intel Fortran forum and look for feedback from Intel support with -check option and the cases where this option runs into difficulties.

Thanks! While I am playing around I found that with --profile debug --compiler ifort what also doesn’t work is

program main

  implicit none
  integer :: i, j

  do concurrent (j=1:5, i=1:5)
    associate (idx => pair(i, j))
      write (*, *) idx
    end associate
  end do

contains

  pure function pair(i_, j_) result(ret)
    integer, intent(in) :: i_, j_
    integer :: ret(2)

    ret = [i_, j_]
  end function pair

end program main

The compiler throws me two remarks and a bunch of incorrect indices

test.f90(6): remark #7712: This variable has not been used.   [I]
  do concurrent (j=1:5, i=1:5)
------------------------^
test.f90(6): remark #7712: This variable has not been used.   [J]
  do concurrent (j=1:5, i=1:5)
-----------------^
  -858993460  -858993460
  -858993460  -858993460
  -858993460  -858993460
...

I guess I will just use --profile release and declare an array integer :: idx(2) and assign it explicitly in the loop for now.

It was the “-check stack” option that triggered it.

fpm run --compiler ifort -profile debug -flag '-check nostack'

"ifort file.f90 -check all " triggers it, and “fpm --profile debug --compiler ifort” uses “-check all”; but if you turn off just “stack” it runs.
So the simplest trigger is just “ifort -check stack file.f90”.

It seems -check all is a pretty strict flag, which is helpful for me to find bugs, either from me or the compiler. :slight_smile:

:slight_smile: That sums it up nicely. It really is a useful switch which I agree fpm should use in debug mode; but one cannot help but smile in this case when the debug flag adds the bug and then detects it.

1 Like