2 * C Converted Whetstone Double Precision Benchmark
3 * Version 1.2 22 March 1998
5 * (c) Copyright 1998 Painter Engineering, Inc.
8 * Permission is granted to use, duplicate, and
9 * publish this text and program as long as it
10 * includes this entire comment block and limited
13 * Converted by Rich Painter, Painter Engineering, Inc. based on the
14 * www.netlib.org benchmark/whetstoned version obtained 16 March 1998.
16 * A novel approach was used here to keep the look and feel of the
17 * FORTRAN version. Altering the FORTRAN-based array indices,
18 * starting at element 1, to start at element 0 for C, would require
19 * numerous changes, including decrementing the variable indices by 1.
20 * Instead, the array E1[] was declared 1 element larger in C. This
21 * allows the FORTRAN index range to function without any literal or
22 * variable indices changes. The array element E1[0] is simply never
23 * used and does not alter the benchmark results.
25 * The major FORTRAN comment blocks were retained to minimize
26 * differences between versions. Modules N5 and N12, like in the
27 * FORTRAN version, have been eliminated here.
29 * An optional command-line argument has been provided [-c] to
30 * offer continuous repetition of the entire benchmark.
31 * An optional argument for setting an alternate LOOP count is also
32 * provided. Define PRINTOUT to cause the POUT() function to print
33 * outputs at various stages. Final timing measurements should be
34 * made with the PRINTOUT undefined.
36 * Questions and comments may be directed to the author at
40 C**********************************************************************
41 C Benchmark #2 -- Double Precision Whetstone (A001)
43 C o This is a REAL*8 version of
44 C the Whetstone benchmark program.
46 C o DO-loop semantics are ANSI-66 compatible.
48 C o Final measurements are to be made with all
49 C WRITE statements and FORMAT sttements removed.
51 C**********************************************************************
54 /* standard C library headers required */
60 /* the following is optional depending on the timing function used */
62 unsigned long int clock(void);
63 void clockinc(void) __interrupt(1);
65 /* map the FORTRAN math functions, etc. to the C versions */
74 /* function prototypes */
75 void POUT(long N
, long J
, long K
, double X1
, double X2
, double X3
, double X4
);
78 void P3(double X
, double Y
, double *Z
);
79 #define USAGE "usage: whetdc [-c] [loops]\n"
82 COMMON T,T1,T2,E1(4),J,K,L
88 main(int argc
, char *argv
[])
90 /* used in the FORTRAN version */
92 long N1
, N2
, N3
, N4
, N6
, N7
, N8
, N9
, N10
, N11
;
93 double X1
,X2
,X3
,X4
,X
,Y
,Z
;
97 /* added for this version */
98 long startmsec
, finimsec
;
108 C Start benchmark timing at this point.
115 C The actual benchmark starts here.
123 C With loopcount LOOP=10, one million Whetstone instructions
124 C will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
125 C 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
147 C Module 1: Simple identifiers
155 for (I
= 1; I
<= N1
; I
++) {
156 X1
= (X1
+ X2
+ X3
- X4
) * T
;
157 X2
= (X1
+ X2
- X3
+ X4
) * T
;
158 X3
= (X1
- X2
+ X3
+ X4
) * T
;
159 X4
= (-X1
+ X2
+ X3
+ X4
) * T
;
162 IF (JJ
==II
)POUT(N1
,N1
,N1
,X1
,X2
,X3
,X4
);
167 C Module 2: Array elements
175 for (I
= 1; I
<= N2
; I
++) {
176 E1
[1] = ( E1
[1] + E1
[2] + E1
[3] - E1
[4]) * T
;
177 E1
[2] = ( E1
[1] + E1
[2] - E1
[3] + E1
[4]) * T
;
178 E1
[3] = ( E1
[1] - E1
[2] + E1
[3] + E1
[4]) * T
;
179 E1
[4] = (-E1
[1] + E1
[2] + E1
[3] + E1
[4]) * T
;
183 IF (JJ
==II
)POUT(N2
,N3
,N2
,E1
[1],E1
[2],E1
[3],E1
[4]);
188 C Module 3: Array as parameter
191 for (I
= 1; I
<= N3
; I
++)
195 IF (JJ
==II
)POUT(N3
,N2
,N2
,E1
[1],E1
[2],E1
[3],E1
[4]);
200 C Module 4: Conditional jumps
204 for (I
= 1; I
<= N4
; I
++) {
222 IF (JJ
==II
)POUT(N4
,J
,J
,X1
,X2
,X3
,X4
);
228 C Module 6: Integer arithmetic
236 for (I
= 1; I
<= N6
; I
++) {
237 J
= J
* (K
-J
) * (L
-K
);
238 K
= L
* K
- (L
-J
) * K
;
245 IF (JJ
==II
)POUT(N6
,J
,K
,E1
[1],E1
[2],E1
[3],E1
[4]);
250 C Module 7: Trigonometric functions
256 for (I
= 1; I
<= N7
; I
++) {
257 X
= T
* DATAN(T2
*DSIN(X
)*DCOS(X
)/(DCOS(X
+Y
)+DCOS(X
-Y
)-1.0));
258 Y
= T
* DATAN(T2
*DSIN(Y
)*DCOS(Y
)/(DCOS(X
+Y
)+DCOS(X
-Y
)-1.0));
262 IF (JJ
==II
)POUT(N7
,J
,K
,X
,X
,Y
,Y
);
267 C Module 8: Procedure calls
274 for (I
= 1; I
<= N8
; I
++)
278 IF (JJ
==II
)POUT(N8
,J
,K
,X
,Y
,Z
,Z
);
283 C Module 9: Array references
293 for (I
= 1; I
<= N9
; I
++)
297 IF (JJ
==II
)POUT(N9
,J
,K
,E1
[1],E1
[2],E1
[3],E1
[4]);
302 C Module 10: Integer arithmetic
308 for (I
= 1; I
<= N10
; I
++) {
316 IF (JJ
==II
)POUT(N10
,J
,K
,X1
,X2
,X3
,X4
);
321 C Module 11: Standard functions
326 for (I
= 1; I
<= N11
; I
++)
327 X
= DSQRT(DEXP(DLOG(X
)/T1
));
330 IF (JJ
==II
)POUT(N11
,J
,K
,X
,X
,X
,X
);
335 C THIS IS THE END OF THE MAJOR LOOP.
343 C Stop benchmark timing at this point.
349 C----------------------------------------------------------------
350 C Performance in Whetstone KIP's per second is given by
354 C where TIME is in seconds.
355 C--------------------------------------------------------------------
358 if (finimsec
-startmsec
<= 0) {
359 printf("Insufficient duration- Increase the LOOP count\n");
363 printf("Loops: %ld, Iterations: %d, Duration: %ld msec.\n",
364 LOOP
, II
, finimsec
-startmsec
);
366 KIPS
= (100.0*LOOP
*II
)/((float)(finimsec
-startmsec
)/1000.0f
);
368 printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS
/1000.0);
370 printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS
);
384 E
[1] = ( E
[1] + E
[2] + E
[3] - E
[4]) * T
;
385 E
[2] = ( E
[1] + E
[2] - E
[3] + E
[4]) * T
;
386 E
[3] = ( E
[1] - E
[2] + E
[3] + E
[4]) * T
;
387 E
[4] = (-E
[1] + E
[2] + E
[3] + E
[4]) / T2
;
403 P3(double X
, double Y
, double *Z
)
416 POUT(long N
, long J
, long K
, double X1
, double X2
, double X3
, double X4
)
418 printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
419 N
, J
, K
, X1
, X2
, X3
, X4
);