home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Power-Programmierung
/
CD1.mdf
/
magazine
/
comp_lan
/
85_febr
/
benmrk.lbr
/
BENMRK.MAT
< prev
next >
Wrap
Text File
|
1988-07-25
|
2KB
|
88 lines
The Matrix Benchmark
C Compiler Analysis
February 1985 COMPUTER LANGUAGE
/*
** Matrix.c -- a benchmark based on the matrix multiplication
** program given by Jerry Pournelle in Byte October 1982 p. 254.
**
** Type conversions have been made explicit with casts. Array
** and loop indices now start at 0.
*/
#define M 20
#define N 20
#define BELL 7
char gup;
double summ, a[M][N], b[N][M], c[M][M];
main()
{
summ = 0.0;
printf("Hit any character to start\n");
gup = getchar();
filla();
printf("\nA filled\n");
fillb();
printf("\nB filled\n");
fillc();
printf("\nC filled\n");
matmult();
printf("\nMultiplied\n");
summit();
printf("The sum is: %20f\n", summ);
putchar(BELL);
}
filla()
{
int i, j;
for (i=0; i < M; i++)
for (j = 0; j < N; j++)
a[i][j] = (double) (i+1) + (j+1);
}
fillb()
{
int i, j;
for (i=0; i < N; i++)è for (j = 0; j < M; j++)
b[i][j] = (double) (int) (((i+1) + (j+1)) / (j+1));
}
fillc()
{
int i, j;
for (i=0; i < M; i++)
for (j = 0; j < M; j++)
c[i][j] = (double) 0;
}
matmult()
{
int i, j, k;
for (i = 0; i < M; i++)
for (j = 0; j < N; j++)
for (k = 0; k < M; k++)
c[i][j] = c[i][j] + a[i][k]*b[k][j];
}
summit()
{
int i, j;
for (i = 0; i < M; i++)
for (j = 0; j < M; j++)
summ = summ + c[i][j];
}