Hi,

(After I typed most of this in, I poked around some more on the
mailing lists --- and it looks like the answer to the first question
is no, based on

  http://sourceforge.net/p/chapel/mailman/message/28604686/
  http://sourceforge.net/p/chapel/mailman/message/32089491/

But I wasn't able to find an discussion of a workaround.)

Is it possible to pass an instance of a reduction class to a reduction?

A toy example is below, modeled on test code in the chapel source.
Trying to compile this, I get a "error: invalid use of 'new'" error.

If not, is there a workaround to set up the reduction class? The use
case I'm thinking is a histogram, with the parameters being varying
numbers of bins...

Thanks!
-- Nikhil

use Random;
config const seed=7323;
config const n=10;

var rnd = new RandomStream(seed);
var A : [1..n] real(64);
rnd.fillRandom(A);

// Build custom reduction
class scalSum : ReduceScanOp {
        type eltType;
        var val : eltType = 0;
        var scal : real = 1;

        proc scalSum(eltType, s1) {
                scal = s1;
        };

        proc accumulate(x : eltType) {
                val += scal*x;
        }

        proc combine(x : scalSum) {
                val += x.val;
        }

        proc generate() {
                return val;
        }
}

// Try a variant
var sum2 = new scalSum(real(64), 2);
writeln("in a more complicated way...",sum2 reduce A);

---------------------------------
Nikhil Padmanabhan
[email protected]

------------------------------------------------------------------------------
_______________________________________________
Chapel-users mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/chapel-users

Reply via email to