chapel-lang / chapel

a Productive Parallel Programming Language
https://chapel-lang.org
Other
1.79k stars 421 forks source link

Unimplemented feature: Reduction over instantiated reduce class #16462

Open ronawho opened 4 years ago

ronawho commented 4 years ago

[#16518 changed this to an unimplemented feature.]

Trying to do a reduction on an instantiation of a reduction class results in a compiler segfault:

class PlusMinusReduceOp: ReduceScanOp {
  type eltType;
  var sum = true;
  var value: eltType;

  proc identity {
    return 0: eltType;
  }

  proc accumulate(elm) {
    if sum then value += elm;
           else value -= elm;

  }

  proc accumulateOntoState(ref state, elm) {
    if sum then state += elm;
           else state -= elm;
  }

  proc combine(other: borrowed PlusMinusReduceOp) {
    if sum then value += other.value;
           else value -= other.value;
  }
  proc generate() return value;

  proc clone() return new unmanaged PlusMinusReduceOp(eltType=eltType);
}

config const doSum = true;

var A = [1000, 200, 30, 4];
var plusMinus = new unmanaged PlusMinusReduceOp(eltType=int, sum=doSum);

var sum: int;

// forall reduce with instantiation works
forall elm in A with (plusMinus reduce sum) do
  sum reduce= elm;
writeln(sum);

// Op reduce with type works (but you can't specify sum=<val>)
sum = PlusMinusReduceOp reduce A;
writeln(sum);

// Op reduce with instantiation segfaults
sum = plusMinus reduce A;
writeln(sum);

delete plusMinus;

Test: test/reductions/sungeun/count.chpl

ronawho commented 4 years ago

FYI @vasslitvinov

vasslitvinov commented 4 years ago

This is an unimplemented feature. The compiler should issue an appropriate error message instead of a segfault.

vasslitvinov commented 4 years ago

16518 changed this to an unimplemented feature.

I updated OP and the title.