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 clock(void);
64 /* map the FORTRAN math functions, etc. to the C versions */
73 /* function prototypes */
74 void POUT(long N
, long J
, long K
, double X1
, double X2
, double X3
, double X4
);
77 void P3(double X
, double Y
, double *Z
);
78 #define USAGE "usage: whetdc [-c] [loops]\n"
81 COMMON T,T1,T2,E1(4),J,K,L
87 main(int argc
, char *argv
[])
89 /* used in the FORTRAN version */
91 long N1
, N2
, N3
, N4
, N6
, N7
, N8
, N9
, N10
, N11
;
92 double X1
,X2
,X3
,X4
,X
,Y
,Z
;
96 /* added for this version */
97 long startmsec
, finimsec
;
107 C Start benchmark timing at this point.
114 C The actual benchmark starts here.
122 C With loopcount LOOP=10, one million Whetstone instructions
123 C will be executed in EACH MAJOR LOOP..A MAJOR LOOP IS EXECUTED
124 C 'II' TIMES TO INCREASE WALL-CLOCK TIMING ACCURACY.
146 C Module 1: Simple identifiers
154 for (I
= 1; I
<= N1
; I
++) {
155 X1
= (X1
+ X2
+ X3
- X4
) * T
;
156 X2
= (X1
+ X2
- X3
+ X4
) * T
;
157 X3
= (X1
- X2
+ X3
+ X4
) * T
;
158 X4
= (-X1
+ X2
+ X3
+ X4
) * T
;
161 IF (JJ
==II
)POUT(N1
,N1
,N1
,X1
,X2
,X3
,X4
);
166 C Module 2: Array elements
174 for (I
= 1; I
<= N2
; I
++) {
175 E1
[1] = ( E1
[1] + E1
[2] + E1
[3] - E1
[4]) * T
;
176 E1
[2] = ( E1
[1] + E1
[2] - E1
[3] + E1
[4]) * T
;
177 E1
[3] = ( E1
[1] - E1
[2] + E1
[3] + E1
[4]) * T
;
178 E1
[4] = (-E1
[1] + E1
[2] + E1
[3] + E1
[4]) * T
;
182 IF (JJ
==II
)POUT(N2
,N3
,N2
,E1
[1],E1
[2],E1
[3],E1
[4]);
187 C Module 3: Array as parameter
190 for (I
= 1; I
<= N3
; I
++)
194 IF (JJ
==II
)POUT(N3
,N2
,N2
,E1
[1],E1
[2],E1
[3],E1
[4]);
199 C Module 4: Conditional jumps
203 for (I
= 1; I
<= N4
; I
++) {
221 IF (JJ
==II
)POUT(N4
,J
,J
,X1
,X2
,X3
,X4
);
227 C Module 6: Integer arithmetic
235 for (I
= 1; I
<= N6
; I
++) {
236 J
= J
* (K
-J
) * (L
-K
);
237 K
= L
* K
- (L
-J
) * K
;
244 IF (JJ
==II
)POUT(N6
,J
,K
,E1
[1],E1
[2],E1
[3],E1
[4]);
249 C Module 7: Trigonometric functions
255 for (I
= 1; I
<= N7
; I
++) {
256 X
= T
* DATAN(T2
*DSIN(X
)*DCOS(X
)/(DCOS(X
+Y
)+DCOS(X
-Y
)-1.0));
257 Y
= T
* DATAN(T2
*DSIN(Y
)*DCOS(Y
)/(DCOS(X
+Y
)+DCOS(X
-Y
)-1.0));
261 IF (JJ
==II
)POUT(N7
,J
,K
,X
,X
,Y
,Y
);
266 C Module 8: Procedure calls
273 for (I
= 1; I
<= N8
; I
++)
277 IF (JJ
==II
)POUT(N8
,J
,K
,X
,Y
,Z
,Z
);
282 C Module 9: Array references
292 for (I
= 1; I
<= N9
; I
++)
296 IF (JJ
==II
)POUT(N9
,J
,K
,E1
[1],E1
[2],E1
[3],E1
[4]);
301 C Module 10: Integer arithmetic
307 for (I
= 1; I
<= N10
; I
++) {
315 IF (JJ
==II
)POUT(N10
,J
,K
,X1
,X2
,X3
,X4
);
320 C Module 11: Standard functions
325 for (I
= 1; I
<= N11
; I
++)
326 X
= DSQRT(DEXP(DLOG(X
)/T1
));
329 IF (JJ
==II
)POUT(N11
,J
,K
,X
,X
,X
,X
);
334 C THIS IS THE END OF THE MAJOR LOOP.
342 C Stop benchmark timing at this point.
348 C----------------------------------------------------------------
349 C Performance in Whetstone KIP's per second is given by
353 C where TIME is in seconds.
354 C--------------------------------------------------------------------
357 if (finimsec
-startmsec
<= 0) {
358 printf("Insufficient duration- Increase the LOOP count\n");
362 printf("Loops: %ld, Iterations: %d, Duration: %ld msec.\n",
363 LOOP
, II
, finimsec
-startmsec
);
365 KIPS
= (100.0*LOOP
*II
)/((float)(finimsec
-startmsec
)/1000.0f
);
367 printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS
/1000.0);
369 printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS
);
383 E
[1] = ( E
[1] + E
[2] + E
[3] - E
[4]) * T
;
384 E
[2] = ( E
[1] + E
[2] - E
[3] + E
[4]) * T
;
385 E
[3] = ( E
[1] - E
[2] + E
[3] + E
[4]) * T
;
386 E
[4] = (-E
[1] + E
[2] + E
[3] + E
[4]) / T2
;
402 P3(double X
, double Y
, double *Z
)
415 POUT(long N
, long J
, long K
, double X1
, double X2
, double X3
, double X4
)
417 printf("%7ld %7ld %7ld %12.4e %12.4e %12.4e %12.4e\n",
418 N
, J
, K
, X1
, X2
, X3
, X4
);