Created
March 29, 2020 04:16
-
-
Save omar-3/25d130e9a87150fd56440235274b8d44 to your computer and use it in GitHub Desktop.
this is an implementation for python's starmap method in Chapel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use RangeChunk; | |
use Time; | |
// serial | |
iter starmap(array, function) { | |
var iterable = array; // I know that I don't need to copy "array" to new variable "iterable" | |
for i in iterable { | |
yield function((...i)); | |
} | |
} | |
// leader | |
iter starmap(param tag: iterKind, array, function) | |
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 starmap(param tag: iterKind, array, function, followThis) | |
where tag == iterKind.follower && followThis.size == 1 { | |
var nowRange = followThis(1); | |
for i in nowRange { | |
yield function((...array[i])); | |
} | |
} | |
var used_1 = [(1,2), (3,2), (2,5), (10,2), (9,1)]; | |
proc funcUsed_1(a: int, b: int) : int { | |
return a**b; | |
} | |
writeln("serial"); | |
for i in starmap(used_1, funcUsed_1) { | |
writeln(i); | |
} | |
writeln("parallel") | |
forall i in starmap(used_1, funcUsed_1) { | |
writeln(i); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment