Skip to content

Commit

Permalink
Merge pull request #12547 from bradcray/reduce-atomics-future
Browse files Browse the repository at this point in the history
Add future requesting the ability to + reduce atomics

[trivial, not reviewed]

It seems that we should be able to simply do reductions across arrays of atomics, yet this seems not to work without providing some additional helper functions yourself... This may relate somewhat to issue #8847.
  • Loading branch information
bradcray committed Mar 9, 2019
2 parents 82970d8 + f309757 commit 5684d56
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 0 deletions.
1 change: 1 addition & 0 deletions test/reductions/reduceAtomics.bad
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
reduceAtomics.chpl:12: error: Cannot directly add atomic variables
35 changes: 35 additions & 0 deletions test/reductions/reduceAtomics.chpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
var A: [1..10] atomic int;

forall i in 1..10 do
A[i].write(i);

var AofA: [1..3] [1..10] atomic int;

forall i in 1..3 do
forall j in 1..10 do
AofA[i][j].write(i*10 + j);

var B = + reduce A;
var C = + reduce AofA;

writeln(B);
writeln(C);


// It's annoying that I have to define these in order to run a +
// reduction over an array of atomic ints, but that seems to be
// the case at present...
/*
proc +(x: atomic int, y: atomic int) {
return x.read() + y.read();
}
proc +=(ref x: int, y: atomic int) {
x += y.read();
}
proc +=(X: [?D] int, Y: [D] atomic int) {
forall i in D do
X[i] += Y[i].read();
}
*/
8 changes: 8 additions & 0 deletions test/reductions/reduceAtomics.future
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
feature request: Support reductions on arrays of atomics

It seems that we should support reductions on arrays of atomics, yet
today we don't. Here, I focus on + reductions and atomic ints, but I
think we should have a general solution for all cases. The commented
out code demonstrates overloads that will make this program work as
intended if I uncomment it. But I don't think I should have to write
it and wouldn't expect most users to figure out how to do it.
2 changes: 2 additions & 0 deletions test/reductions/reduceAtomics.good
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
55
63 66 69 72 75 78 81 84 87 90

0 comments on commit 5684d56

Please sign in to comment.