Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: zippered iteration error when storing forall expression with filter into a typed array #26385

Open
mppf opened this issue Dec 10, 2024 · 1 comment

Comments

@mppf
Copy link
Member

mppf commented Dec 10, 2024

Summary of Problem

Description:
I'm investigating filtering predicates with a forall expression because I'm looking at an algorithm that would benefit from it. I'm talking about syntax like the spec describes. See also #26384 which notes that they don't appear to result in a parallel loop.

If the LHS of such a forall expression is an array with a type, I see a "zippered iterations have non-equal lengths" error. It runs without issue if I declare the LHS variable without a type.

Is this issue currently blocking your progress?
no

Steps to Reproduce

Source Code:

use Random;

config const n = 20;
config const debug = false;

proc main() {
  var A:[0..<n] int;
  fillRandom(A, min=0, max=9, seed=1);
  if debug then writeln(A);

  // count the zeros
  writeln("counting");
  var numZeros = 0;
  forall x in A with (+ reduce numZeros) {
    if x == 0 then numZeros += 1;
  }

  // store the positions of the zeros, not parallel
  writeln("manual way");
  var ZerosS0:[0..<numZeros] int;
  var counter = 0;
  for (x,i) in zip(A,A.domain) {
    if x == 0 {
      ZerosS0[counter] = i;
      counter += 1;
    }
  }
  if debug then writeln(ZerosS0);

  writeln("forall loop with filter stored in typed");
  var ZerosP2:[0..<numZeros] int = [i in A.domain] if A[i] == 0 then i;
  if debug then writeln(ZerosP2);
  assert(ZerosP2.equals(ZerosS0));
}

Compile command:
chpl bb.chpl

Execution command:
./bb

$ ./bb
counting
manual way
forall loop with filter stored in typed
$CHPL_HOME/modules/internal/ChapelArray.chpl:2533: error: zippered iterations have non-equal lengths

Associated Future Test(s):
TODO

Configuration Information

Chapel 2.3 pre-release on an Ubuntu PC.

@mppf mppf added the type: Bug label Dec 10, 2024
@mppf mppf changed the title [Bug]: [Bug]: zippered iteration error when storing forall expression with filter into a typed array Dec 10, 2024
@bradcray
Copy link
Member

bradcray commented Dec 10, 2024

Interesting case! I'm finding that if the last element of A is forced to zero before counting and executing the loop, the error goes away. That makes me imagine that the current check for "Did one zippered iterator run out before the other?" only takes into account that iterations remain, not that in the presence of a filter, all subsequent elements might be false such that effectively we're done.

This example is also making me realize that it's probably not only the "capture in a new variable" aspect of the previous issue that thwarts parallelization, but the filtering in general (since, in our normal parallelization, it'd be difficult to anticipate where a given filtered element should align to). I'll update my previous comment.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants