Смекни!
smekni.com

Паралельноє програмирование (стр. 10 из 10)

entry Zdat1;

entry Zdat2;

private

F1:integer:=0;

F2:integer:=0;

end Box;

----------------------

protected body Box is

Procedure VvidMC(MCK: in Matrix) is

begin

MC:=MCK;

end VvidMC;

Procedure VvidMK(MKK: in Matrix) is

begin

MK:=MKK;

end VvidMK;

function Kopija1 return Matrix is

begin

return MC;

end Kopija1;

function Kopija2 return Matrix is

begin

return MK;

end Kopija2;

procedure Signal1 is

begin

F1:=F1+1;

end Signal1;

procedure Signal2 is

begin

F2:=F2+1;

end Signal2;

entry Zdat1

when F1=4 is

begin

null;

end Zdat1;

entry Zdat2

when F2=4 is

begin

null;

end Zdat2;

end Box;

----------------------

Procedure start is

task T1;

task body T1 is

MCC,MC1,MK1:Matrix;

begin

put("T1 started");

new_line;

--vvid matruci MC-----

for i in 1..N loop

for j in 1..N loop

MCC(i)(j):=1;

end loop;

end loop;

Box.VvidMC(MCC);

--Signal pro zavershennja vvody--

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

--Kopija---

MC1:=Box.Kopija1;

MK1:=Box.Kopija2;

--Obchuslennja--

for i in 1..H loop

for j in 1..N loop

for k in 1..N loop

MA(i)(j):=MA(i)(j)+MB(i)(k)*MC1(k)(j)+MO(i)(k)*MK1(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T1 Finished ");

end T1;

--------------------------------

task T2;

task body T2 is

MBB,MC2,MK2:Matrix;

begin

put(" T2 started ");

--vvid---------

for i in 1..N loop

for j in 1..N loop

MB(i)(j):=1;

end loop;

end loop;

--Signal pro zavershennja vvody---

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

--Kopija--

MC2:=Box.Kopija1;

MK2:=Box.Kopija2;

--Obchuslennja--

for i in H+1..2*H loop

for j in 1..N loop

for k in 1..N loop

MA(i)(j):=MA(i)(j)+MB(i)(k)*MC2(k)(j)+MO(i)(k)*MK2(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T2 Finished ");

end T2;

-------------------------------------------

task T3;

task body T3 is

MOO,MC3,MK3:Matrix;

begin

put(" T3 started ");

--vvid---------

for i in 1..N loop

for j in 1..N loop

MO(i)(j):=1;

end loop;

end loop;

--Signal pro zavershennja vvody---

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

MC3:=Box.Kopija1;

MK3:=Box.Kopija2;

--Obchuslennja--

for i in 2*H+1..3*H loop

for j in 1..N loop

for k in 1..N loop

MA(i)(j):=MA(i)(j)+MB(i)(k)*MC3(k)(j)+MO(i)(k)*MK3(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat2;

--vuvid--

for i in 1..N loop

for j in 1..N loop

put(MA(i)(j));

put(" ");

end loop;

new_line;

end loop;

put(" T3 Finished ");

end T3;

-------------------------------------------

task T4;

task body T4 is

MKK,MC4,MK4:Matrix;

begin

put(" T4 started ");

--vvid---------

for i in 1..N loop

for j in 1..N loop

MKK(i)(j):=1;

end loop;

end loop;

Box.VvidMK(MKK);

--Signal pro zavershennja vvody---

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

MC4:=Box.Kopija1;

MK4:=Box.Kopija2;

--Obchuslennja--

for i in 3*H+1..N loop

for j in 1..N loop

for k in 1..N loop

MA(i)(j):=MA(i)(j)+MB(i)(k)*MC4(k)(j)+MO(i)(k)*MK4(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T4 Finished ");

end T4;

begin Null;

end start;

begin

put("N=");

get(N);

t:=clock;

s1:=Seconds(t);

s2:=integer(s1);

start;

t:=clock;

s3:=Seconds(t);

s4:=integer(s3);

S5:=S4-S2;

put_line("Main");

new_line;

put("Cas=");

put(s5);

end Bakalawr3;