From aa13912e3ec97705d47207003afb6845c6859bc8 Mon Sep 17 00:00:00 2001 From: Akshay Date: Wed, 13 Oct 2021 15:58:07 +0530 Subject: init --- src/1/main.c | 13 ++++++++++ src/2/main | Bin 0 -> 34312 bytes src/2/main.c | 82 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ src/2/table | 7 +++++ 4 files changed, 102 insertions(+) create mode 100644 src/1/main.c create mode 100755 src/2/main create mode 100644 src/2/main.c create mode 100644 src/2/table (limited to 'src') diff --git a/src/1/main.c b/src/1/main.c new file mode 100644 index 0000000..975c495 --- /dev/null +++ b/src/1/main.c @@ -0,0 +1,13 @@ +#include +#include + +int main() { + long long int total = 1, i; +#pragma omp parallel for reduction(*:total) + for(i = 1; i <= 20; i++) { + // printf("working in thread %d\n", omp_get_thread_num()); + total = total * i; + } + printf("total: %lld\n", total); +} + diff --git a/src/2/main b/src/2/main new file mode 100755 index 0000000..b999f77 Binary files /dev/null and b/src/2/main 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 @@ +#include +#include + +#include + +int main() { + int **a, **b, **c, l, m1, m2, n; + + printf("Order of matrix A: "); + int _ = scanf("%d %d", &l, &m1); + + printf("Order of matrix B: "); + _ = scanf("%d %d", &m2, &n); + + if (m1 != m2) { + printf("Invalid order\n"); + exit(1); + } + + int m = m1; + + a = (int **) calloc(l, sizeof(int *)); + for(int i = 0; i < m; i++) a[i] = (int *) calloc(m, sizeof(int)); + + b = (int **) calloc(m, sizeof(int *)); + for(int i = 0; i < n; i++) b[i] = (int *) calloc(n, sizeof(int)); + + c = (int **) calloc(l, sizeof(int *)); + for(int i = 0; i < n; i++) c[i] = (int *) calloc(n, sizeof(int)); + + + printf("L: %d, M: %d, N: %d\n", l, m, n); + + // input for A + // printf("Enter A:\n"); + for(int i = 0; i < l; i++) { + for(int j = 0; j < m; j++) { + // _ = scanf("%d", &a[i][j]); + a[i][j] = rand() % 500; + } + } + + // input for B + // printf("Enter B:\n"); + for(int i = 0; i < m; i++) { + for(int j = 0; j < n; j++) { + // _ = scanf("%d", &b[i][j]); + b[i][j] = rand() % 1000; + } + } + + // printf("\nA: \n"); + for(int i = 0; i < l; i++) { + for(int j = 0; j < m; j++) { + // printf("%d\t", a[i][j]); + } + // printf("\n"); + } + + // printf("\nB: \n"); + for(int i = 0; i < m; i++) { + for(int j = 0; j < n; j++) { + // printf("%d\t", b[i][j]); + } + // printf("\n"); + } + + double start_time = omp_get_wtime(); + int i, j, k; +#pragma omp parallel for private(j, k) num_threads(1) + for(i = 0; i < l; i++) { + for(j = 0; j < m; j++) { + c[i][j] = 0; + for(k = 0; k < n; k++) { + c[i][j] += a[i][k] * b[k][j]; + } + } + } + double end_time = omp_get_wtime(); + + printf(">>= Done in %f secs", end_time - start_time); +} 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 | 2 | 4 | 8 +-----|-----------|-----------|-----------|---------- + 100 | 0.000862 | 0.000813 | 0.000492 | 0.018057 + 250 | 0.016979 | 0.007088 | 0.008280 | 0.023153 + 500 | 0.187274 | 0.095052 | 0.083152 | 0.081629 +1000 | 2.522172 | 1.221258 | 1.139272 | 1.361240 +2000 | 47.200504 | 26.900284 | 19.395751 | 15.864646 -- cgit v1.2.3