[J3] [EXTERNAL] More on rank-agnostic capabilities

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Tue Aug 2 18:19:28 UTC 2022

Argh.  Sorry for the glaring typo.  That final blurb of code should have been:

   Z(@:shape(X), at i_y) = op(X, Y(@i_y))

I.e.,  SHAPE(Y) rather than i_y.

From: J3 <j3-bounces at mailman.j3-fortran.org> on behalf of j3 <j3 at mailman.j3-fortran.org>
Reply-To: j3 <j3 at mailman.j3-fortran.org>
Date: Tuesday, August 2, 2022 at 1:42 PM
To: j3 <j3 at mailman.j3-fortran.org>
Cc: "Clune, Thomas L. (GSFC-6101)" <thomas.l.clune at nasa.gov>
Subject: [EXTERNAL] [J3] More on rank-agnostic capabilities


A couple of side questions within the generics mailing list has led to a (small) flurry of examples that would significantly benefit from additional support for rank-agnostic beyond F202x features and template constructs.

In particular, consider trying to write the outer product of two arrays X and Y of rank M and rank N respectively.  The result, Z, is an array of rank M+N.     And we have an elemental procedure  op()  that combines individual elements from X and Y to produce elements of Z.
Our @ notation helps some here, as we can compute a single element of Z with something like:

Z(@i_x, at i_y) = op(X(@i_x), Y(@i_y))

Here i_x and i_y are 1D arrays containing the indices for X and Y respectively.

But now we need to loop over all i_x and i_y.    We can get half (square root?) way there via elemental:

Z(@:SHAPE(X), at i_y) = op(X, Y(@i_y))

Here we’ve included all indices for X for a single set of indices of Y.   The rest we need to do by looping.    We need to write a rank-agnostic nested loop where the nesting is N  (i.e., RANK(Y)).    This can be done with some ugly code that I won’t attempt to write here.     And in the end, none of the parallelism is exposed to the compiler.

I’m suggesting we consider something along the lines of:
DO CONCURRENT (i_y=@:i_y)
   Z(@:shape(X), at i_y) = op(X, Y(@i_y))

Of course this just makes the compiler do all the hard work of iterating over an N-way nested loop  (with an M-way nested loop hidden in the body of the loop to boot!).

Is something like this at all possible?

-          Tom
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.j3-fortran.org/pipermail/j3/attachments/20220802/4f93aef9/attachment-0001.htm>

More information about the J3 mailing list