Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Contiguous dummy arguments

176 views
Skip to first unread message

Thomas Koenig

unread,
Jan 13, 2019, 7:35:29 AM1/13/19
to
Hi,

I'm a bit confused about contiguous dummy variables - what
is supposed to happen when a non-contigous array slice
is passed to them?

Example:

module m
contains
subroutine foo(a)
real, dimension(:), contiguous, intent(inout) :: a
a = a + 1.
end subroutine foo
end module m

program main
use m
real, dimension(10) :: a
a = 1.
call foo(a(1:20:2))
print *,a
end program main

Should a compiler use copyin / copy out, or is this simply a user
error, which might nor might not be diagnosed?

Neither 8.5.7 or 15.5.2.4 appear to shed any light on this.

FortranFan

unread,
Jan 13, 2019, 10:52:52 AM1/13/19
to
On Sunday, January 13, 2019 at 7:35:29 AM UTC-5, Thomas Koenig wrote:

> ..
> I'm a bit confused about contiguous dummy variables - what
> is supposed to happen when a non-contigous array slice
> is passed to them?
> ..
> Should a compiler use copyin / copy out, or is this simply a user
> error, which might nor might not be diagnosed?
>
> Neither 8.5.7 or 15.5.2.4 appear to shed any light on this.


The standard is rather silent on this but considering the fact it says "It is processor dependent whether any other object is contiguous" at all, one would think this is entirely in the processor-dependent category and the onus being on the coder. The compiler can of course choose to be "kind" and "helpful" to coders as appropriate.

The book Modern Fortran Explained, the previous edition toward Fortran 2008 or the current edition including Fortran 2018, has in the section of CONTIGUOUS attribute a statement among other descriptions, "For an assumed-shape array, it specifies that if the corresponding actual is not contiguous, copy-in copy-out is used (to) make the dummy arguments contiguous."

Steve Lionel

unread,
Jan 13, 2019, 1:01:49 PM1/13/19
to
On 1/13/2019 10:52 AM, FortranFan wrote:
> The standard is rather silent on this but considering the fact it says "It is processor dependent whether any other object is contiguous" at all, one would think this is entirely in the processor-dependent category and the onus being on the coder. The compiler can of course choose to be "kind" and "helpful" to coders as appropriate.
>
> The book Modern Fortran Explained, the previous edition toward Fortran 2008 or the current edition including Fortran 2018, has in the section of CONTIGUOUS attribute a statement among other descriptions, "For an assumed-shape array, it specifies that if the corresponding actual is not contiguous, copy-in copy-out is used (to) make the dummy arguments contiguous."

This was the subject of interpretation F08/0061 (see
https://j3-fortran.org/doc/year/11/11-199r2.txt) that was approved for
F2008 Corrigendum 2. The change also made its way into F2018.

F2008 says: "The CONTIGUOUS attribute specifies that an assumed-shape
array can only be argument associated with a contiguous effective
argument,..."

where F2018 says: "The CONTIGUOUS attribute specifies that an
assumed-shape array is contiguous..."

The effect of this is that the processor (compiler) must ensure that the
effective argument is contiguous, whether or not the actual argument is
contiguous.

The original paper (11-199r2) suggests adding a note saying that this
may be accomplished by copy-in/copy-out, but that did not make it to the
paper that was passed. You can see the text that was passed in
https://j3-fortran.org/doc/year/17/17-020.txt

--
Steve Lionel
Retired Intel Fortran developer/support
Email: firstname at firstnamelastname dot com
Twitter: @DoctorFortran
LinkedIn: https://www.linkedin.com/in/stevelionel
Blog: http://intel.com/software/DrFortran

Thomas Koenig

unread,
Jan 13, 2019, 1:16:04 PM1/13/19
to
Steve Lionel <st...@seesignature.invalid> schrieb:
> On 1/13/2019 10:52 AM, FortranFan wrote:
>> The standard is rather silent on this but considering the fact it says "It is processor dependent whether any other object is contiguous" at all, one would think this is entirely in the processor-dependent category and the onus being on the coder. The compiler can of course choose to be "kind" and "helpful" to coders as appropriate.
>>
>> The book Modern Fortran Explained, the previous edition toward Fortran 2008 or the current edition including Fortran 2018, has in the section of CONTIGUOUS attribute a statement among other descriptions, "For an assumed-shape array, it specifies that if the corresponding actual is not contiguous, copy-in copy-out is used (to) make the dummy arguments contiguous."
>
> This was the subject of interpretation F08/0061 (see
> https://j3-fortran.org/doc/year/11/11-199r2.txt) that was approved for
> F2008 Corrigendum 2. The change also made its way into F2018.
>
> F2008 says: "The CONTIGUOUS attribute specifies that an assumed-shape
> array can only be argument associated with a contiguous effective
> argument,..."
>
> where F2018 says: "The CONTIGUOUS attribute specifies that an
> assumed-shape array is contiguous..."
>
> The effect of this is that the processor (compiler) must ensure that the
> effective argument is contiguous, whether or not the actual argument is
> contiguous.

Thanks a lot!

So, https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56789 is indeed a
wrong-code bug, and needs to be fixed.

Ron Shepard

unread,
Jan 14, 2019, 11:51:33 AM1/14/19
to
With this new interpretation of the CONTIGUOUS attribute, is it now, or
will it be in the future, possible to assign pointers in the following
manner:

real, contiguous, target :: a(:,:) ! say (3,4), 12 elements total.
real, pointer :: a1(:), a2(:,:)
...
a1(1:12) => a
...
a2(2,6) => a

Such assignments are legal now provided you first pass the contiguous
array as an actual argument to a subprogram with either the appropriate
explicit shape dummy argument declaration or as a rank 1 array.

This ability might help many legacy codes that depend on array element
sequence association move up to modern fortran.

$.02 -Ron Shepard

Steve Lionel

unread,
Jan 14, 2019, 8:52:03 PM1/14/19
to
On 1/14/2019 11:51 AM, Ron Shepard wrote:
> With this new interpretation of the CONTIGUOUS attribute, is it now, or
> will it be in the future, possible to assign pointers in the following
> manner:
>
>    real, contiguous, target :: a(:,:)   ! say (3,4), 12 elements total.
>    real, pointer :: a1(:), a2(:,:)
>    ...
>    a1(1:12) => a
>    ...
>    a2(2,6) => a
>
> Such assignments are legal now provided you first pass the contiguous
> array as an actual argument to a subprogram with either the appropriate
> explicit shape dummy argument declaration or as a rank 1 array.

As far as I can tell, this is legal in F2018.
Message has been deleted
0 new messages