MODULE broadcast3; (*--------------------------------------------------------- File name: broadcast3.pm Author: AG Date: 5/24/05 Problem: This program broadcasts a marked selection of a chain into another chain. Selection is marked from 1 to N. Example of Execution: N: 3 L1: 34 44 92 7 47 43 0 36 22 91 30 76 50 93 29 85 L2: 34 44 92 34 44 92 34 44 92 34 44 92 34 44 92 34 Cycles: N assignments (where N is the size of the selected section of the chain) *) (*---------------------------------------------------------- CONFIGURATION ----------------------------------------------------------*) CONST MAXCELLS=1024; (* MAXCELLS cells in one line *) CONFIGURATION chain[0..(MAXCELLS - 1)]; CONNECTION left: chain [i] -> chain[(i-1) MOD MAXCELLS]; right: chain[i] -> chain[(i+1) MOD MAXCELLS]; (*---------------------------------------------------------- VARIABLES ----------------------------------------------------------*) VAR L0, L1, L2: chain OF INTEGER; N, i, RightLimit, MaxVal: INTEGER; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (*Initialize data *) RightLimit:= 16; N:= 3; MaxVal:= 100; (* Maximum value for the random numbers *) L1:= RandomInt(chain) MOD MaxVal; (*set L1 to random numbers *) L0:= ID(chain) - 1; (* L0= 0 1 2 3 4 5 6 7 8 9 10 .. *) IF L0 < RightLimit THEN (*Prepare Selection *) L0:= L0 MOD N; (* L0 = 0 1 2 3 4 0 1 2 3 4 0 1 2 3 *) FOR i:= 0 TO (N - 1) DO IF L0 = i THEN (*select positions for new items *) L2:= L1<>; (* Processor ID's start from 1 to N *) END; (* IF *) END; (* FOR *) (*printing *) WriteString("N: "); WriteInt(N, 2);WriteLn; WriteString("L1: "); WriteInt(L1, 2);WriteLn; WriteString("L2: "); WriteInt(L2, 2);WriteLn; END; (* IF *) END broadcast3.