Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
18BCE2182 ASSESS_1 Q2-3
#include <stdio.h> #include <stdlib.h> #include <omp.h> #define M 5 #define N 5 int main(int argc, char *argv) { omp_set_num_threads(8); int i,j,k; double sum; double start, end, start_p, end_p; double **A, **B, **C; A= malloc(M*sizeof(double *)); B= malloc(M*sizeof(double *)); C= malloc(M*sizeof(double *)); for(i=0; i<M; i++) { A[i]= malloc(N*sizeof(double)); B[i]= malloc(N*sizeof(double)); C[i]= malloc(N*sizeof(double)); } for(i=0; i<M; i++) { for(j=0; j<N; j++) { A[i][j]=j*1; B[i][j]=i*j+2; C[i][j]=j-i*2; } } printf("MATRIX A:\n"); for(i=0; i<M; i++) { for(j=0; j<N; j++) { printf("%f ",A[i][j]); } printf("\n"); } printf("\n"); printf("MATRIX B:\n"); for(i=0; i<M; i++) { for(j=0; j<N; j++) { printf("%f ",B[i][j]); } printf("\n"); } printf("\n"); start= omp_get_wtime(); for(i=0; i<M; i++) { for(j=0; j<N; j++) { sum=0; for(k=0; k<M; k++) { sum+=A[i][k]*B[k][j]; } C[i][j]=sum; } } end= omp_get_wtime(); printf("Serial Execution Time: %f\n\n",(end-start)); ////////////////////////////////// start_p= omp_get_wtime(); #pragma omp parallel for for(i=0; i<M; i++) { for(j=0; j<N; j++) { sum=0; for(k=0; k<M; k++) { sum+=A[i][k]*B[k][j]; } C[i][j]=sum; } } end_p= omp_get_wtime(); printf("Parallel Execution Time: %f\n\n",(end_p-start_p)); printf("MATRIX MULTIPLICATION, MATRIX C:\n"); for(i=0; i<M; i++) { for(j=0; j<N; j++) { printf("%f ",C[i][j]); } printf("\n"); } return 0; }
run
|
edit
|
history
|
help
0
Singly LinkedList.c
c program for hollow rhombus
Matrices de cadenas con *punteros
Witout goto
alphabet2 pyramid right
Example array of struct print
A_141211_FuncionesVarias
18BCE2182 LAB FAT-2-A-ii
ternar
apel