In this section we only give out example programs to show the new language features.
The first example is Choleski decomposition,
Procs1 p = new Procs1(4); on(p) { Range x = new CyclicRange(size, p.dim(0)); float a[[,#]] = new float [[size, x]]; // initialize the array here; float b[[]] = new float [[size]]; // as a buffer at(j=x[0]) a[0,j]=Math.sqrt(a[0,j]); for(int k=0; k<size-1; k++) { for(int s=k+1; s<size; s++) at(j=x[k]) a[s,j]/=a[j,j]; Adlib.remap(b[[k+1:]],a[[x[k+1:], k]]); over (j=x|k+1:) for (int i=x; i<size; i++) a[i,j]-=b[i]*b[j]; at(j=x[k+1]) a[k+1,j]=Math.sqrt(a[k+1,j]); } }
Here, remap is used to broadcast one updated column to each process.
The second example is Jacobi iteration,
Procs2 p = new Procs2(2, 4); Range x = new BlockRange(100, p.dim(0), 1); Range y = new BlockRange(200, p.dim(1), 1); on(p) { float [[#,#]] a = new int [[x,y]] ; // ... some code to initialize `a' float [[#,#]] b = new int [[x,y]]; Adlib.writeHalo(a); over(i=x|:) over(j=y|:) b[i,j] = (a[i-1,j] + a[i+1,j] + a[i,j-1] + a[i,j+1]) * 0.25; over(i=x|:) over(j=y|:) a[i,j] = b[i,j]; }
In the above code, there is only one iteration, it is used to demonstrate how to define range reference with halo area, and how to use the writeHalo function.