-
Notifications
You must be signed in to change notification settings - Fork 424
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
Zippering of two sets can fail even when they are the same length #15824
Comments
Refactor set to use chpl__hashtable (#15772) This PR refactors the set type to make use of `chpl__hashtable` instead of an associative array. This decouples `set` from any adjustments that might need to be made to associative arrays in the future, (i.e. to support non-nilable classes) while letting `set` rely on a common implementation that is shared with `map` and associative arrays and domains. It also adds two tests for parallel zippering (prior to this, it looks like we had no code testing leader/follower iterators for set). Future work: - Sets of same length cannot be zippered if their elements are distributed poorly and their followers yield differing number of full slots: #15824 --- Testing: - [x] library/standard/Set locally on darwin when quickstart - [x] ALL on linux64 when COMM=none --- Reviewed by @mppf. Thanks!
Is this bug with respect to the way set was implemented prior to #15772, or after, or both? Historically, I thought that the leader-follower iterators for associative were hardcoded to only work if all the things being zippered involved the same domain (and printed an error otherwise). If that's not the case anymore, I'm not sure whether we removed that check incorrectly or whether I'm completely misremembering / getting mixed up with sparse or something else. |
I'm not sure if it was prior or not, @cassella suggested in an edit that this bug seemed to occur prior as well (? correct if wrong). It's easy enough to go test in a bit. |
(As for why I have no frame-of-reference, I guess the test for |
@bradcray Yes, you're right -- prior to #15772, the set leader / follower just dispatched to the associative domain So I guess it's not new that sets with different members can't be zippered. Though I guess it is new that a set can't be zippered with an associative domain whose indices are exactly the set's elements. (I haven't tested that.) |
I'm giving this a bump in priority because it came up in a user gitter issue today. |
Here's another case a user submitted on gitter that didn't work as expected: use Set;
var LocalSet= new set(int,parSafe = true);
LocalSet.add(1);
LocalSet.add(2);
LocalSet.add(3);
LocalSet.add(4);
LocalSet.add(5);
var A : [0..4] int;
writeln(A.size, LocalSet.size);
forall (a,b) in zip(A,LocalSet) {
a=b;
writeln(b);
} And a less-complete pattern: var LocalSet= new set(int,parSafe = true);
forall (a,b) in zip (A,LocalSet) {
a=b;
}
// In the above, the value of b is not the element of LocalSet
// When I change the set to an array, it works
forall (a,b) in zip (A,LocalSet.toArray()) {
a=b;
} |
Test comes from issue chapel-lang#15824 and checks zippering two sets of the same length (but different contents). Sorts the output so that it is consistent instead of potentially racy. ---- Signed-off-by: Lydia Duncan <lydia-duncan@users.noreply.github.com>
[reviewed by @benharsh, with help from @bradcray] Prior to this work, sets could only zipper with identical other sets (or basically just itself). Zippering with sets of the same length, or with arrays, would result in errors about unequal zippering lengths. Resolves #15824 <details> Adds a leader/follower pair of iterators to ChapelHashtable to support this effort. These iterators and their support functions allow the hashtable to evenly divide the elements stored in it, instead of evenly dividing the entire hashtable's storage capacity. While here, I fixed a comment that was missing a closing parenthesis. New tests: - Added a version of setZipDifferentSize.chpl that reversed the order, to show that it still worked - Added a test of zippering with an array leader that is the same length as the set - Added a test of zippering with an array follower that is the same length as the set - Added a test of zippering with an array leader that is shorter than the set - Added a test of zippering with an array follower that is shorter than the set - Added a test of zippering two sets with different contents (basically, David Longnecker's original test from #15824) - Added a test of zippering an array with the set's `toArray` result (user code, but not expected to have changed as a result of this effort) </details> Places for improvement: - It currently iterates over the whole backing hashtable for each follower. Ideally we'd iterate over it once and store the location of all filled elements somewhere helpful, but that's a problem for another time Passed a full paratest with futures
Currently the zippering of two sets can fail even if they are the same length. The number of full slots yielded by each follower currently depends on the distribution of slots in the hashtable used to implement the set. If the followers for two different hashtables yield a different number of full slots, iteration will fail with a runtime error.
Code from @cassella
Here is a potential solution proposed by @cassella in #15772:
https://github.com/chapel-lang/chapel/pull/15772/files#discussion_r434996280
The text was updated successfully, but these errors were encountered: