Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
2.3 Comparision with Matrix Multiplication Execution Time
#include <stdio.h> #include <omp.h> #include <stdlib.h> #include <time.h> #import <math.h> int main(void) { int r=1000; int c=1000; printf("%d %d \n",r,c); // Taking Input for 2 arrays - int *arr1[r]; int *arr2[r]; for(int i=0;i<r;i++){ arr1[i]=(int *)malloc(c*sizeof(int)); } for(int i=0;i<r;i++){ arr2[i]=(int *)malloc(c*sizeof(int)); } for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ arr1[i][j]=rand(); } } for(int i=0;i<r;i++){ for(int j=0;j<c;j++){ arr2[i][j]=rand(); } } printf("\nSequential Time: \n"); int *arr3[r]; for(int i=0;i<r;i++){ arr3[i]=(int *)malloc(c*sizeof(int)); } double start=omp_get_wtime(); for (int i = 0; i < r; i++) { for (int j = 0; j < r; j++) { arr3[i][j] = 0; for (int k = 0; k < r; k++) arr3[i][j] += arr1[i][k] * arr2[k][j]; } } double end=omp_get_wtime(); printf("Execution Time : %f\n",end-start); // Starting parallel construct printf("\nParallel Time: \n"); int *arr4[r]; for(int i=0;i<r;i++){ arr4[i]=(int *)malloc(c*sizeof(int)); } int i=0; int j=0; int k=0; double start1=omp_get_wtime(); #pragma omp parallel for private(j,k) for (i = 0; i < r; i++) { for (j = 0; j < r; j++) { arr4[i][j] = 0; for (k = 0; k < r; k++) arr4[i][j] += arr1[i][k] * arr2[k][j]; } } double end1=omp_get_wtime(); printf("Execution Time : %f\n",end1-start1); for(int i=0;i<r;i++){ free(arr1[i]); free(arr2[i]); free(arr3[i]); free(arr4[i]); } return 0; }
run
|
edit
|
history
|
help
0
Adding sums of two 1-D arrays
recurs2
Bool datatype Operation for GCC
Spring 2017 Project 2 v1.2
Spring 2017 Project 2 v.02
First program.c
19_1_7
método de ordenamiento insertion sort
BSEARCH() COMPLETE
LECTURA DE CADENAS CON FGETS