2004-05-19 18:02:34 +00:00
|
|
|
/*
|
2004-05-26 20:44:29 +00:00
|
|
|
* C/C++ Whetstone Benchmark Single or Double Precision
|
|
|
|
*
|
|
|
|
* Original concept Brian Wichmann NPL 1960's
|
|
|
|
* Original author Harold Curnow CCTA 1972
|
|
|
|
* Self timing versions Roy Longbottom CCTA 1978/87
|
|
|
|
* Optimisation control Bangor University 1987/90
|
|
|
|
* C/C++ Version Roy Longbottom 1996
|
|
|
|
* Compatibility & timers Al Aburto 1996
|
|
|
|
*
|
|
|
|
************************************************************
|
|
|
|
*
|
|
|
|
* Official version approved by:
|
|
|
|
*
|
|
|
|
* Harold Curnow 100421.1615@compuserve.com
|
|
|
|
*
|
|
|
|
* Happy 25th birthday Whetstone, 21 November 1997
|
2004-05-19 18:02:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// Modified a little to work with BOINC
|
2004-09-14 21:29:52 +00:00
|
|
|
//
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2010-05-11 19:10:29 +00:00
|
|
|
#include "cpp.h"
|
|
|
|
|
2004-05-19 18:02:34 +00:00
|
|
|
#ifdef _WIN32
|
2004-06-16 23:29:48 +00:00
|
|
|
#include "boinc_win.h"
|
2010-05-11 19:10:29 +00:00
|
|
|
#else
|
2005-11-21 18:34:44 +00:00
|
|
|
#include "config.h"
|
2009-04-30 21:48:20 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <math.h>
|
|
|
|
#include <time.h>
|
2004-05-22 01:36:36 +00:00
|
|
|
#endif
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2004-11-05 19:52:19 +00:00
|
|
|
#include "util.h"
|
2004-05-21 22:40:54 +00:00
|
|
|
#include "cpu_benchmark.h"
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2004-05-26 20:44:29 +00:00
|
|
|
#define SPDP double
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2004-09-07 20:06:01 +00:00
|
|
|
// External array; store results here so that optimizing compilers
|
|
|
|
// don't do away with their computation.
|
|
|
|
// suggested by Ben Herndon
|
|
|
|
//
|
|
|
|
double extern_array[12];
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2004-09-14 21:29:52 +00:00
|
|
|
// #pragma intrinsic (sin, cos, tan, atan, sqrt, exp, log)
|
|
|
|
|
|
|
|
|
2004-05-26 20:44:29 +00:00
|
|
|
void pa(SPDP e[4], SPDP t, SPDP t2)
|
|
|
|
{
|
2011-01-06 23:09:13 +00:00
|
|
|
long j;
|
|
|
|
for(j=0;j<6;j++)
|
|
|
|
{
|
|
|
|
e[0] = (e[0]+e[1]+e[2]-e[3])*t;
|
|
|
|
e[1] = (e[0]+e[1]-e[2]+e[3])*t;
|
|
|
|
e[2] = (e[0]-e[1]+e[2]+e[3])*t;
|
|
|
|
e[3] = (-e[0]+e[1]+e[2]+e[3])/t2;
|
|
|
|
}
|
|
|
|
|
|
|
|
return;
|
2004-05-26 20:44:29 +00:00
|
|
|
}
|
2004-05-24 23:57:28 +00:00
|
|
|
|
2004-05-26 20:44:29 +00:00
|
|
|
void po(SPDP e1[4], long j, long k, long l)
|
|
|
|
{
|
2011-01-06 23:09:13 +00:00
|
|
|
e1[j] = e1[k];
|
|
|
|
e1[k] = e1[l];
|
|
|
|
e1[l] = e1[j];
|
|
|
|
return;
|
2004-05-26 20:44:29 +00:00
|
|
|
}
|
2004-05-24 23:57:28 +00:00
|
|
|
|
2004-05-26 20:44:29 +00:00
|
|
|
void p3(SPDP *x, SPDP *y, SPDP *z, SPDP t, SPDP t1, SPDP t2)
|
|
|
|
{
|
2011-01-06 23:09:13 +00:00
|
|
|
*x = *y;
|
|
|
|
*y = *z;
|
|
|
|
*x = t * (*x + *y);
|
|
|
|
*y = t1 * (*x + *y);
|
|
|
|
*z = (*x + *y)/t2;
|
|
|
|
return;
|
2004-05-26 20:44:29 +00:00
|
|
|
}
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2008-05-05 00:51:20 +00:00
|
|
|
// return an error if CPU time is less than min_cpu_time
|
|
|
|
//
|
|
|
|
int whetstone(double& flops, double& cpu_time, double min_cpu_time) {
|
2011-01-06 23:09:13 +00:00
|
|
|
long n1,n2,n3,n4,n5,n6,n7,n8,i,ix,n1mult;
|
|
|
|
SPDP x,y,z;
|
|
|
|
long j,k,l, jjj;
|
|
|
|
SPDP e1[4];
|
|
|
|
double startsec, finisec;
|
|
|
|
double KIPS;
|
2004-05-26 20:44:29 +00:00
|
|
|
int xtra, ii;
|
2007-06-12 17:28:08 +00:00
|
|
|
int x100 = 1000; // chosen to make each pass take about 0.1 sec
|
2004-05-26 21:00:46 +00:00
|
|
|
// on my current computer (2.2 GHz celeron)
|
2007-06-12 17:28:08 +00:00
|
|
|
// This must be small enough that one loop finishes
|
|
|
|
// in 10 sec on the slowest CPU
|
2004-05-21 22:40:54 +00:00
|
|
|
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[11] = 1;
|
2004-05-21 22:40:54 +00:00
|
|
|
benchmark_wait_to_start(BM_TYPE_FP);
|
|
|
|
|
2004-12-05 23:52:17 +00:00
|
|
|
boinc_calling_thread_cpu_time(startsec);
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
SPDP t = 0.49999975;
|
|
|
|
SPDP t0 = t;
|
|
|
|
SPDP t1 = 0.50000025;
|
|
|
|
SPDP t2 = 2.0;
|
2004-07-09 14:11:17 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
n1 = 12*x100;
|
|
|
|
n2 = 14*x100;
|
|
|
|
n3 = 345*x100;
|
|
|
|
n4 = 210*x100;
|
|
|
|
n5 = 32*x100;
|
|
|
|
n6 = 899*x100;
|
|
|
|
n7 = 616*x100;
|
|
|
|
n8 = 93*x100;
|
2004-05-26 20:44:29 +00:00
|
|
|
|
|
|
|
xtra = 1;
|
2011-01-06 23:09:13 +00:00
|
|
|
n1mult = 10;
|
2004-05-26 20:44:29 +00:00
|
|
|
ii = 0;
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 1, Array elements */
|
|
|
|
|
|
|
|
e1[0] = 1.0;
|
|
|
|
e1[1] = -1.0;
|
|
|
|
e1[2] = -1.0;
|
|
|
|
e1[3] = -1.0;
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=0; i<n1*n1mult; i++)
|
|
|
|
{
|
|
|
|
e1[0] = (e1[0] + e1[1] + e1[2] - e1[3]) * t;
|
|
|
|
e1[1] = (e1[0] + e1[1] - e1[2] + e1[3]) * t;
|
|
|
|
e1[2] = (e1[0] - e1[1] + e1[2] + e1[3]) * t;
|
|
|
|
e1[3] = (-e1[0] + e1[1] + e1[2] + e1[3]) * t;
|
|
|
|
}
|
|
|
|
t = 1.0 - t;
|
|
|
|
}
|
|
|
|
t = t0;
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[0] = e1[0];
|
|
|
|
extern_array[1] = e1[1];
|
|
|
|
extern_array[2] = e1[2];
|
|
|
|
extern_array[3] = e1[3];
|
2004-05-26 20:44:29 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 2, Array as parameter */
|
|
|
|
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=0; i<n2; i++)
|
|
|
|
{
|
|
|
|
pa(e1,t,t2);
|
|
|
|
}
|
|
|
|
t = 1.0 - t;
|
|
|
|
}
|
|
|
|
t = t0;
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[4] = e1[0];
|
2004-05-26 20:44:29 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 3, Conditional jumps */
|
|
|
|
jjj = (long) extern_array[11];
|
2004-09-19 01:10:50 +00:00
|
|
|
j = k = jjj;
|
2011-01-06 23:09:13 +00:00
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++) {
|
|
|
|
for(i=0; i<n3; i++) {
|
|
|
|
if(j==1) l = jjj;
|
|
|
|
else l = k;
|
|
|
|
if(k>2) j = jjj;
|
|
|
|
else j = 1;
|
|
|
|
if(l<1) k = 1;
|
|
|
|
else k = jjj;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[5] = (double)j;
|
2004-05-26 20:44:29 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 4, Integer arithmetic */
|
|
|
|
j = long(e1[0]);
|
|
|
|
k = 2;
|
|
|
|
l = 3;
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=0; i<n4; i++)
|
|
|
|
{
|
|
|
|
j = j *(k-j)*(l-k);
|
|
|
|
k = l * k - (l-j) * k;
|
|
|
|
l = (l-k) * (k+j);
|
|
|
|
e1[l&3] = j + k + l;
|
|
|
|
e1[k&3] = j * k * l;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[6] = e1[0];
|
2004-07-09 14:11:17 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 5, Trig functions */
|
|
|
|
x = 0.5;
|
|
|
|
y = 0.5;
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=1; i<n5; i++)
|
|
|
|
{
|
|
|
|
x = t*atan(t2*sin(x)*cos(x)/(cos(x+y)+cos(x-y)-1.0));
|
|
|
|
y = t*atan(t2*sin(y)*cos(y)/(cos(x+y)+cos(x-y)-1.0));
|
|
|
|
}
|
|
|
|
t = 1.0 - t;
|
|
|
|
}
|
|
|
|
t = t0;
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[7] = x;
|
2004-07-09 14:11:17 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 6, Procedure calls */
|
|
|
|
x = 1.0;
|
|
|
|
y = 1.0;
|
|
|
|
z = 1.0;
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=0; i<n6; i++)
|
|
|
|
{
|
|
|
|
p3(&x,&y,&z,t,t1,t2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[8] = x;
|
2004-07-09 14:11:17 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 7, Array refrences */
|
|
|
|
j = 0;
|
|
|
|
k = 1;
|
|
|
|
l = 2;
|
|
|
|
e1[0] = 1.0;
|
|
|
|
e1[1] = 2.0;
|
|
|
|
e1[2] = 3.0;
|
|
|
|
{
|
|
|
|
for (ix=0; ix<xtra; ix++)
|
|
|
|
{
|
|
|
|
for(i=0;i<n7;i++)
|
|
|
|
{
|
|
|
|
po(e1,j,k,l);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[9] = e1[0];
|
2004-07-09 14:11:17 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
/* Section 8, Standard functions */
|
|
|
|
x = 0.75;
|
|
|
|
for (ix=0; ix<xtra; ix++) {
|
|
|
|
for(i=0; i<n8; i++) {
|
|
|
|
x = sqrt(exp(log(x)/t1));
|
|
|
|
}
|
|
|
|
}
|
2004-09-07 20:06:01 +00:00
|
|
|
extern_array[10] = x;
|
2004-05-26 20:44:29 +00:00
|
|
|
|
|
|
|
ii++;
|
2004-05-21 22:40:54 +00:00
|
|
|
}
|
2004-05-22 01:36:36 +00:00
|
|
|
while (!benchmark_time_to_stop(BM_TYPE_FP));
|
2004-05-21 23:03:48 +00:00
|
|
|
|
2004-12-05 23:52:17 +00:00
|
|
|
boinc_calling_thread_cpu_time(finisec);
|
2008-05-05 00:51:20 +00:00
|
|
|
double diff = finisec - startsec;
|
|
|
|
cpu_time = diff;
|
|
|
|
if (diff < min_cpu_time) {
|
|
|
|
return -1;
|
|
|
|
}
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2011-01-06 23:09:13 +00:00
|
|
|
KIPS = (100.0*x100*ii)/diff;
|
2004-05-19 20:12:06 +00:00
|
|
|
#if 0
|
2011-01-06 23:09:13 +00:00
|
|
|
if (KIPS >= 1000.0)
|
|
|
|
printf("C Converted Double Precision Whetstones: %.1f MIPS\n", KIPS/1000.0);
|
|
|
|
else
|
|
|
|
printf("C Converted Double Precision Whetstones: %.1f KIPS\n", KIPS);
|
2004-05-19 20:12:06 +00:00
|
|
|
#endif
|
2004-05-19 18:02:34 +00:00
|
|
|
|
2004-05-20 22:12:57 +00:00
|
|
|
// convert from thousands of instructions a second to instructions a second.
|
|
|
|
flops = KIPS*1000.0;
|
2008-05-05 00:51:20 +00:00
|
|
|
return 0;
|
2004-05-19 18:02:34 +00:00
|
|
|
}
|
2004-12-08 00:40:19 +00:00
|
|
|
|