-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtmp.c
More file actions
55 lines (44 loc) · 1.18 KB
/
tmp.c
File metadata and controls
55 lines (44 loc) · 1.18 KB
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#define _XOPEN_SOURCE 600
#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
pthread_barrier_t barrier;
int A[2][2] = {2, 1, 5, 7};
int b[] = {11, 12};
int x[2] = {1, 1};
void *Jacobi(void *threadid);
int main() {
int n;
scanf("%d", &n);
pthread_t threads[n];
int *ids[n];
pthread_barrier_init(&barrier, NULL, n);
for(int i = 0; i < n; i++) {
ids[i] = (int *) malloc(sizeof(int));
*ids[i] = i;
pthread_create(&threads[i], NULL, Jacobi, (void *) ids[i]);
}
for(int i = 0; i < n; i++) {
pthread_join(threads[i], NULL);
}
pthread_barrier_destroy(&barrier);
pthread_exit(NULL);
}
void *Jacobi(void *threadid) {
int k = 0;
while(k < 10) {
for(int i = 0; i < 2; i++) {
int sum;
for(int j = 1; j < 3; j++) {
if(j != i) {
sum = A[i][j] * x[j];
}
}
printf("%d\n")
x[i] = (1/A[i][i]) * (b[i] - sum); //x[i] no tempo k+1
printf("No tempo %d, Thread %d calculou que x[%d] = %d\n", k+1, *((int *)threadid), i, x[i]);
}
pthread_barrier_wait(&barrier);
k++;
}
}