Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
18BCE2182 ASSESS_2 Q4
//gcc 7.4.0 #include <stdio.h> #include <stdlib.h> #include <omp.h> int main(void) { int n, i, big, small, fac, j, k,l; int a[n]; double start, end, start1, end1, start2, end2, start3, end3, start4, end4; n=5; big=0; small=0; fac=1; j=-1; k=1; l=0; for(i=0; i<n; i++) { a[i]=rand(); } start=omp_get_wtime(); #pragma omp parallel #pragma omp sections { #pragma omp section { start1=omp_get_wtime(); for(i=0; i<n; i++) { if(big<a[i]) { big=a[i]; } } end1=omp_get_wtime(); printf("Biggest of n numbers: %d\n",big); printf("Serial Execution Time for above: %f\n", (end1-start1) ); } #pragma omp section { start2=omp_get_wtime(); for(i=0; i<n; i++) { if(small>a[i]) { small=a[i]; } } end2=omp_get_wtime(); printf("Smallest of n numbers: %d\n",small); printf("Serial Execution Time for above: %f\n", (end2-start2) ); } #pragma omp section { start3=omp_get_wtime(); for(i=1; i<=n; i++) { fac=fac*a[i]; } end3=omp_get_wtime(); printf("Factorial of n numbers: %d\n",fac); printf("Serial Execution Time for above: %f\n", (end3-start3) ); } #pragma omp section { start4=omp_get_wtime(); for(i=0; i<n; i++) { l=j+k; printf("%d,",l); j=k; k=l; } end4=omp_get_wtime(); printf("\n"); printf("Serial Execution Time for above: %f\n", (end4-start4) ); } } end=omp_get_wtime(); printf("Parallel Execution Time : %f", (end-start) ); return 0; }
run
|
edit
|
history
|
help
0
A.c
macaddress
MergeSort
TAREA M4 - LOTERIA
holiwis
-Wall
final advice
C_141113_Primos02
Float data type.c
20171117_TARTAGLIA