It starts like all good stories, I have a matrix A
and I want to find the max, sometimes of the whole thing or sometimes along the rows.
var dom = {1..2, 1..5};
var m: [dom] real;
m[1,..] = [1.0, 2.0, 3.1, 4.8, 5.6];
m[2,..] = [2.0, 3.0, 4.1, 5.8, 6.6];
writeln(m);
writeln(max(m));
But there's no love here, it just poops on me:
maxy.chpl:5: error: unresolved call 'max([domain(1,int(64),false)] real(64))'
$CHPL_HOME/modules/internal/ChapelBase.chpl:614: note: candidates are: max(x, y)
Should I use reduce
or is there some easier syntax?
Using a max reduction is the easiest way to accomplish this today:
However, for the problem size shown in the example, a parallel max reduction may be overkill. If performance matters, it may be better to write your own
proc max(arr: [])
procedure that iterates over the array and finds the largest element.Chapel already supports a built-in
max()
procedure for variadic arguments, but it does not support arrays. In answering this question, I wonder if it should...