Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
18BCE2182 ASSESS_3 Q2
//gcc 7.4.0 #include <stdio.h> #include <stdlib.h> #include <time.h> #include <omp.h> int main(void) { int n=1024; int arr1[n][n]; int arr2[n][n]; int arr3[n][n]; int i, j; for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr1[i][j] = rand()%20; arr2[i][j] = rand()%20; } } double start = omp_get_wtime(); //serial matrix addition for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]+arr2[i][j]; } } double end = omp_get_wtime(); printf("\nAddition in Serial is %f",end-start); start = omp_get_wtime(); //serial matrix subtraction for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]-arr2[i][j]; } } end = omp_get_wtime(); printf("\nSubtraction in Serial is %f",end-start); //addition in parallel start=omp_get_wtime(); #pragma omp parallel for for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]+arr2[i][j]; } } end=omp_get_wtime(); printf("\nAddition in parallel is %f",end-start); //subtraction in parallel start=omp_get_wtime(); #pragma omp parallel for for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]-arr2[i][j]; } } end=omp_get_wtime(); printf("\nSubtraction in parallel is %f",end-start); //addition in parallel static start=omp_get_wtime(); #pragma omp parallel for schedule(static,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]+arr2[i][j]; } } end=omp_get_wtime(); printf("\nAddition in parallel schedule :static is %f",end-start); //subtraction in parallel static start=omp_get_wtime(); #pragma omp parallel for schedule(static,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]-arr2[i][j]; } } end=omp_get_wtime(); printf("\nSubtraction in parallel schedule :static is %f",end-start); //addition in parallel dynamic start=omp_get_wtime(); #pragma omp parallel for schedule(dynamic,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]+arr2[i][j]; } } end=omp_get_wtime(); printf("\nAddition in parallel schedule :dynamic is %f",end-start); //subtraction in parallel dynamic start=omp_get_wtime(); #pragma omp parallel for schedule(dynamic,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]-arr2[i][j]; } } end=omp_get_wtime(); printf("\nSubtraction in parallel schedule :dynamic is %f",end-start); //addition in parallel guided start=omp_get_wtime(); #pragma omp parallel for schedule(guided,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]+arr2[i][j]; } } end=omp_get_wtime(); printf("\nAddition in parallel schedule :guided is %f",end-start); //subtraction in parallel guided start=omp_get_wtime(); #pragma omp parallel for schedule(guided,16) for(i=0; i<n; i++) { for(j=0;j<n;j++) { arr3[i][j] = arr1[i][j]-arr2[i][j]; } } end=omp_get_wtime(); printf("\nSubtraction in parallel schedule :guided is %f",end-start); }
run
|
edit
|
history
|
help
0
16-bit signed or unsigned int -> ASCII
Simple interest
convertletter
Goodone pointer minus void pointer
Bitwise Operations
Address.c
BMI Calc CT
CremovePointFun
MatrixMul_shortxshort
Maze