diff options
Diffstat (limited to 'src/2')
-rwxr-xr-x | src/2/main | bin | 0 -> 34312 bytes | |||
-rw-r--r-- | src/2/main.c | 82 | ||||
-rw-r--r-- | src/2/table | 7 |
3 files changed, 89 insertions, 0 deletions
diff --git a/src/2/main b/src/2/main new file mode 100755 index 0000000..b999f77 --- /dev/null +++ b/src/2/main | |||
Binary files differ | |||
diff --git a/src/2/main.c b/src/2/main.c new file mode 100644 index 0000000..ee7f2c8 --- /dev/null +++ b/src/2/main.c | |||
@@ -0,0 +1,82 @@ | |||
1 | #include <stdio.h> | ||
2 | #include <stdlib.h> | ||
3 | |||
4 | #include <omp.h> | ||
5 | |||
6 | int main() { | ||
7 | int **a, **b, **c, l, m1, m2, n; | ||
8 | |||
9 | printf("Order of matrix A: "); | ||
10 | int _ = scanf("%d %d", &l, &m1); | ||
11 | |||
12 | printf("Order of matrix B: "); | ||
13 | _ = scanf("%d %d", &m2, &n); | ||
14 | |||
15 | if (m1 != m2) { | ||
16 | printf("Invalid order\n"); | ||
17 | exit(1); | ||
18 | } | ||
19 | |||
20 | int m = m1; | ||
21 | |||
22 | a = (int **) calloc(l, sizeof(int *)); | ||
23 | for(int i = 0; i < m; i++) a[i] = (int *) calloc(m, sizeof(int)); | ||
24 | |||
25 | b = (int **) calloc(m, sizeof(int *)); | ||
26 | for(int i = 0; i < n; i++) b[i] = (int *) calloc(n, sizeof(int)); | ||
27 | |||
28 | c = (int **) calloc(l, sizeof(int *)); | ||
29 | for(int i = 0; i < n; i++) c[i] = (int *) calloc(n, sizeof(int)); | ||
30 | |||
31 | |||
32 | printf("L: %d, M: %d, N: %d\n", l, m, n); | ||
33 | |||
34 | // input for A | ||
35 | // printf("Enter A:\n"); | ||
36 | for(int i = 0; i < l; i++) { | ||
37 | for(int j = 0; j < m; j++) { | ||
38 | // _ = scanf("%d", &a[i][j]); | ||
39 | a[i][j] = rand() % 500; | ||
40 | } | ||
41 | } | ||
42 | |||
43 | // input for B | ||
44 | // printf("Enter B:\n"); | ||
45 | for(int i = 0; i < m; i++) { | ||
46 | for(int j = 0; j < n; j++) { | ||
47 | // _ = scanf("%d", &b[i][j]); | ||
48 | b[i][j] = rand() % 1000; | ||
49 | } | ||
50 | } | ||
51 | |||
52 | // printf("\nA: \n"); | ||
53 | for(int i = 0; i < l; i++) { | ||
54 | for(int j = 0; j < m; j++) { | ||
55 | // printf("%d\t", a[i][j]); | ||
56 | } | ||
57 | // printf("\n"); | ||
58 | } | ||
59 | |||
60 | // printf("\nB: \n"); | ||
61 | for(int i = 0; i < m; i++) { | ||
62 | for(int j = 0; j < n; j++) { | ||
63 | // printf("%d\t", b[i][j]); | ||
64 | } | ||
65 | // printf("\n"); | ||
66 | } | ||
67 | |||
68 | double start_time = omp_get_wtime(); | ||
69 | int i, j, k; | ||
70 | #pragma omp parallel for private(j, k) num_threads(1) | ||
71 | for(i = 0; i < l; i++) { | ||
72 | for(j = 0; j < m; j++) { | ||
73 | c[i][j] = 0; | ||
74 | for(k = 0; k < n; k++) { | ||
75 | c[i][j] += a[i][k] * b[k][j]; | ||
76 | } | ||
77 | } | ||
78 | } | ||
79 | double end_time = omp_get_wtime(); | ||
80 | |||
81 | printf(">>= Done in %f secs", end_time - start_time); | ||
82 | } | ||
diff --git a/src/2/table b/src/2/table new file mode 100644 index 0000000..8e89bcc --- /dev/null +++ b/src/2/table | |||
@@ -0,0 +1,7 @@ | |||
1 | | 1 | 2 | 4 | 8 | ||
2 | -----|-----------|-----------|-----------|---------- | ||
3 | 100 | 0.000862 | 0.000813 | 0.000492 | 0.018057 | ||
4 | 250 | 0.016979 | 0.007088 | 0.008280 | 0.023153 | ||
5 | 500 | 0.187274 | 0.095052 | 0.083152 | 0.081629 | ||
6 | 1000 | 2.522172 | 1.221258 | 1.139272 | 1.361240 | ||
7 | 2000 | 47.200504 | 26.900284 | 19.395751 | 15.864646 | ||