Смекни!
smekni.com

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

4. Языки программирования: Ада, Паскаль, Си.Сравнение и оцен­ка/ Под ред.Н. Джехани - М.: Радио и связь, 1989. - 386 с.

5.Русанова О.В. Программное обеспечение компьютерны сис­тем. Особенности программирования и компиляции. - К.: Корійчук, 2003.-94 с

6. Троелсон Є. С# и платформа-NET. Библиотека программиста -СПб.: Питер, 2004. - 796 с.

7. Эндрюс Г. Основы многопоточного, параллельного и распреде -ленного програмирования.: Пер. с англ. - М.: Изд. Дом «Виль -ямс», 2003.-512 с.

8. Элементы параллельного программирования / В.А.Вальковский, В.Е.Котов, А.Г.Марчук/ Под ред. В. Е. Котова- М.: Радио и связь, 1983.-240 с.

9.Бар Р. Язык Ада в проектировании систем. - М.: Мир, 1988.-ЗІ 0 с

10. Богачев К.Ю. Основы параллельного программирования.- М.: БИНОМ. Лаб. знаний, 2003. - 342 с .

11. М. Кузьминский, «64-разрядные микропроцессоры AMD». Открытые системы, № 4, 2002.

12.Паралельне програмування для многопроцессорних обчислювальних систем автори: Немнюгин С., Стесик О.

ДОДАТКИ


Додаток А

Блок-схема роботи програми

Рис. A.1 Захищений модуль операції

\

Додаток Б

Лістинг програми


-- Zaxushenuj modylj----

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

with Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

use Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

Procedure Bakalawr1 is

P:integer:=4;

N:integer:=5000;

H:integer:=N/P;

t:time;

s1,s3:day_Duration;

s2,s4,s5:integer;

-----Tupu-----

type Vector is array (1..N) of integer;

type Matrix is array (1..N) of Vector;

-----Zminni------

MA,MC,MB:Matrix;

----Zaxuchenuj m-----

Protected Box is

procedure VvidMC(MCK: in Matrix);

function Kopija1 return Matrix;

procedure Signal1;

procedure Signal2;

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;

function Kopija1 return Matrix is

begin

return MC;

end Kopija1;

procedure Signal1 is

begin

F1:=F1+1;

end Signal1;

procedure Signal2 is

begin

F2:=F2+1;

end Signal2;

entry Zdat1

when F1=2 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: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;

--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)+MC1(k)(j);--MB(i)(k);--*MC1(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(" T1 Finished ");

end T1;

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

task T2;

task body T2 is

MBB,MC2: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;

---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);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T2 Finished ");

end T2;

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

task T3;

task body T3 is

MC3:Matrix;

begin

put(" T3 started ");

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

MC3:=Box.Kopija1;

---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);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T3 Finished ");

end T3;

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

task T4;

task body T4 is

MC4:Matrix;

begin

put(" T4 started ");

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

MC4:=Box.Kopija1;

---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);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

put(" T4 Finished ");

end T4;

begin Null;

end start;

begin

put_line("Main");

put("N=");

get(N);

t:=clock;

s1:=Seconds(t);

s2:=integer(s1);

start;

t:=clock;

s3:=Seconds(t);

s4:=integer(s3);

S5:=S4-S2;

new_line;

put("Càs programu=");

put(s5);

end Bakalawr1;


Додаток В

Блок-схема роботи програми

Рис. В.1 Захищений модуль операції

Додаток Г

Лістинг програми


-- Zaxushenuj modylj----

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

with Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

use Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

Procedure Bakalawr2 is

P:integer:=4;

N:integer:=5000;

H:integer:=N/P;

t:time;

s1,S3:day_Duration;

s2,S4,S5:integer;

-----Tupu-----

type Vector is array (1..N) of integer;

type Matrix is array (1..N) of Vector;

-----Zminni------

MA,MC,MB,ME,MAA:Matrix;

----Zaxuchenuj m-----

Protected Box is

procedure VvidME(MEK: in Matrix);

function Kopija1 return Matrix;

function Kopija2 return Matrix;

procedure Signal1;

procedure Signal2;

procedure Signal3;

entry Zdat1;

entry Zdat2;

entry Zdat3;

private

F1:integer:=0;

F2:integer:=0;

F3:integer:=0;

end Box;

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

protected body Box is

Procedure VvidME(MEK: in Matrix) is

begin

ME:=MEK;

end VvidME;

function Kopija1 return Matrix is

begin

return ME;

end Kopija1;

function Kopija2 return Matrix is

begin

return MAA;

end Kopija2;

procedure Signal1 is

begin

F1:=F1+1;

end Signal1;

procedure Signal2 is

begin

F2:=F2+1;

end Signal2;

procedure Signal3 is

begin

F3:=F3+1;

end Signal3;

entry Zdat1

when F1=3 is

begin

null;

end Zdat1;

entry Zdat2

when F2=4 is

begin

null;

end Zdat2;

entry Zdat3

when F3=4 is

begin

null;

end Zdat3;

end Box;

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

procedure start is

task T1;

task body T1 is

MCC,ME1,MA1:Matrix;

begin

put("T1 started");

new_line;

--vvid matruci MC-----

for i in 1..N loop

for j in 1..N loop

MC(i)(j):=1;

end loop;

end loop;

--Signal pro zavershennja vvody--

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

--Kopija---

ME1:=Box.Kopija1;

--Obchuslennja MC*ME--

for i in 1..H loop

for j in 1..N loop

for k in 1..N loop

MAA(i)(j):=MAA(i)(j)+MC(i)(k)*ME1(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat2;

--Kopija---

MA1:=Box.Kopija2;

--Obchuslennja MB*(MC*ME)--

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)*MA1(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal3;

put(" T1 Finished ");

end T1;

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

task T2;

task body T2 is

MBB,ME2,MA2: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--

ME2:=Box.Kopija1;

--Obchuslennja MC*ME--

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

for j in 1..N loop

for k in 1..N loop

MAA(i)(j):=MAA(i)(j)+MC(i)(k)*ME2(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat2;

--Kopija---

MA2:=Box.Kopija2;

--Obchuslennja MB*(MC*ME)--

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)*MA2(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal3;

put(" T2 Finished ");

end T2;

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

task T3;

task body T3 is

MEE,ME3,MA3:Matrix;

begin

put(" T3 started ");

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

for i in 1..N loop

for j in 1..N loop

MEE(i)(j):=1;

end loop;

end loop;

Box.VvidME(MEE);

--Signal pro zavershennja vvody---

Box.Signal1;

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

ME3:=Box.Kopija1;

--Obchuslennja MC*ME--

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

for j in 1..N loop

for k in 1..N loop

MAA(i)(j):=MAA(i)(j)+MC(i)(k)*ME3(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat2;

--Kopija---

MA3:=Box.Kopija2;

--Obchuslennja MB*(MC*ME)--

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)*MA3(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal3;

put(" T3 Finished ");

end T3;

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

task T4;

task body T4 is

ME4,MA4:Matrix;

begin

put(" T4 started ");

--Chekaje zavershennja vvody inshux danux--

Box.Zdat1;

---Kopija---

ME4:=Box.Kopija1;

--Obchuslennja MC*ME--

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

for j in 1..N loop

for k in 1..N loop

MAA(i)(j):=MAA(i)(j)+MC(i)(k)*ME4(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja--

Box.Signal2;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat2;

--Kopija---

MA4:=Box.Kopija2;

--Obchuslennja MB*(MC*ME)--

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)*MA4(k)(j);

end loop;

end loop;

end loop;

--Signal pro zavershennja obchuslennja—

Box.Signal3;

--Chekaje zavershennja obchuslennja inshux procesiv--

Box.Zdat3;

--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(" T4 Finished ");

end T4;

begin Null;

end start;

begin

put("N=");

get(N);

put_line("Main");

t:=clock;

s1:=Seconds(t);

s2:=integer(s1);

start;

t:=clock;

s3:=Seconds(t);

s4:=integer(s3);

S5:=S4-S2;

put(s5);

end Bakalawr2;


Додаток Д

Блок-схема роботи програми

Рис. Д.1 Захищений модуль операції

Додаток Е

Лістинг програми


-- Zaxushenuj modylj----

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

with Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

use Ada.Text_IO,

Ada.Integer_Text_IO,Ada.Calendar;

Procedure Bakalawr3 is

P:integer:=4;

N:integer:=4000;

H:integer:=N/P;

t:time;

s1,S3:day_Duration;

s2,S4,S5:integer;

-----Tupu-----

type Vector is array (1..N) of integer;

type Matrix is array (1..N) of Vector;

-----Zminni------

MA,MC,MB,MO,MK:Matrix;

----Zaxuchenuj m-----

Protected Box is

procedure VvidMC(MCK: in Matrix);

procedure VvidMK(MKK: in Matrix);

function Kopija1 return Matrix;

function Kopija2 return Matrix;

procedure Signal1;

procedure Signal2;