Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
3.1.2 Matrix add/sub file concept
#include <stdio.h> #include <stdlib.h> #include <omp.h> int main() { int n; printf("\nDhananjay, 19BCE0599 \nenter value of n: \t"); scanf("%d", &n); int arr1[n][n]; int ans[n][n]; for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { arr1[i][j] = rand() % 10; } } double start = omp_get_wtime(); for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] + arr1[i][j]; double end = omp_get_wtime(); printf("serial addition of matrix: %lf \n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(static, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] + arr1[i][j]; end = omp_get_wtime(); printf("time addition of matrix using static modifier and chunk_size 16: %lf \n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(dynamic, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] + arr1[i][j]; end = omp_get_wtime(); printf("time addition of matrix using dynamic modifier and chunk_size 16: %lf\n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(guided, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] + arr1[i][j]; end = omp_get_wtime(); printf("time addition of matrix using guided modifier and chunk_size 16: %lf\n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(static, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] - arr1[i][j]; end = omp_get_wtime(); printf("time substraction of matrix using static modifier and chunk_size 16: %lf\n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(dynamic, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] - arr1[i][j]; end = omp_get_wtime(); printf("time substraction of matrix using dynamic modifier and chunk_size 16: %lf\n", end - start); start = omp_get_wtime(); #pragma omp parallel for schedule(guided, 16) for (int i = 0; i < n; i++) for (int j = 0; j < n; j++) ans[i][j] = arr1[i][j] - arr1[i][j]; end = omp_get_wtime(); printf("time substraction of matrix using guided modifier and chunk_size 16: %lf\n", end - start); return 0; }
run
|
edit
|
history
|
help
0
tst2.c
Binary example
project menu
18BCE2182 ASSESS_1 Q1-6
bitwise operations
Bitwise Operations
19BCE0666.C
141124_PI
20171127_ARRAY_PRIMOS
union behaviour when const obj created