MODULE vectorscalar0; (*--------------------------------------------------------- File name: vectorscalar0.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 those vectors with themselves. Example of Execution 1: N: 2 (vector size = 2) L2: 4 1 1 3 1 2 1 0 2 0 3 3 0 2 1 L3: 17 2 10 10 5 5 1 4 4 9 18 9 4 5 1 (4 x 4) + (1 x 1)= 17 (1 x 1) + (3 x 3) = 10 ... Example of Execution 2: N: 3 L2: 2 2 4 3 4 2 2 2 0 4 2 1 2 0 0 L3: 24 29 41 29 24 12 8 20 20 21 9 5 4 0 0 (2 x 3) + (2 x 2) + (4 x 4) = 24 (3 x 3) + (4 x 4) + (2 x 2) = 29 ... Cycles: 1 multiplication + 1 assignment + (N - 1)(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; (*---------------------------------------------------------- MAIN ----------------------------------------------------------*) BEGIN (*Initialize data *) RightLimit := 16; MaxVal := 5;(* Maximum value for the random numbers *) N := 3; L1 := RandomInt(chain) MOD MaxVal; (*set L1 to random numbers *) L2 := L1; IF ID(chain) < RightLimit THEN (*printing *) WriteString("N: "); WriteInt(N, 2); WriteLn; WriteString("L2: "); WriteInt(L2, 2); WriteLn; L2 := L2 * L2; (*L2 = 1*1 2*2 3*3 4*4 *) L3:= L2; FOR i:= 1 TO (N - 1) DO L3 := RECEIVE.left(L3); (* shift the elements in the group *) L3 := L3 + L2; (* calculate the sum *) END; (* FOR *) (*printing*) WriteString("L3: "); WriteInt(L3, 2); WriteLn; END; (* IF *) END vectorscalar0.