Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <mpi.h>
- #include <math.h>
- int main(int argc, char *argv[]) {
- //Determinar los valores de B y T
- //Tcom = B + T(Tamaño_Mensaje).
- //B = mensaje sin datos. Enviar solo un byte con MPI_BYTE.
- //T = (tiempo_mensaje - B)/tamaño mensaje
- //Variar: 256, 512, 1k, 2k, 4K...
- MPI_Status status;
- int myrank;
- int numproc;
- MPI_Init(&argc,&argv);
- MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
- MPI_Comm_size(MPI_COMM_WORLD,&numproc);
- //Para MPI_Wtime()
- double start_time, end_time;
- double start_time2, end_time2;
- double B;
- char msg = 'm';
- //PARA CALCULAR LA LATENCIA B.
- if (myrank == 0){
- //Iniciamos el tiempo
- start_time = MPI_Wtime();
- }
- for (int i = 1; i <= 1000; ++i)
- {
- if (myrank == 0) {
- //Transmitir el mensaje
- MPI_Send(&msg, 1, MPI_BYTE, 1, 0, MPI_COMM_WORLD);
- //Recibimos el mensaje
- MPI_Recv(&msg, 1, MPI_BYTE, 1, 0, MPI_COMM_WORLD, &status);
- }else {
- //Recibimos el mensaje
- MPI_Recv(&msg, 1, MPI_BYTE, 0, 0, MPI_COMM_WORLD, &status);
- //Transmitir el mensaje
- MPI_Send(&msg, 1, MPI_BYTE, 0, 0, MPI_COMM_WORLD);
- }
- }
- if (myrank == 0){
- end_time = MPI_Wtime();
- B = (end_time - start_time)/1000;
- B = (B/2) * pow(10,6);
- printf("Valor de B = %f \n",B);
- }
- MPI_Finalize();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement