MODULE vectorscalar1; (*--------------------------------------------------------- File name: vectorscalar1.pm Author: AG Date: 5/27/05 Problem: This program calculates the scalar multiplication of a series of vectors represented by sections of a chain. Each chain contains many vectors of size N. This program calculates the scalar mutliplications of all those vectors by one vector stored in an array in the controller. Example of Execution 1: N: 2 L2: 0 3 1 3 3 4 2 1 0 0 3 4 3 0 4 A: 1 2 L3: 6 7 7 9 11 10 4 2 0 3 11 11 3 4 4 Example of Execution 2: N: 3 L2: 1 1 1 1 0 2 1 4 3 4 0 2 2 2 2 A: 1 2 3 L3: 6 6 4 7 7 15 18 21 13 10 8 12 12 10 6 Cycles: assignment + (N - 1)(1 multiplication + 1 shift + 1 addition). *) (*---------------------------------------------------------- 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, L3: chain OF INTEGER; N, i, RightLimit, MaxVal: INTEGER; A: ARRAY[0..(N-1)] OF INTEGER; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (*Initialize data *) RightLimit := 16; MaxVal := 5;(* Maximum value for the random numbers *) N := 2; L1 := RandomInt(chain) MOD MaxVal; (*set L2 to random numbers *) L2 := L1; L3 := 0; (* Initialize array of multiplyers *) A[0] := 1; A[1] := 2; (* A[2]:= 3; *) L0 := ID(chain); IF L0 < RightLimit THEN L0 := (L0 - 1) MOD N; (*printing*) WriteString("N: "); WriteInt(N, 2); WriteLn; WriteString("L2: "); WriteInt(L2, 2); WriteLn; WriteString("A: "); FOR i:=0 TO (N - 1) DO IF L0= i THEN (* Test for correspondent multiplyer *) L2 := L2 * A[i]; (*L2 = 1*1 2*2 3*1 4*2 *) END; (* IF *) (*printing*) WriteInt(A[i] , 2); END; (* FOR *) (*printing *)WriteLn; L3 := L2; (* prepare for moving *) FOR i:= 1 TO (N - 1) DO L3 := RECEIVE.left(L3); (* shift to prepare the sum *) L3 := L3 + L2; (* calculate the sum *) END; (* FOR *) (*printint *) WriteString("L3: "); WriteInt(L3, 2); WriteLn; END; (* IF *) END vectorscalar1.