-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix-multiplication-sequential.c
More file actions
46 lines (37 loc) · 1.02 KB
/
Copy pathmatrix-multiplication-sequential.c
File metadata and controls
46 lines (37 loc) · 1.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 500 // Matrix size
void multiply_matrices(int A[N][N], int B[N][N], int C[N][N]) {
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
C[i][j] = 0;
for (int k = 0; k < N; k++) {
C[i][j] += A[i][k] * B[k][j];
}
}
}
}
double get_execution_time() {
int A[N][N], B[N][N], C[N][N];
// Initialize matrices with random values
for (int i = 0; i < N; i++) {
for (int j = 0; j < N; j++) {
A[i][j] = rand() % 10;
B[i][j] = rand() % 10;
}
}
clock_t start = clock();
multiply_matrices(A, B, C);
clock_t end = clock();
return (double)(end - start) / CLOCKS_PER_SEC;
}
int main() {
double total_time = 0.0;
int runs = 10;
for (int i = 0; i < runs; i++) {
total_time += get_execution_time();
}
printf("Average Execution Time (Sequential): %.6f seconds\n", total_time / runs);
return 0;
}