Unformatted text preview: 51 FuncCons/operators expecCng scalars can also take... …arrays, causing each element to be passed in sin(A)
2*A ≈ forall a in A do sin(a)
forall a in A do 2*a …domains, causing each index to be passed in foo(Inner) ≈ forall i in Inner do foo(i)
MulCple arguments promote using zippered iteraCon pow(A, B) ≈ forall (a,b) in zip(A,B) do pow(a,b) 52 Indexing into arrays with domain values results in a sub array expression (an “array slice”) A[Inner] = B[Inner.translate(0,1)]; =
A B 53 Reassigning a domain logically reallocates its arrays ༉ array values are preserved for common indices D = {1..2*m, 1..2*n}; A B 54 Chapel supports several domain types… var OceanSpace = {0..#lat, 0..#long},
AirSpace = OceanSpace by (2,4),
IceSpace: sparse subdomain(OceanSpace) = genCaps(); dense strided sparse “steve” “lee” unstructured “sung” associative “david” “jacob” “albert” “brad” var Vertices: domain(opaque) = …, People: domain(string) = …;
55 All domain types can be used to declare arrays… var Ocean: [OceanSpace] real,
Air: [AirSpace] real,
IceCaps[IceSpace] real; var Weight: [Vertices] real, “steve” “lee” “sung” “david” “jacob” “albert” “brad” Age: [People] int; 56 …to iterate over index sets… forall ij in AirSpace do
Ocean[ij] += IceCaps[ij]; “steve” “lee” “sung” “david” “jacob” “albert” “brad” forall v in Vertices do
Weight[v] = numEdges[v]; forall p in People do
Age[p] += 1;
57 …to slice arrays… Ocean[AirSpace] += IceCaps[AirSpace]; “steve” “lee” “sung” “david” “jacob” “albert” “brad” …Vertices[Interior]… …People[Interns]…
58 …and to reallocate arrays AirSpace = OceanSpace by (2,2);
IceSpace += genEquator(); newnode = Vertices.create(); “steve” “lee” “sung” “david” “jacob” “albert” “brad” “vass” People += “vass”;
59 var Presidents: domain(string) =
{“George”, “John”, “Thomas”,
“James”, “Andrew”, “Martin”};
Presidents += “William”;
var Age: [Presidents] int,
Birthday: [Presidents] string;
Birthday[“George”] = “Feb 22”;
forall president in President do
if Birthday[president] == today then
Age[president] += 1; George John Thomas James Andrew Mar3n William Presidents
Feb 22 Oct 30 Apr 13 Mar 16 Mar 15 Dec 5 Feb 9 277 274 266 251 242 227 236 Birthday Age 60 Jacobi Iteration in Pictures
n A: n 1.0 Σ ÷4 repeat until max
change < ε Jacobi Iteration in Chapel
config const n = 6,
epsilon = 1.0e5;
const BigD: domain(2) = {0..n+1, 0..n+1},
D: subdomain(BigD) = {1..n, 1..n},
LastRow: subdomain(BigD) = D.exterior(1,0);
var A, Temp : [BigD] real;
A[LastRow] = 1.0;
do {
[(i,j) in D] Temp[i,j] = (A[i1,j] + A[i+1,j]
+ A[i,j1] + A[i,j+1]) / 4;
const delta = max reduce abs(A[D]  Temp[D]);
A[D] = Temp[D...
View
Full Document
 Winter '09

Click to edit the document details