Skip to content

Commit 05f6eaf

Browse files
committed
Modify whole repository
1 parent 963a7e7 commit 05f6eaf

File tree

36 files changed

+7827
-0
lines changed

36 files changed

+7827
-0
lines changed

Code Test/Dell XPS8900/Testing on Intel Core i7 CPU/Test 1/fox_floats_timer_caching_omp_fileIO_benchmark.c

Lines changed: 1137 additions & 0 deletions
Large diffs are not rendered by default.

Code Test/Dell XPS8900/Testing on Intel Core i7 CPU/Test 1/fox_floats_timer_caching_omp_fileIO_benchmark.c~

Lines changed: 1137 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/* Program name: serial_matrix_multiplication_benchmark.c
2+
* benchmark serial matrix multiplication with timer
3+
*
4+
*/
5+
6+
/* Compiler command:
7+
* icc -O3 -xCORE-AVX2 -qopt-report-phase=vec -qopt-report=3 serial_matrix_multiplication_benchmark.c -o serial_matrix_multiplication_benchmark
8+
*
9+
* Run command:
10+
* ./serial_matrix_multiplication_benchmark
11+
*/
12+
13+
/* Head files */
14+
#include <stdio.h>
15+
#include <math.h>
16+
#include <stdlib.h>
17+
#include <sys/time.h>
18+
19+
20+
// define problem scale, matrix row/col size
21+
#define PROBLEM_SCALE 64
22+
23+
// define float precision, 4 byte single-precision float or 8 byte double-precision float
24+
#define FLOAT double
25+
26+
// define macro for array access
27+
#define Entry(A,i,j) (*(A + (n*(i) + (j)))) // defination with parameters, Array dereference
28+
29+
30+
// dtime
31+
//
32+
// utility routine to return
33+
// the current wall clock time
34+
//
35+
double dtime()
36+
{
37+
double tseconds = 0.0;
38+
struct timeval mytime;
39+
gettimeofday(&mytime, (struct timezone*)0);
40+
tseconds = (double)(mytime.tv_sec + mytime.tv_usec*1.0e-6);
41+
return( tseconds );
42+
}
43+
44+
45+
/*********************************************************/
46+
int main(int argc, char* argv[]) {
47+
FILE *fp;
48+
49+
int i;
50+
int j;
51+
int k;
52+
53+
int n;
54+
int content;
55+
56+
FLOAT *matrix_A;
57+
FLOAT *matrix_B;
58+
FLOAT *matrix_C;
59+
60+
double tstart;
61+
double tend;
62+
63+
64+
// Matrix Generator
65+
printf("Generate and write matrix A\n");
66+
fp = fopen("A.dat", "w"); // Generate and print matrix A into a file
67+
for (i = 0; i < PROBLEM_SCALE; i++) {
68+
for (j = 0; j < PROBLEM_SCALE; j++)
69+
if(i == j){
70+
fprintf(fp,"%d ",1);
71+
}
72+
else {
73+
fprintf(fp,"%d ",0);
74+
}
75+
76+
fprintf(fp,"\n");
77+
}
78+
fclose(fp);
79+
80+
printf("Generate and write matrix B\n");
81+
fp = fopen("B.dat", "w"); // Generate and print matrix B into a file
82+
for (i = 0; i < PROBLEM_SCALE; i++){
83+
for (j = 0; j < PROBLEM_SCALE; j++)
84+
fprintf(fp,"%d ", (i*PROBLEM_SCALE)+j);
85+
86+
fprintf(fp, "\n");
87+
}
88+
fclose(fp);
89+
90+
91+
// Allocate memory and Read Matrices from files
92+
fp = fopen("A.dat","r");
93+
n = 0;
94+
while((content = fgetc(fp)) != EOF)
95+
{
96+
//printf("fgetc = %c\n", (char)content);
97+
if(content != 0x20 && content != 0x0A) n++;
98+
}
99+
fclose(fp);
100+
// printf("We read the order of the matrices from A.dat is\n %d\n", n);
101+
n = (int) sqrt((double) n);
102+
printf("We read the order of the matrices from A.dat is\n %d\n", n);
103+
104+
matrix_A = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix A
105+
matrix_B = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix B
106+
matrix_C = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix C
107+
108+
printf("Read matrix A\n");
109+
fp = fopen("A.dat", "r"); // Read Matrix A from a file
110+
for (i = 0; i < n; i++) {
111+
for (j = 0; j < n; j++)
112+
fscanf(fp, "%lf", (matrix_A + (i*n) + j));
113+
}
114+
fclose(fp);
115+
116+
printf("Read matrix B\n");
117+
fp = fopen("B.dat", "r"); // Read matrix B from a file
118+
for (i = 0; i < n; i++){
119+
for (j = 0; j < n; j++)
120+
fscanf(fp, "%lf", (matrix_B + (i*n) + j));
121+
}
122+
fclose(fp);
123+
124+
125+
/******************************************************/
126+
// Serial Matrix Multiply with timer
127+
/******************************************************/
128+
for (i = 0; i < n; i++)
129+
for (j = 0; j < n; j++)
130+
Entry(matrix_C,i,j) = 0.0;
131+
132+
printf("Start C = A*B\n");
133+
tstart = dtime();
134+
for (i = 0; i < n; i++)
135+
for (j = 0; j < n; j++)
136+
for (k = 0; k < n; k++)
137+
Entry(matrix_C,i,j) = Entry(matrix_C,i,j)
138+
+ Entry(matrix_A,i,k)*Entry(matrix_B,k,j);
139+
tend = dtime();
140+
printf("C = A*B finished\n");
141+
142+
// print timer result in the command line
143+
printf("Serial Matrix Multiplication Elapsed time:\n %30.20E seconds\n", tend-tstart);
144+
145+
146+
// Writing result to a file
147+
printf("Write result C = A*B to a file C.dat\n");
148+
fp = fopen("C.dat", "w"); // Read matrix B from a file
149+
for (i = 0; i < PROBLEM_SCALE; i++){
150+
for (j = 0; j < PROBLEM_SCALE; j++)
151+
fprintf(fp,"%lf ", Entry(matrix_C,i,j));
152+
153+
fprintf(fp, "\n");
154+
}
155+
fclose(fp);
156+
157+
158+
return 0;
159+
}
Lines changed: 159 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,159 @@
1+
/* Program name: serial_matrix_multiplication_benchmark.c
2+
* benchmark serial matrix multiplication with timer
3+
*
4+
*/
5+
6+
/* Compiler command:
7+
* icc -O3 -xCORE-AVX2 -qopt-report-phase=vec -qopt-report=3 serial_matrix_multiplication_benchmark.c -o serial_matrix_multiplication_benchmark
8+
*
9+
* Run command:
10+
* ./serial_matrix_multiplication_benchmark
11+
*/
12+
13+
/* Head files */
14+
#include <stdio.h>
15+
#include <math.h>
16+
#include <stdlib.h>
17+
#include <sys/time.h>
18+
19+
20+
// define problem scale, matrix row/col size
21+
#define PROBLEM_SCALE 64
22+
23+
// define float precision, 4 byte single-precision float or 8 byte double-precision float
24+
#define FLOAT double
25+
26+
// define macro for array access
27+
#define Entry(A,i,j) (*(A + (n*(i) + (j)))) // defination with parameters, Array dereference
28+
29+
30+
// dtime
31+
//
32+
// utility routine to return
33+
// the current wall clock time
34+
//
35+
double dtime()
36+
{
37+
double tseconds = 0.0;
38+
struct timeval mytime;
39+
gettimeofday(&mytime, (struct timezone*)0);
40+
tseconds = (double)(mytime.tv_sec + mytime.tv_usec*1.0e-6);
41+
return( tseconds );
42+
}
43+
44+
45+
/*********************************************************/
46+
int main(int argc, char* argv[]) {
47+
FILE *fp;
48+
49+
int i;
50+
int j;
51+
int k;
52+
53+
int n;
54+
int content;
55+
56+
FLOAT *matrix_A;
57+
FLOAT *matrix_B;
58+
FLOAT *matrix_C;
59+
60+
double tstart;
61+
double tend;
62+
63+
64+
// Matrix Generator
65+
printf("Generate and write matrix A\n");
66+
fp = fopen("A.dat", "w"); // Generate and print matrix A into a file
67+
for (i = 0; i < PROBLEM_SCALE; i++) {
68+
for (j = 0; j < PROBLEM_SCALE; j++)
69+
if(i == j){
70+
fprintf(fp,"%d ",1);
71+
}
72+
else {
73+
fprintf(fp,"%d ",0);
74+
}
75+
76+
fprintf(fp,"\n");
77+
}
78+
fclose(fp);
79+
80+
printf("Generate and write matrix B\n");
81+
fp = fopen("B.dat", "w"); // Generate and print matrix B into a file
82+
for (i = 0; i < PROBLEM_SCALE; i++){
83+
for (j = 0; j < PROBLEM_SCALE; j++)
84+
fprintf(fp,"%d ", (i*PROBLEM_SCALE)+j);
85+
86+
fprintf(fp, "\n");
87+
}
88+
fclose(fp);
89+
90+
91+
// Allocate memory and Read Matrices from files
92+
fp = fopen("A.dat","r");
93+
n = 0;
94+
while((content = fgetc(fp)) != EOF)
95+
{
96+
//printf("fgetc = %c\n", (char)content);
97+
if(content != 0x20 && content != 0x0A) n++;
98+
}
99+
fclose(fp);
100+
// printf("We read the order of the matrices from A.dat is\n %d\n", n);
101+
n = (int) sqrt((double) n);
102+
printf("We read the order of the matrices from A.dat is\n %d\n", n);
103+
104+
matrix_A = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix A
105+
matrix_B = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix B
106+
matrix_C = (FLOAT*) malloc((n*n) * sizeof(FLOAT)); // Allocate memory for matrix C
107+
108+
printf("Read matrix A\n");
109+
fp = fopen("A.dat", "r"); // Read Matrix A from a file
110+
for (i = 0; i < n; i++) {
111+
for (j = 0; j < n; j++)
112+
fscanf(fp, "%lf", (matrix_A + (i*n) + j));
113+
}
114+
fclose(fp);
115+
116+
printf("Read matrix B\n");
117+
fp = fopen("B.dat", "r"); // Read matrix B from a file
118+
for (i = 0; i < n; i++){
119+
for (j = 0; j < n; j++)
120+
fscanf(fp, "%lf", (matrix_B + (i*n) + j));
121+
}
122+
fclose(fp);
123+
124+
125+
/******************************************************/
126+
// Serial Matrix Multiply with timer
127+
/******************************************************/
128+
for (i = 0; i < n; i++)
129+
for (j = 0; j < n; j++)
130+
Entry(matrix_C,i,j) = 0.0;
131+
132+
printf("Start C = A*B\n");
133+
tstart = dtime();
134+
for (i = 0; i < n; i++)
135+
for (j = 0; j < n; j++)
136+
for (k = 0; k < n; k++)
137+
Entry(matrix_C,i,j) = Entry(matrix_C,i,j)
138+
+ Entry(matrix_A,i,k)*Entry(matrix_B,k,j);
139+
tend = dtime();
140+
printf("C = A*B finished\n");
141+
142+
// print timer result in the command line
143+
printf("Serial Matrix Multiplication Elapsed time:\n %30.20E seconds\n", tend-tstart);
144+
145+
146+
// Writing result to a file
147+
printf("Write result C = A*B to a file C.dat\n");
148+
fp = fopen("C.dat", "w"); // Read matrix B from a file
149+
for (i = 0; i < PROBLEM_SCALE; i++){
150+
for (j = 0; j < PROBLEM_SCALE; j++)
151+
fprintf(fp,"%lf ", Entry(matrix_C,i,j));
152+
153+
fprintf(fp, "\n");
154+
}
155+
fclose(fp);
156+
157+
158+
return 0;
159+
}

0 commit comments

Comments
 (0)