-- time_psimeq.adb with Ada.text_io; use Ada.text_io; with Ada.Calendar; use Ada.Calendar; with Ada.Command_Line; use Ada; with real_arrays; use real_arrays; with psimeq; --with Random; use Random; -- Udrnrt with Ada.Numerics.Float_random; use Ada.Numerics.Float_random; procedure Time_Psimeq is N : Positive := 200; -- number of equations NP : Positive := 8; -- number of processors Start_Time : Duration; Debug : boolean := true; S : Generator; Udrnrt : Real; procedure Check(A:Real_Matrix; X:Real_Vector; Y:Real_Vector) is Sum : Real := 0.0; Maxe : Real := 0.0; Diff : Real; Tmp : Real; begin for I in 1..N loop Tmp := 0.0; for J in 1..N loop Tmp := Tmp + A(I,J)*X(J); end loop; Tmp := Tmp - Y(I); diff := abs(Tmp); if diff>Maxe then Maxe := diff; end if; sum := sum + diff; end loop; -- while Put_Line("check N="&Integer'Image(N)& ", NP="&Integer'Image(NP)& ", maxerr:="&Real'Image(Maxe)); end check; begin Put_Line("time_psimeq.adb"); if Command_Line.Argument_Count >= 1 then N := Positive'Value(Command_Line.Argument(1)); end if; Put_Line("number of equations N="&Integer'Image(N)); if Command_Line.Argument_Count >= 2 then NP := Positive'Value(Command_Line.Argument(2)); end if; Put_Line("number of processors NP="&Integer'Image(NP)); declare X : Real_Vector(1..N); Y : Real_Vector(1..N); A : Real_Matrix(1..N,1..N); -- A * X = Y begin for I in 1..N loop for J in 1..N loop Udrnrt := Real(Random(S)); A(I,J) := Udrnrt; end loop; Udrnrt := Real(Random(S)); Y(I) := Udrnrt; end loop; if Debug then -- just see a few random numbers for I in 1..5 loop for J in 1..5 loop Put_Line("A"&Integer'Image(I)&","&Integer'Image(J)& ")="&Real'image(A(I,J))); end loop; Put_Line("Y("&Integer'Image(I)&Real'Image(Y(I))); end loop; end if; Start_Time := Calendar.Seconds(Calendar.Clock); X := psimeq(NP, A, Y); Put_Line("wall time="& Duration'Image(Calendar.Seconds(Calendar.Clock)-Start_Time)& " seconds, N="&Integer'Image(N)& ", processors="&Integer'Image(NP)); if Debug then Check(A, X, Y); end if; Put_Line("End Time_Psimeq"); end; -- declare end Time_Psimeq;