Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
18BCE2182 MIDTERM PART-B ATOMIC
#include <omp.h> #include <stdio.h> #include <stdlib.h> #include <limits.h> #include <time.h> #define N 50 int main() { srand(time(NULL)); int arr[N]; for (int i = 0; i < N; i++) { arr[i] = (rand() - (RAND_MAX / 2)) % N; printf("%d ", arr[i]); } printf("\n"); int x = arr[rand() % N]; int cnt = 0; int max = INT_MIN; int min = INT_MAX; #pragma omp parallel for for (int i = 0; i < N; i++) { if (arr[i] > max) { #pragma omp critical (max_critical) { if (arr[i] > max) max = arr[i]; } } else { #pragma omp critical (min_critical) { if (arr[i] < min) min = arr[i]; } } if (arr[i] > x) { # pragma omp atomic cnt++; } } printf("max = %d\n", max); printf("min = %d\n", min); printf("Number of elements greater than %d = %d", x, cnt); return 0; }
run
|
edit
|
history
|
help
0
X=1
Finite State Machine Program Example (ECE 2534)
linux (mostly) true random number generator
prime numbers min>max
ytre
C_14119_Media
Factorial_LOOP
MatrixMul_shortxshort
a1
some_tests