-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathejercicio7.c
More file actions
48 lines (40 loc) · 1019 Bytes
/
ejercicio7.c
File metadata and controls
48 lines (40 loc) · 1019 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <mpi.h>
int main() {
int comm_sz, i, my_rank;
MPI_Init(NULL, NULL);
MPI_Comm_size(MPI_COMM_WORLD, &comm_sz);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
int buffer = 0;
if(comm_sz != 2)
{
MPI_Finalize();
return 0;
}
if(my_rank == 0)
{
for(i=0 ; i<10 ; i++)
{
MPI_Send(&buffer, 1, MPI_INT, 1, 0, MPI_COMM_WORLD);
printf("Sent to process 1 - value =%d \n", buffer);
buffer++;
MPI_Recv(&buffer, 1, MPI_INT, 1, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received from process 1 - value = %d \n", buffer);
}
}
else
{
for(i=0 ; i<10 ; i++)
{
MPI_Recv(&buffer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
printf("Received from process 0 - value = %d \n", buffer);
buffer++;
MPI_Send(&buffer, 1, MPI_INT, 0, 0, MPI_COMM_WORLD);
printf("Sent to process 0 - value = %d \n", buffer);
}
}
MPI_Finalize();
return 0;
}