# matrix multiplication using processes and fine-grained concurrency # usage: a.out dimension resource matrix_mult() # read command line argument var n: int; getarg(1,n) # declare and initialize shared arrays var a[n,n] := ([n] ([n] 1.0)), b[n,n] := ([n] ([n] 1.0)), c[n,n] : real # compute n**2 inner products concurrently process inner(i := 1 to n, j := 1 to n) var sum := 0.0 fa k := 1 to n -> sum +:= a[i,k]*b[k,j] af c[i,j] := sum end # wait for processes to terminate, then print result, by rows final fa i := 1 to n -> fa j := 1 to n -> writes(c[i,j], " ") af write() af end end