Open main menu

CDOT Wiki β

Changes

GPU621/The Chapel Programming Language

942 bytes added, 17:00, 1 December 2020
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;
var for i = 0; while i <= in 1..#n {
yield i1;
var i3 = i1 + i2;
i1 = i2;
i2 = i3;
i += 1;
}
}
config const n =10;
for (i,idVar) in zip(0..n, fibonacci(n)) do
writeln("#", i, " - ", idVar);
=== Task Parallelism ===
25
edits