-
Notifications
You must be signed in to change notification settings - Fork 441
Open
Labels
Description
When writing a forall with a reduce intent, it can be useful to use reduce= inside the loop to avoid having to specify the reduction operator in multiple places. However, I find that &&= and reduce= differ in behavior.
The following code behaves differently based on the value of useReduceEq
config const useReduceEq = false;
var numCalls: atomic int;
proc getBool(i) {
numCalls.add(1);
if i == 7 then return false; else return true;
}
var sum = true;
forall i in 1..1000 with (&& reduce sum) {
if useReduceEq then
sum reduce= getBool(i);
else
sum &&= getBool(i);
}
writeln(sum);
writeln("numCalls: ", numCalls.read());> ./bug --useReduceEq=false
false
numCalls: 882
> ./a.out --useReduceEq=true
false
numCalls: 1000