Chapel sum reduce: unresolved call 'sum(eltType=type int(64))'
chapel
Solution
Because the only reduce operator in the paper I was reading was `max`, I mistakenly assumed that all reduce operator were written like their description in the paper.
Chapel provides a number of standard reduction and scan operators, such as sum, product, logical and bitwise operations, and max/min (with or without location information). http://chapel.cray.com/papers/BriefOverviewChapel.pdf
Actually, the reduce operators are written like the normal operators. The correct code should be:
`var total = + reduce mostWanted;`
Reduce is an operator that combines a set of values to produce a single value. Reduce is useful because in parallel computation it is almost always necessary at some point to compare or combine results produced by different threads. The syntax for reduce is:
`var varName = reduce_operator reduce iterator_expression;`
In the code above, valid reduce_operators are: +, *, &, |, ^, &&, ||, min, max, minloc, and maxloc. Furthermore, iterator_expression can be an expression of any type that can be iterated over, provided the reduction operator can be applied to the values yielded by the iteration. For example, the bitwise-and operator can be applied to arrays of boolean or integral types to compute the bitwise-and of all the values.
To sum up all the elements of an array A of size 10, you write: var sum = + reduce A;
http://faculty.knox.edu/dbunde/teaching/chapel/#Reduce
Problem
I'm experimenting with Chapel to solve a simple problem: Find the sum of multiples of 3 or 5 below 1000 (ProjectEuler001) This is my code: ``` module Main { const topValue = 1000; var mostWanted : [0..#topValue] int; proc main() { forall (elem,i) in zip(mostWanted, 0..) { if(i % 3 == 0 || i % 5 == 0) { elem = i; } } var total = sum reduce mostWanted; writeln(total); } } ``` Then I receive the message: ``` 001.chpl:6: In function 'main': 001.chpl:14: error: unresolved call 'sum(eltType=type int(64))' ``` But if I change the word `sum` to `max`, it gives me the right answer: 999. What am I missing? I can't understand why `max` work and `sum` doesn't.