Post Reply 
Benchmark: Whetstones
12-03-2017, 11:51 PM (This post was last modified: 11-01-2018 08:25 PM by StephenG1CMZ.)
Post: #1
Benchmark: Whetstones
I have attempted an implementation of the original Whetstone benchmark algorithm in PPL.

This was primarily a learning exercise to remind myself what the benchmark consisted of and to discover whether it was implementable in PPL.

Disclaimer: The implementation is unverified both in accuracy and timings.

If comparing accuracy of results with on-line sources, remember that there are several Whetstone benchmarks, so you might not be making a valid comparison.

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
12-04-2017, 12:01 AM (This post was last modified: 12-04-2017 12:02 AM by StephenG1CMZ.)
Post: #2
RE: Benchmark: Whetstones
Version 0.1 is a simple translation of the Original Algol benchmark.
No attempt has been made to optimise the PPL.
The figures here are not intended to be representative of what the PPL can achieve.

Code:

 LOCAL ID:="Whetstones V0.1 (UNVERIFIED)\nPPL StephenG1CMZ 2017";

 //Requires a procedure to output a list of reals
 //(to list,print or logfile)
 //IMPORT(OUTREAL);//See Benchmarks for example

 EXPORT ABOUT()
 BEGIN
  MSGBOX(ID);
  MSGBOX(" Aims to approximate the workload of Whetstone & verify that the algorithm is implementable in PPL.");
  MSGBOX("Neither accuracy nor timing is approved.");
  MSGBOX("The unoptimised version makes no attempt to improve loops.");
 END;

 //PPL:ALL VARIABLES REAL
 //PPL:INPUTS/OUTPUTS LISTED RATHER THAN 1BY1
 //PPL:OUTPUTS LISTED AND PRINTED
 //ONLY ONE REQUIRED AND SOME DO NEITHER

 LOCAL UnitST:="Mwhetstone";

 // BENCHMARK 
 
 POUT(LST)
 BEGIN
  //IN ORIGINAL EACH NUM WAS OUTREALED
  OUTREAL(LST);
 END;

 //INITIALISE CONSTANTS
 LOCAL TT:=0.499975;
 LOCAL T1:=0.50025;
 LOCAL T2:=2.0;

 //REAL
 LOCAL X1,X2,X3,X4,XX,YY,ZZ;
 //ARRAY
 LOCAL E1:={};//4
 LOCAL EE:={};//UNDEF
 //INTEGER
 LOCAL II,JJ,KK,LL;
 LOCAL NK:={0,12,14,345,0,210,32,899,616,0,93};//11 ITERATION CONSTANTS
 LOCAL NN:={};//11 ITERATION COUNTS

 P0()
 BEGIN
  E1(JJ):=E1(KK);
  E1(KK):=E1(LL);
  E1(LL):=E1(JJ);
 END;//P0

 P3(XX,YY,ZZ)
 //REAL XYZ
 BEGIN
  LOCAL XXX,YYY;//VALUE
  XXX:=TT*(XX+YY);
  YYY:=TT*(XX+YY);
  ZZ:=(XXX+YYY)/T2;
  RETURN ZZ;//UPDATED
 END;

 PA(EEP)
 //EE:ARRAY
 BEGIN
  LOCAL EE:=EEP;//UPDATABLE 
  //INTEGER
  LOCAL JJ:=0;
  //LAB:
  REPEAT
   EE(1):=( EE(1) + EE(2) + EE(3) - EE(4))*TT;
   EE(2):=( EE(1) + EE(2) - EE(3) + EE(4))*TT; 
   EE(3):=( EE(1) - EE(2) + EE(3) + EE(4))*TT;
   EE(4):=(−EE(1) + EE(2) + EE(3) + EE(4))*TT; 
   JJ:=JJ+1;
  UNTIL JJ≥6;//GOTO LAB-PPL HAS NO GOTO
  RETURN EE;//UPDATED  
 END;//PA

 WhetstoneItUnopt(ITER)
 //Unoptimised:No PPL optimisation
 //ITER:ITERATIONS. 10=MEGAWets.
 BEGIN
  //INITIALISE CONSTANTS
  TT:=0.499975;
  T1:=0.50025;
  T2:=2.0;
  NN:=ITER*NK;
  PRINT();//DEBUG
  
  //MODULE 1:SIMPLE IDENTIFIERS
   X1:=1.0;
   //X2:=X3:=X4:=−1.0;
   X4:=−1.0; X3:=X4; X2:=X3;
   //MSGBOX(NN(1));
   FOR II FROM 1 TO NN(1) STEP 1 DO
    X1:=( X1 + X2 + X3 - X4)*TT;
    X2:=( X1 + X2 - X3 + X4)*TT;
    X3:=( X1 - X2 + X3 + X4)*TT;
    X4:=(−X1 + X2 + X3 + X4)*TT;
   END;//FOR
  //END MODULE 1
  POUT({NN(1),NN(1),NN(1),X1,X2,X3,X4});
   
  //MODULE 2:ARRAY ELEMENTS
   E1(1):=1.0;
   //EE(2):=EE(3):=EE(4):=−1.0;
   E1(4):=−1.0; E1(3):=E1(4); E1(2):=E1(3);
   
   FOR II FROM 1 TO NN(2) STEP 1 DO
    E1(1):=( E1(1) + E1(2) + E1(3) - E1(4))*TT;
    E1(2):=( E1(1) + E1(2) - E1(3) + E1(4))*TT;
    E1(3):=( E1(1) - E1(2) + E1(3) + E1(4))*TT;
    E1(4):=(−E1(1) + E1(2) + E1(3) + E1(4))*TT; 
   END;//FOR
  //END MODULE 2
  POUT({NN(2),NN(3),NN(2),E1});
 
  //MODULE 3: ARRAY AS PARAMETER
   FOR II FROM  1 TO NN(3) STEP 1 DO
    E1:=PA(E1);
   END;//FOR
  //END MODULE 3
  POUT({NN(3),NN(2),NN(2),E1});
  
  //MODULE 4: CONDITIONAL JUMPS
   JJ:=1;
   FOR II FROM 1 TO NN(4)  STEP 1 DO
    IF JJ==1 THEN
     JJ:=2;
    ELSE
     JJ:=3;
    END;
    IF JJ>2 THEN
     JJ:=0;
    ELSE
     JJ:=1;
    END;
    IF JJ<1 THEN
     JJ:=1;
    ELSE
     JJ:=0;
    END;
   END;//FOR
  //END MODULE 4
  POUT({NN(4),JJ,JJ,X1,X2,X3,X4});

  //MODULE 5: OMITTED
  //END MODULE 5

  //MODULE 6: INTEGER ARITHMETIC
   JJ:=1;
   KK:=2;
   LL:=3;

   FOR II FROM  1 TO NN(6) STEP 1 DO

    JJ:=JJ*(KK-JJ)*(LL-KK);
    KK:=LL*KK-(LL-JJ)*KK;
    LL:=(LL-KK)*(KK+JJ);
     //SOME VERSIONS USE -2 AND ROUND?
    E1(LL-1):=JJ+KK+LL;
    E1(KK-1):=JJ*KK*LL;
   END;
  //END MODULE 6
  POUT({NN(6),JJ,KK,E1});
  
  //MODULE 7: TRIG FUNCTIONS
   YY:=0.5;
   XX:=0.5;
   FOR II FROM 1 TO NN(7) STEP 1  DO
    XX:=TT*ATAN(T2*SIN(XX)*COS(XX)/(COS(XX+YY)+COS(XX-YY)-1.0));
    YY:=TT*ATAN(T2*SIN(YY)*COS(YY)/(COS(XX+YY)+COS(XX-YY)-1.0));
   END;
  //END MODULE 7
  POUT({JJ,KK,XX,XX,YY,YY});

  //MODULE 8: PROCEDURE CALLS
   //X:=Y:=Z:=1.0;
   ZZ:=1.0;
   YY:=ZZ;
   XX:=YY;
   FOR II FROM 1  TO NN(8)  STEP 1 DO
    ZZ:=P3(XX,YY,ZZ);
   END;
  //END MODULE 8
  POUT({NN(8),JJ,KK,XX,YY,ZZ,ZZ});

  //MODULE 9: ARRAY REFERENCES
   JJ:=1;
   KK:=2;
   LL:=3;
   E1(1):=1.0;
   E1(2):=2.0;
   E1(3):=3.0;
   FOR II FROM 1  TO  NN(9) STEP 1 DO
    P0();
   END; 
  //END MODULE 9
  POUT({NN(9),JJ,KK,E1});

  //MODULE 10: INTEGER ARITHMETIC
   JJ:=2;
   KK:=3;
   FOR II FROM 1  TO NN(10) STEP 1 DO
    JJ:=JJ+KK;
    KK:=JJ+KK;
    JJ:=KK-JJ;
    KK:=KK-JJ-JJ;
   END;

  //END MODULE 10
  POUT({NN(10),JJ,KK,X1,X2,X3,X4});

  //MODULE 11: STANDARD FUNCTIONS
   XX:=0.75;
   FOR II FROM 1 TO NN(11) STEP 1 DO
    //SOME VERSIONS USE ALOG NOT LN
    XX:=√(EXP(LN(XX)/T1));
   END;
  //END MODULE 11 
  POUT({NN(11),JJ,KK,XX,XX,XX,XX});

  //OUTPUT:POUT
  //EITHER JUST PRINT OR RETURN OR SAVE OUTL
  //IF OUTLIST THEN
  // RETURN OUTL;//POUT
  //END;

 END;//BenchWet

 // END BENCHMARK

 EXPORT WhetstoneIt(ITER)
 BEGIN
  RETURN WhetstoneItUnopt(ITER);
 END;

 EXPORT MegaWhetstone()
 BEGIN
  WhetstoneItUnopt(10);
 END;

 EXPORT MegaWhetstones(Mwhetstones)
 BEGIN
  WhetstoneItUnopt(10*Mwhetstones);
 END;

 EXPORT MWhetstone_s ()
 BEGIN
  LOCAL TM:=TEVAL(MegaWhetstone);
   PRINT(ID);
   PRINT(TM+"/"+UnitST);
  
  RETURN TM;
 END;

 EXPORT MWIPS()
 //
 BEGIN
  LOCAL MWIPS;
  LOCAL TM:=MWhetstone_s();

  TM:=TM/1_s;//Remove Units
  //0s=>clock err or more Whetstones needed
  MWIPS:=IFTE(TM,ROUND((1/TM),6),"NaN");//Guard 0 Time
  PRINT(MWIPS+"_"+UnitST+"/s");
  RETURN MWIPS;
 END;

 EXPORT WHETSTONES()
 BEGIN
  ABOUT();
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
11-01-2018, 07:59 PM (This post was last modified: 11-01-2018 08:03 PM by StephenG1CMZ.)
Post: #3
RE: Benchmark: Whetstones
The Whetstone benchmark relies upon an OUTREAL function.

This was originally provided in my Benchmarks program, but that complicated compilation.

I have now extracted OUTREAL here.
The example code here emphasis flexibility (allowing reals to be printed, listed, or both).
Before publishing timings a much simpler OUTREAL should be substituted
Code:


 //CUSTOMISE
 //SELECT OUTPUT 
 //GLOBAL SP SELECTS/INHIBITS PRINT
 //TO LIST OR TO SCREEN (OR LOGFILE TBD)
 EXPORT BenchmarkList:=1;
 EXPORT BenchmarkAns:={};
 //END CUSTOMISE

 EXPORT OUTREAL(LST)
 //REQUIRED TO OUTPUT OR USE RESULTS
 //HOW IS UNSPECIFIED
 BEGIN 
  //ONLY 1 OUTPUT IS REQUIRED
  //THE SELECTION/ALTERNATIVE IS AN OVERHEAD ANDSHOULDBE REMOVED
  IF SP THEN
   PRINT(LST);
  END;
  IF BenchmarkList THEN
   BenchmarkAns(0):=LST;
  END;
 END;

 BenchmarkReset()
 BEGIN
  PRINT();
  //PRINT(CRID);
  BenchmarkAns:={};
 END;

Stephen Lewkowicz (G1CMZ)
https://my.numworks.com/python/steveg1cmz
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)