Skip to content

Instantly share code, notes, and snippets.

@omar-3
Last active March 29, 2020 02:53
Show Gist options
  • Save omar-3/ba58acd0e0a67373a78ba721cd595301 to your computer and use it in GitHub Desktop.
Save omar-3/ba58acd0e0a67373a78ba721cd595301 to your computer and use it in GitHub Desktop.
implementation of python's chain() method in Chapel
use RangeChunk;
iter compress(array, trutharray) {
for (i,j) in zip(array, trutharray) {
if j {
yield i;
}
}
}
// leader
iter compress(param tag: iterKind, array, trutharray)
where tag == iterKind.leader {
var numTasks = here.maxTaskPar;
var Range = array.domain.low..array.domain.high;
coforall tid in 0..#numTasks {
var nowRange = chunk(Range, numTasks, tid);
yield (nowRange, );
}
}
// follower
iter compress(param tag: iterKind, array, trutharray, followThis)
where tag == iterKind.follower && followThis.size == 1 {
var nowRange = followThis(1);
for i in nowRange {
if trutharray[i] {
yield array[i];
}
}
}
var used = [1,2,3,4,5,6,7,8,9,10,11,12];
var truth = [1,0,0,0,1,1,0,1,0,1, 1, 0];
writeln("paraller");
forall i in compress(used, truth) {
writeln(i);
}
writeln("serial");
for i in compress(used, truth) {
writeln(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment