-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlcd
More file actions
33 lines (33 loc) · 806 Bytes
/
lcd
File metadata and controls
33 lines (33 loc) · 806 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// Loop-carried dependence using OpenMP
#include <stdio.h>
#include <omp.h>
#define N 10
int main() {
int A[N], B[N], C[N];
// Initialize arrays A and B
for (int i = 0; i < N; i++) {
A[i] = i + 1;
B[i] = (i + 1) * 2;
}
// Handling loop-carried dependence
C[0] = A[0] + B[0]; // First element is initialized separately
#pragma omp parallel
{
#pragma omp single
{
for (int i = 1; i < N; i++) {
#pragma omp task depend(in:C[i-1]) depend(out:C[i])
{
C[i] = A[i] + B[i] + C[i-1];
}
}
}
}
// Display the result
printf("Array C:\n");
for (int i = 0; i < N; i++) {
printf("%d ", C[i]);
}
printf("\n");
return 0;
}