MODULE modulus; (*--------------------------------------------------------- File name: modulus.pm Author: MM Date: 5/18/05 Problem: This program parallely calculates the Modulus of N on a line. In this example, the initial line is composed of the indexes of the processors, and N is read trough standard input. Example of Execution: C:\>p3 modulus C:\>a Line is: 1 2 3 4 5 ... 1024 Enter N?: 5 Line is: 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 1 2 3 4 0 ... Cycles: 1 MOD. *) (*---------------------------------------------------------- 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 L: chain OF INTEGER; (* Line always "L#" *) N: INTEGER; (*---------------------------------------------------------- MAIN -----------------------------------------------------------*) BEGIN (*initializing data *) L := ID( chain ); (* Index is ID *) WriteString( " Line is: ");WriteInt( L , 2);WriteLn; (*reading*) WriteString("Enter N?: "); ReadInt(N); (* Read an integer *) L:= L MOD N; (* calculate mod of N *) (*printing*) WriteString( "Line is: "); WriteInt( L , 2); WriteLn; END modulus.