19.11.2014 Views

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

The Fortress Language Specification - CiteSeerX

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

several new variables. This syntax serves to break the right-hand side into pieces and bind the pieces to the variables.<br />

Matrix unpastings are concise, eliminate several opportunities for fencepost errors, guarantee unaliased parts, and<br />

avoid overspecification of how the matrix should be taken apart.<br />

<strong>The</strong> motivating example for matrix unpasting is cache-oblivious matrix multiplication. <strong>The</strong> general plan in a cache<br />

oblivious algorithm is to break the input apart on its largest dimension, and recursively attack the resulting smaller and<br />

more compact problems.<br />

mmnat m,nat n,nat p(left : R m×n ,right : R n×p ,result : R m×p ) :() = do<br />

case largest of<br />

1 ⇒ result 0,0 += (left 0,0 right 0,0 )<br />

m ⇒ [lefttop<br />

leftbottom ] = left<br />

[resulttop<br />

resultbottom ] = result<br />

t 1 = spawn do mm(lefttop,right,resulttop) end<br />

mm(leftbottom,right,resultbottom)<br />

t 1 .wait()<br />

p ⇒ [rightleft rightright ] = right<br />

[resultleft resultright ] = result<br />

t 1 = spawn do mm(left,rightleft,resultleft) end<br />

mm(left,rightright,resultright)<br />

t 1 .wait()<br />

n ⇒ [leftleft leftright ] = left<br />

[righttop<br />

rightbottom ] = right<br />

mm(leftleft,righttop,result)<br />

mm(leftright,rightbottom,result)<br />

end<br />

end<br />

In unpasting, the element syntax is slightly enhanced both to permit some specification of the split location and to<br />

receive information about the split that was performed. For example, perhaps only the upper left square of a matrix is<br />

interesting. <strong>The</strong> programmer can annotate bounds to the square unpasted element:<br />

foonat m,nat n(A : R m×n ) : () = do<br />

if m < n then<br />

[ square m×m rest ] = A<br />

. . .<br />

elif m > n then<br />

[ square n×n<br />

rest ] = A<br />

. . .<br />

else (∗ A already square ∗)<br />

square = A<br />

. . .<br />

end<br />

end<br />

<strong>The</strong> types of the elements of the newly declared matrix variables on the left-hand side of an unpasting are inferred<br />

(trivially) to be the type of the elements on the right-hand side.<br />

If an unpasting into explicitly sized pieces does not exactly cover the right-hand-side matrix, an UnpastingException<br />

is thrown.<br />

59

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!