MODULE exo4; (* ---------------------------------------------------------------------- exo4.pm D. Thiebaut Computes the value of a polynomial of degree 4 in a chain of PEs. The number of PEs is defined by N. The coefficients are stored in a vector array called coefs. The value x is given by the ID of the PE in which it resides. The result of the polynomial evaluation is saved in y at the end of the computation. ---------------------------------------------------------------------- *) CONST N=8; CONFIGURATION chain[0..N-1]; CONNECTION (* no connection needed *); VAR coefs : chain OF ARRAY[0..4] OF INTEGER; x, y : chain OF INTEGER; BEGIN (*--- initialization ---*) x := ID( chain ); WriteString( " x = " ); WriteInt( x, 2 ); (*--- coefficients ---*) coefs[0] := 1; coefs[1] := 1; coefs[2] := 1; coefs[3] := 1; coefs[4] := 1; (*--- parallel computation of the polynomials ---*) (*--- (can be made more efficient using horner's method) ---*) y := ( x**4 ) * coefs[4] + ( x**3 ) * coefs[3] + ( x**2 ) * coefs[2] + x * coefs[1] + coefs[0]; (*--- output ---*) WriteString( " y = " ); WriteInt( y, 2 ); END exo4.