-- Copyright (C) International Computer Science Institute, 1995. COPYRIGHT -- -- NOTICE: This code is provided "AS IS" WITHOUT ANY WARRANTY and is subject -- -- to the terms of the SATHER LIBRARY GENERAL PUBLIC LICENSE contained in -- -- the file "Doc/License" of the Sather distribution. The license is also -- -- available from ICSI, 1947 Center St., Suite 600, Berkeley CA 94704, USA. -- --------> Please email comments to "sather-bugs@icsi.berkeley.edu". <---------- -- -- matrix.sa -- implements naive matrix multiplication used to benchmark compileroptimizations. -- Version 1.0, June 1996, by Claudio Fleiner class MATRIX{T} is include S_MATRIX{T}; times(m:SAME):SAME pre cols=m.rows is r::=#SAME(rows,rows); loop x::=rows.times!; loop y::=rows.times!; loop z::=cols.times!; r[y,x]:=r[y,x]+[z,x]*m[y,z]; end; end; end; return r; end; end; class S_MATRIX{T} is include ARRAY2{T}; cols:INT is return size1; end; rows:INT is return size2; end; str:STR is r::=""; loop y::=rows.times!; r:=r+"| "; loop x::=cols.times!; r:=r+[x,y]+" "; end; r:=r+"|\n"; end; return r; end; end; class MAIN is test is a,b,c:MATRIX{FLT}; a:=#(30,50); b:=#(50,30); loop x::=30.times!; loop y::=50.times!; a[x,y]:=RND::uniform.flt; b[y,x]:=RND::uniform.flt; end; end; c:=a*b; loop y::=c.rows.times!; loop x::=c.cols.times!; #OUT+#FMT("<#####> ",(c[x,y]*100.0).int); end; #OUT+'\n'; end; end; usage is #OUT+"USAGE: matrix TEST\n" +" matrix [-p] size steps\n"; end; main(arg:ARRAY{STR}):INT is print::=false; size::=0; steps::=0; if arg.size=2 and arg[1]="TEST" then test; return 0; end; if arg.size=4 then if arg[1]="-p" then print:=true; else usage; return 1; end; size:=#INT(arg[2]); steps:=#INT(arg[3]); elsif arg.size=3 then size:=#INT(arg[1]); steps:=#INT(arg[2]); else usage; return 1; end; a,b:MATRIX{FLT}; s::=#INT(arg[1]); a:=#(s,s); b:=#(s,s); loop x::=size.times!; loop y::=size.times!; a[x,y]:=RND::uniform.flt; b[x,y]:=RND::uniform.flt; end; end; t::=#TIMES; t.start; c:MATRIX{FLT}; loop steps.times!; c:=a*b; end; d::=t.elapsed; if print then #OUT+c.str+'\n'; end; #OUT+d.str; return 0; end; end; -- vim:sw=3:nosmartindent