[J3] Passing an element of an assumed shape array to an assumed size dummy array
Pierre Hugonnet
pieru at ugo235.fr
Tue May 13 09:11:35 UTC 2025
Hi,
In solution 2) the pointer array wouldn't be contiguous (unless I didn't
get your point), thus resulting in copy-in/copy-out, which is what we
want to avoid here.
The solution 1) would work, but in practice I am calling some library
routines and have no control on their interfaces. So, a wrapper routine
should be written, with the whole array declared as explicit shape or
assumed size, then passing the appropriate array element to the library
routine. But:
- this is more code to write (not that I am lazy, but more code is also
more room for bugs)
- I faced the problem because I was converting the dummy arguments of an
existing code from explicit size to assumed-shape. Because of this
restriction, one way or another I have to revert to explicit size
(either keeping the original code as is, or in a wrapper routine), that
is to a less modern feature, and still have to rely on sequence
association at some point (the wrapper routine will call the library
routine by passing an array element anyway).
Cheers
Le 12.05.2025 13:10, Malcolm Cohen via J3 a écrit :
> There are multiple ways to do this:
>
> * Pass the whole assumed-shape array (no copying) to the assumed-size array, with the element number you want to start at as a separate argument. You're already passing leading-dimension etc info so IMO that's not a big deal.
> * Use rank-remapping pointer assignment to construct the view you want, and pass that.
>
> All these old uses of sequence association were (as admitted in that thread) hard to understand and thus maintain. I do not think that extending sequence association to additional cases is a productive direction. We want things to be more reliable, not just add more stuff that works like the old F66/77 stuff did, which was notorious for bugs in programs when passing arguments.
>
> Cheers,
>
> --
>
> ................Malcolm Cohen, NAG Oxford/Tokyo.
>
> FROM: J3 <j3-bounces at mailman.j3-fortran.org> ON BEHALF OF Pierre Hugonnet via J3
> SENT: Monday, May 12, 2025 6:41 PM
> TO: General J3 interest list <j3 at mailman.j3-fortran.org>
> CC: Pierre Hugonnet <pieru at ugo235.fr>
> SUBJECT: Re: [J3] Passing an element of an assumed shape array to an assumed size dummy array
>
> There are actually cases where passing an element and counting on sequence association is still useful, and where passing an array section instead would result in copy-in/copy-out, thus hurting the performances. I have given an example here:
>
> https://fortran-lang.discourse.group/t/array-element-actual-argument-assumed-size-dummy/9649/3?u=pieru [1]
>
> Pierre
>
> Le 11.05.2025 21:22, Van Snyder via J3 a écrit :
>
> On Sat, 2025-05-10 at 21:07 -0700, Robert Corbett via J3 wrote:
>
> There is no incompatibility with FORTRAN 66 or FORTRAN 77. The restriction on passing a scalar actual argument to an array dummy arguments applies only to assumed-shape, pointer, or polymorphic arrays (see the first dotted item in paragraph 14 of Subclause 15.5.2.5). Therefore, the only incompatibility with FORTRAN 66 or FORTRAN 77 codes is with FORTRAN 66 or FORTRAN 77 codes that include assumed-shape, pointer, or polymorphic arrays.
>
> Would it be useful to carve out an exception to use an element of a contiguous assumed-shape array (or pointer) as the start of a sequence association?
>
> Probably not, because the actual argument is necessarily in a scope using stuff from Fortran 90 onward so there's no excuse not to write x(10:).
Links:
------
[1]
https://fortran-lang.discourse.group/t/array-element-actual-argument-assumed-size-dummy/9649/3?u=pieru
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20250513/f8b1e953/attachment.htm>
More information about the J3
mailing list