home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.dataforce.net
/
2014.05.ftp.dataforce.net.tar
/
ftp.dataforce.net
/
pub
/
solar
/
mflops.c
< prev
next >
Wrap
C/C++ Source or Header
|
1998-12-17
|
2KB
|
96 lines
/*
* Measure peak MFLOPS: no memory accesses, a lot of parallelism.
*/
#include <stdio.h>
#include <string.h>
#include <signal.h>
#include <setjmp.h>
#include <sys/time.h>
#define TIME 1
#define ITERATIONS 100
#define INCREASING 1
#define MIN -1e6
#define MAX 1e6
#define C0 -111.1
#define C1 22.2
#define C2 33.3
#define C3 44.4
#define C4 155.5
#define f(x, y) \
{ \
double x2; \
x2 = x * x; \
y = C0 + C1 * x + C2 * x2 + C3 * x * x2 + C4 * x2 * x2; \
}
#define F(x, y) \
{ \
double u1, u2, u3, u4, u5; \
double v1, v2, v3, v4, v5; \
u1 = x * 0.123 + 0.678; \
u2 = x * 0.234 + 0.567; \
u3 = x * 0.345 + 0.456; \
u4 = x * 0.456 + 0.345; \
u5 = x * 0.567 + 0.234; \
f(x, y); \
f(u1, v1); \
f(u2, v2); \
f(u3, v3); \
f(u4, v4); \
f(u5, v5); \
y += v1 + v2 + v3 + v4 + v5; \
}
#define FLOPS \
(ITERATIONS * (11 + (11 + 3) * (6 - 1) + 2))
jmp_buf there;
void handler()
{
longjmp(there, 1);
}
int main()
{
struct itimerval tv;
volatile int count;
volatile double x, y;
double a, b, c, fc;
int i;
count = 0;
if (setjmp(there)) {
printf("%.2f MFLOPS (x=%e y=%e)\n",
(double)count * FLOPS / TIME / 1e6, x, y);
return 0;
}
signal(SIGVTALRM, handler);
memset(&tv, 0, sizeof(tv));
tv.it_value.tv_sec = TIME;
setitimer(ITIMER_VIRTUAL, &tv, NULL);
while (1) {
a = MIN; b = MAX;
i = ITERATIONS;
do {
c = (a + b) * 0.5;
F(c, fc);
#if INCREASING
if (fc > 0) b = c; else a = c;
#else
if (fc < 0) b = c; else a = c;
#endif
} while (--i);
x = c; y = fc;
count++;
};
}