---------------------------> Sather 1.1 source file <-------------------------- -- 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". <---------- -- -- pheat.sa -- implements simple heat distribution in 2D. Used to benchmark Sather and -- pSather. class HEAT is include S_HEAT{ARRAY2{FLT}}; heat_step is t::=t1; t1:=t2; t2:=t; parloop p::=cluster_size.times!; do loop x::=((cols*p)/cluster_size).upto!(cols*(p+1)/cluster_size-1); loop y::=rows!; [x,y]:=heat_of(t2,x,y); end; end; end; end; end; class S_HEAT{T} is attr t1,t2:T; create(s1:INT,s2:INT):SAME is r::=new; r.t1:=#(s1,s2); r.t2:=#(s1,s2); return r; end; heat_of(t:T,x,y:INT):FLT is h::=t[x,y]; d::=1; if x>0 then d:=d+1;h:=h+t[x-1,y]; if y>0 then d:=d+1;h:=h+t[x-1,y-1]; end; if y0 then d:=d+1;h:=h+t[x+1,y-1]; end; if y0 then d:=d+1;h:=h+t[x,y-1]; end; if y15 then i:=15; end; #OUT+st[i]; end; #OUT+"\n"; end; end; end; class MAIN is test is h::=#HEAT(32,32); h[0,0]:=1000.0; h[h.cols-1,0]:=2000.0; h[0,h.rows-1]:=3000.0; h[h.cols-1,h.rows-1]:=4000.0; loop 100.times!; h.heat_step; end; loop y::=h.rows!; loop x::=h.cols!; #OUT+#FMT("<####> ",(100.0*h[x,y]).int); end; #OUT+"\n"; end; end; usage is #OUT+"USAGE: heat TEST\n" +" heat [-p] size steps\n"; end; main(argv:ARRAY{STR}):INT is print::=false; size::=0; steps::=0; if argv.size=2 and argv[1]="TEST" then test; return 0; end; if argv.size=4 then if argv[1]="-p" then print:=true; else usage; return 1; end; size:=#INT(argv[2]); steps:=#INT(argv[3]); elsif argv.size=3 then size:=#INT(argv[1]); steps:=#INT(argv[2]); else usage; return 1; end; h::=#HEAT(size,size); h[0,0]:=(size*50).flt; h[size-1,0]:=h[0,0]; h[0,size-1]:=h[0,0]; h[size-1,size-1]:=h[0,0]; t::=#TIMES; t.start; loop steps.times!; h.heat_step; end; d::=t.elapsed; if print then h.print; end; #OUT+d.str; return 0; end; end; -- vim:sw=3:nosmartindent