with Ada.Exceptions; use Ada.Exceptions;
with Ada.Text_IO; use Ada.Text_IO;
with Hold_when_Busy; use Hold_when_Busy;
package body Calculation_Nodes is
use Complex_Types;
task body Compute_Node is
begin
loop
select
accept Responsive;
or
accept Compute (Job : Jobs; Diverge_Column : out Natural_Array) do
declare
Divergent : constant Real := 2.0;
begin
Busy_Nodes.Inc;
for y in Diverge_Column'Range loop
declare
C : constant Complex := Job.Origin + (Re => 0.0, Im => Real (y) * Job.Resolution);
Z : Complex := C;
begin
Diverge_Column (y) := Divergence_Limit;
Iterate : for Iteration in 0 .. Divergence_Limit loop
if abs (Z.Re) > Divergent or else abs (Z.Im) > Divergent then
Diverge_Column (y) := Iteration;
exit Iterate;
end if;
Z := C + Z ** 2;
end loop Iterate;
end;
end loop;
Busy_Nodes.Dec;
end;
end Compute;
or
terminate;
end select;
end loop;
exception
when E : others => Put_Line (Exception_Information (E));
end Compute_Node;
end Calculation_Nodes;