Skip to content

Instantly share code, notes, and snippets.

@omar-3
Last active April 2, 2020 17:16
Show Gist options
  • Save omar-3/b1c6f6cd4983d71e9cb3d13d7a9c3c2b to your computer and use it in GitHub Desktop.
Save omar-3/b1c6f6cd4983d71e9cb3d13d7a9c3c2b to your computer and use it in GitHub Desktop.
why don't you just use range? :")
use RangeChunk;
// serial
iter count(start: int, step: int, end: int) {
for i in start..end by step do
yield i;
}
// standalone
pragma "no doc"
iter count(param tag:iterKind, start: int, step: int, end: int)
where tag == iterKind.standalone {
var numTasks = here.maxTaskPar;
coforall tid in 0..#numTasks {
var nowRange = chunk(start..end, numTasks, tid);
for i in nowRange {
if (i - start) % step == 0 { // we need to do this because
yield i; // we need a reference point
} // for every chunk
}
}
}
// leader
pragma "no doc"
iter count(param tag: iterKind, start: int, step: int, end: int)
where tag == iterKind.leader {
var numTasks = here.maxTaskPar;
coforall tid in 0..#numTasks {
var nowRange = chunk(start..end, numTasks, tid).translate(-start);
yield (nowRange,);
}
}
// follower
pragma "no doc"
iter count(param tag: iterKind, start: int, step: int, end: int, followThis)
where tag == iterKind.follower && followThis.size == 1 {
var nowIter = followThis(1).translate(start);
for i in nowIter {
if (i - start) % step == 0 { // we need to do this because
yield i; // we need a reference point
} // for every chunk
}
}
// serial
for i in count(7,2,18){
writeln(i);
}
writeln("--------");
// parallel
forall i in count(7,2,18) {
writeln(i);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment