Skip to content

[Bug]: &&= and reduce= produce different results #27059

@jabraham17

Description

@jabraham17

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions