25
edits
Changes
→Iterators
Records are similar to classes. '''Records''' doesn't support inheritance and virtual dispatch but it supports copy constructor and copy assignment. And record variables refer to a distinct memory.
=== Iterators ===
We declared the '''yield''' statement inside the iterator bodies, it returns a value and suspends the execution.
iter fibonacci(n: int): int { var i1 = 0, i2 = 1; for i in 1..#n { yield i1; var i3 = i1 + i2; i1 = i2; i2 = i3; } } config const n =10; for idVar in fibonacci(n) do writeln(" - ", idVar); ==== Parallel Iterators ==== There are two types of parallel iterator in Chapel: '''Leader-follower iterators:''' implement zippered forall loops. '''Standalone parallel iterators:''' implement non-zippered forall loops. ===== Leader-follower iterator ===== forall (a, b, c) in zip(A, B, C) do //in here, A is the leader; and A, B, C is followers '''leader iterator''' will create the parallel tasks for its forall loop and set iterations to each parallel task. '''follower iterator''' will take input and iterate over it; create opposite results in order. An example code: iter fibonacci(n: int): integer int {
var i1 = 0, i2 = 1;
yield i1;
var i3 = i1 + i2;
i1 = i2;
i2 = i3;
}
}
config const n =10;
for (i,idVar) in zip(0..n, fibonacci(n)) do
writeln("#", i, " - ", idVar);
=== Task Parallelism ===