-
Notifications
You must be signed in to change notification settings - Fork 0
/
pingpong.c
43 lines (32 loc) · 1.14 KB
/
pingpong.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
#include <stdio.h>
#include "mpi.h"
int main(int argc, char** argv)
{
int my_rank; /* Identificador do processo */
int proc_n; /* Número de processos */
int source; /* Identificador do proc.origem */
int dest; /* Identificador do proc. destino */
int tag = 50; /* Tag para as mensagens */
double t1,t2; /* time stamps */
int MSIZE;
int *message; /* message buffer */
MPI_Status status; /* Status de retorno */
MSIZE = atoi(argv[1]);
message = (int *)malloc(sizeof(int)*MSIZE);
MPI_Init (&argc , &argv);
MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
MPI_Comm_size(MPI_COMM_WORLD, &proc_n);
if (my_rank == 0) {
t1 = MPI_Wtime();
MPI_Send (message, MSIZE, MPI_INT, 1, tag, MPI_COMM_WORLD);
MPI_Recv (message, MSIZE, MPI_INT, 1, tag, MPI_COMM_WORLD, &status);
t2 = MPI_Wtime();
printf("\nRound trip(s): %f\n\n", t2-t1);
}
else {
MPI_Recv (message, MSIZE, MPI_INT, 0, tag, MPI_COMM_WORLD, &status);
MPI_Send (message, MSIZE, MPI_INT, 0, tag, MPI_COMM_WORLD);
}
MPI_Finalize();
return 0;
}