-
Notifications
You must be signed in to change notification settings - Fork 32
/
Copy pathrvet.c
80 lines (59 loc) · 1.49 KB
/
rvet.c
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/**
* Código base (incompleto) para implementação de relógios vetoriais.
* Meta: implementar a interação entre três processos ilustrada na figura
* da URL:
*
* https://people.cs.rutgers.edu/~pxk/417/notes/images/clocks-vector.png
*
* Compilação: mpicc -o rvet rvet.c
* Execução: mpiexec -n 3 ./rvet
*/
#include <stdio.h>
#include <string.h>
#include <mpi.h>
typedef struct Clock {
int p[3];
} Clock;
void Event(int pid, Clock *clock){
clock->p[pid]++;
}
void Send(int pid, Clock *clock){
// TO DO
}
void Receive(int pid, Clock *clock){
// TO DO
}
// Representa o processo de rank 0
void process0(){
Clock clock = {{0,0,0}};
Event(0, &clock);
printf("Process: %d, Clock: (%d, %d, %d)\n", 0, clock.p[0], clock.p[1], clock.p[2]);
// TO DO
}
// Representa o processo de rank 1
void process1(){
Clock clock = {{0,0,0}};
printf("Process: %d, Clock: (%d, %d, %d)\n", 1, clock.p[0], clock.p[1], clock.p[2]);
// TO DO
}
// Representa o processo de rank 2
void process2(){
Clock clock = {{0,0,0}};
printf("Process: %d, Clock: (%d, %d, %d)\n", 2, clock.p[0], clock.p[1], clock.p[2]);
// TO DO
}
int main(void) {
int my_rank;
MPI_Init(NULL, NULL);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
if (my_rank == 0) {
process0();
} else if (my_rank == 1) {
process1();
} else if (my_rank == 2) {
process2();
}
/* Finaliza MPI */
MPI_Finalize();
return 0;
} /* main */