Параллельные алгоритмы

Листинг №4

Пример использования процедур из модуля IO_Net.pas

{ ГЛАВНАЯ ЗАДАЧА    master.pas: }  
                 PROGRAM MASTER (Input, Output);     
                 { Модуль оpганизует    взаимодействие с сетью }  
                    CONST   
                           Size_Buf = 2;  
                 TYPE    
                           Mas_Buf  = ARRAY    [1..Size_Buf] OF Integer;     
                     IMPORT PROCEDURE Number     ( VAR n : INTEGER );        
                    IMPORT PROCEDURE MasterOut      
                           ( addr, len : INTEGER;  
                             VAR byff  : Mas_Buf;     
                                 l     : BOOLEAN    );  
                    IMPORT PROCEDURE MasterIn      
                           ( VAR addr, len : INTEGER;    VAR byff: Mas_Buf; l: BOOLEAN );        
                    VAR kt,k,p,i,addr,len,j :    INTEGER;  
                                          m : Mas_Buf;  
                                          l : BOOLEAN;  
                 BEGIN  
                    WHILE TRUE DO    BEGIN  
                 { Опpеделение кол-ва сетевых тpанспьютеpов}  
                       Number(kt);  
                       WriteLn;  
                       WriteLn('Transputer : ', kt);     
                       WriteLn;  
                 {Ввод исходных данных}  
                       WriteLn('Сколько    использовать?');  
                       Read(k);  
                       WriteLn;  
                       WriteLn('Parametr ?');     
                       Read(p);  
                       WriteLn;  
                       WriteLn('Start Work');     
                 { Рассылка данных по сети }  
                       FOR i:=1 TO k DO BEGIN     
                          m[1]:=i; m[2]:=p;     
                          MasterOut(i,2,m,TRUE);  
                       END;  
                       WriteLn;  
                       WriteLn(' Save Data ');     
                 {Получение данных из сети }  
                       FOR i:=1 TO k DO    BEGIN  
                          MasterIn(addr,len,m,l);  
                 {Вывод pезультатов    }  
                          WriteLn;                                   
                          Write('Addres ', addr);  
                          Write('     Rezalt  ', i, ' :');     
                          FOR j:=1 TO 2 DO    BEGIN  
                             Write(' ', m[j]);     
                          END;  
                          WriteLn;  
                       END;  
                 (*Завеpшение pабот*)  
                       WriteLn;  
                       Write(' End ');  
                    END;  
                 END.  
   
MODULE Worker;  
                    CONST  
                           Size_Buf = 256;  
                    TYPE  
                           Mas_Buf  = ARRAY    [1..Size_Buf] OF Integer;     
IMPORT PROCEDURE WorkerOut   
                           (    len: INTEGER; VAR byff  : Mas_Buf;  l        : BOOLEAN );  
                    IMPORT PROCEDURE WorkerIn      
                           ( VAR len : INTEGER; VAR    byff: Mas_Buf; l : BOOLEAN );  
                    PROCEDURE MyWorker;     
                      VAR i,j,k,len : INTEGER;     
                               buf : Mas_Buf;  
                                l : BOOLEAN;  
                    BEGIN  
                    WHILE TRUE DO BEGIN  
                       WorkerIn(len,buff,l);  
                       FOR i:=1 TO buff[2] DO BEGIN     
                          FOR j:=1 TO 1000000    DO BEGIN  
                             k:=k;  
                          END;  
                       END;  
                       buff[1]:=buff[1]+1000;  
                       buff[2]:=len;  
                       WorkerOut(len,buff,TRUE);  
                    END;  
                    END;  
                BEGIN  
                    MyWorker;  
                END. 

возврат


Наш канал на Youtube

1999 1 2 3 4 5 6 7 8 9 10 11 12
2000 1 2 3 4 5 6 7 8 9 10 11 12
2001 1 2 3 4 5 6 7 8 9 10 11 12
2002 1 2 3 4 5 6 7 8 9 10 11 12
2003 1 2 3 4 5 6 7 8 9 10 11 12
2004 1 2 3 4 5 6 7 8 9 10 11 12
2005 1 2 3 4 5 6 7 8 9 10 11 12
2006 1 2 3 4 5 6 7 8 9 10 11 12
2007 1 2 3 4 5 6 7 8 9 10 11 12
2008 1 2 3 4 5 6 7 8 9 10 11 12
2009 1 2 3 4 5 6 7 8 9 10 11 12
2010 1 2 3 4 5 6 7 8 9 10 11 12
2011 1 2 3 4 5 6 7 8 9 10 11 12
2012 1 2 3 4 5 6 7 8 9 10 11 12
2013 1 2 3 4 5 6 7 8 9 10 11 12
Популярные статьи
КомпьютерПресс использует