Hi Damian —

I've been able to reproduce this and reduce it to the following code:

        var A: [1..10] real;
        var z = + reduce ([i in 1..10] i * A);

The source of the problem seems to be due to the combination of using a loop expression ([i in 1..10]) and a promoted operator (i * A) in combination; using either separately seems to work. I haven't come up with a satisfactory workaround that I like (i.e., one that doesn't add additional overheads) but have opened up the following issue against this:

        https://github.com/chapel-lang/chapel/issues/16027

Some too-expensive ways to do this would be to compute the reduction a scalar at a time:

        const rows, cols = 1..10;

        var A: [rows, cols] real;
        var v: [cols] real;

        var z = [j in cols] + reduce [i in rows] (v[i] * A[i, j]);
        writeln(z);

Or to inject a helper routine that computes the `v[i] * A[i, ..]` product, storing the result into an array, returning it, and reducing that:

        const rows, cols = 1..10;

        var A: [rows, cols] real;
        var v: [cols] real;

        proc dotprod(v, Ai) {
          var res = v * Ai;
          return res;
        }

        var z = + reduce [i in rows] dotprod(v, A[i, ..]);
        writeln(z);

And as long as we're talking about expense, I'll mention that rank-change slicing is not particularly cheap in Chapel today, unfortunately.

I want to note that the pattern you're expressing here is what we'd call a partial reduction in Chapel; a long-intended but not-yet-completed feature, the motivation for it being that expressing a row- or column-wise reduction like this can be done much more efficiently when computed wholesale rather than a row or column at a time, particularly for distributed arrays. There's no good excuse for why we haven't implemented it yet other than a lack of users breathing down our neck over it.

-Brad


On Sun, 5 Jul 2020, Damian McGuckin wrote:


I have a chunk of code in which the 'reduce' breaks. If I replace the
reduce by some serial 'for' loop, it works.

I am swamped for the next 5 days at which stage I can document this properly. And it is after midnight and I need some sleep.

If somebody wants to look at it before then, here it is. Or if somebody
wants me to try the latest compile, remind how to grab it.

inline proc core(g : ?R, const v : [?vD] R, ref t : [?tD] R)
{
       const (rows, columns) = tD.dims();
       const h = v[vD.first];
       var z : [rows] R = + reduce ([i in rows] v[i] * t[i, columns]);

       z /= h;
       z /= g;

       forall i in rows do
       {
               t[i, columns] += v[i] * z;
       }
}

$CHPL_HOME/modules/internal/ChapelReduce.chpl:114: internal error: RES-FUN-ION-9910 chpl version 1.22.0
Note: This source location is a guess.

Internal errors indicate a bug in the Chapel compiler ("It's us, not you"), and we're sorry for the hassle. We would appreciate your reporting this bug -- please see https://urldefense.proofpoint.com/v2/url?u=https-3A__chapel-2Dlang.org_bugs.html&d=DwICAg&c=C5b8zRQO1miGmBeVZ2LFWg&r=QUQW-BniEL_d2a7btR4rP5TPiNmpm1pG-Qa_xXzGVKc&m=EwzOmjdx1v0IwdTBNrdG3ureD0zWsYsbGnuEsPB3w8g&s=EhpcxQoBb4Coe-4QR9HfcSXwARPjn6_UzgVTdKVOkNM&e= for instructions. In the meantime, the filename + line number above may be useful in working around the issue.

Regards - Damian

Pacific Engineering Systems International, 277-279 Broadway, Glebe NSW 2037
Ph:+61-2-8571-0847 .. Fx:+61-2-9692-9623 | unsolicited email not wanted here
Views & opinions here are mine and not those of any past or present employer


_______________________________________________
Chapel-developers mailing list
[email protected]
https://urldefense.proofpoint.com/v2/url?u=https-3A__lists.sourceforge.net_lists_listinfo_chapel-2Ddevelopers&d=DwICAg&c=C5b8zRQO1miGmBeVZ2LFWg&r=QUQW-BniEL_d2a7btR4rP5TPiNmpm1pG-Qa_xXzGVKc&m=EwzOmjdx1v0IwdTBNrdG3ureD0zWsYsbGnuEsPB3w8g&s=ABRCAxFb3me2JhoJp11LmaFWVM1eEIvrUmzi1elYyGk&e=
_______________________________________________
Chapel-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-developers

Reply via email to