[J3] More on rank-agnostic capabilities

Clune, Thomas L. (GSFC-6101) thomas.l.clune at nasa.gov
Tue Aug 2 17:42:14 UTC 2022


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/15d155ab/attachment.htm>

More information about the J3 mailing list