Dummy Array with Contiguous Attribute

Hello, I’m having trouble with the contiguous attribute and the is_contiguous intrinsic. Consider the following code:

module mymod
implicit none
contains

subroutine mysub(ia1,ia2)
integer, intent(in), contiguous :: ia1(:)
integer, intent(in) :: ia2(:)

write(*,*) 'in sub: ', is_contiguous(ia1), is_contiguous(ia2)

end subroutine mysub
end module mymod

program main
use mymod
implicit none

integer, allocatable :: ia1(:), ia2(:)
integer :: N

N = 10
allocate(ia1(N), ia2(N))

write(*,*) 'in main: ', is_contiguous(ia1), is_contiguous(ia2)

call mysub(ia1,ia2)

end program main

Which gives the following output with 15.5:

km-gs3% pgfortran test_contiguous.f90; ./a.out 
 in main:   T  T
 in sub:   F  F
km-gs3% pgfortran --version

pgfortran 15.5-0 64-bit target on x86-64 Linux -tp piledriver 
The Portland Group - PGI Compilers and Tools
Copyright (c) 2015, NVIDIA CORPORATION.  All rights reserved.

ia1 is apparently not contiguous, even though I’m specifically tagging it with the contiguous attribute. Is is_contiguous or contiguous not completely implemented in 15.5?

Hi Ross C,

While we are still in the process of adding F2008 features, “is_contiguous” should work here. I’ve added a problem report (TPR#21939) and sent it to engineering for further investigation.

Thanks!
Mat

Thanks. The issue came up when investigating a larger problem, which is described in detail on Stack Overflow here http://stackoverflow.com/questions/32321105/compile-time-warning-to-declare-array-as-sequence . I’m getting a compile-time warning to declare an array as sequence.

I’m not sure if links are kosher here, so let me know if I should post the issue here (on this topic or as a new topic).

Hi Ross,

Actually the warning is correct, albeit a bit difficult to decipher. When calling a routine, arguments should match if the data type is a scalar or array. The warning is indicating that you have a mismatch where you’re passing in a scalar where the routine is expecting an array.

Using “input(1)” and “output(1)” was common in F77 style programming and you wont get the warning if you use the F77 header fine “include mpif.h” instead of the F90 MPI module. With the module, the compiler has an interface and can check the arguments.

The simplest thing to do here is to pass the array itself, i.e. “input”, instead of the first element of the array, i.e. “input(1)”. Granted in both cases the same pointer is passed in so it doesn’t hurt to use “input(1)”, but it will remove the warning.

Hope this helps,
Mat

Mat,

I agree there should be a warning, but I think the supplied warning is incorrect.

So everybody is on the same page, the code in question is:

module mymod
implicit none
contains

subroutine test_sequence(input,output,icomw,N)
use MPI
integer, intent(in) :: input(:)
integer, intent(in) :: icomw, N
integer, intent(out) :: output(:)
integer :: ier

call MPI_REDUCE(input(1),output(1),N,MPI_INTEGER,MPI_MAX,0,icomw,ier)
   ! -- This is the problem line referenced in the warning

end subroutine test_sequence
end module mymod

program main
use MPI
use mymod
implicit none
integer :: icomw, id, nproc, ier, N, i
integer, allocatable :: input(:), output(:)
real :: harvest

call MPI_INIT(ier)
icomw = MPI_COMM_WORLD

N = 10
allocate(input(N), output(N))
input = 1

call test_sequence(input,output,icomw,N)

call MPI_FINALIZE(ier)
end program main

Which gives the following compile-time warning:

[chaud106@hyperion-login-1 Testing]$ mpif90 test_sequence.f90 
PGF90-W-0312-Array input should be declared SEQUENCE (test_sequence.f90: 12)
PGF90-W-0312-Array output should be declared SEQUENCE (test_sequence.f90: 12)
  0 inform,   2 warnings,   0 severes, 0 fatal for test_sequence

Certainly the correct thing to do is pass input (and output) in it’s entirety instead of using input(1).

However, the warning provided is not an array-scalar type mismatch as might be expected. Instead, the user is instructed to apply the sequence attribute to an array. As far as I know, the sequence attribute is only defined for derived data types, and specifies the storage order of a derived type’s components in memory. So I think the warning message needs to be reworded.

Hi Ross,

I did a bit more digging into this. The warning is actually for legacy High Performance Fortran (HPF) where users could use the SEQUENCE directive to force sequence association. I’ve added TPR#21947 and have asked to have the warning replaced with an error due to the rank mismatch.

Best Regards,
Mat

Great, that’s exactly what I was looking for. I appreciate the thorough investigation Mat.

TPR 21939 - UF: “is_contiguous” does not return true for example contiguous array

has been fixed in the current 15.10 release.

thanks,
dave

TPR 21947 - UF: Legacy HPF warning for dummy args needing to be declared SEQUENCE

This legacy test has been removed from the compilers in 16.1.

dave