Advertisement
Guest User

Untitled

a guest
Mar 29th, 2020
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #include <math.h>
  4.  
  5. int main(int argc, char *argv[]) {
  6.  
  7. //Determinar los valores de B y T
  8. //Tcom = B + T(Tamaño_Mensaje).
  9.  
  10. //B = mensaje sin datos. Enviar solo un byte con MPI_BYTE.
  11. //T = (tiempo_mensaje - B)/tamaño mensaje
  12.  
  13. //Variar: 256, 512, 1k, 2k, 4K...
  14.  
  15. MPI_Status status;
  16.  
  17. int myrank;
  18. int numproc;
  19.  
  20. MPI_Init(&argc,&argv);
  21. MPI_Comm_rank(MPI_COMM_WORLD,&myrank);
  22. MPI_Comm_size(MPI_COMM_WORLD,&numproc);
  23.  
  24. //Para MPI_Wtime()
  25. double start_time, end_time;
  26. double start_time2, end_time2;
  27. double B;
  28.  
  29. char msg = 'm';
  30.  
  31. //PARA CALCULAR LA LATENCIA B.
  32.  
  33. if (myrank == 0){
  34. //Iniciamos el tiempo
  35. start_time = MPI_Wtime();
  36. }
  37.  
  38. for (int i = 1; i <= 1000; ++i)
  39. {
  40. if (myrank == 0) {
  41. //Transmitir el mensaje
  42. MPI_Send(&msg, 1, MPI_BYTE, 1, 0, MPI_COMM_WORLD);
  43. //Recibimos el mensaje
  44. MPI_Recv(&msg, 1, MPI_BYTE, 1, 0, MPI_COMM_WORLD, &status);
  45.  
  46. }else {
  47.  
  48. //Recibimos el mensaje
  49. MPI_Recv(&msg, 1, MPI_BYTE, 0, 0, MPI_COMM_WORLD, &status);
  50. //Transmitir el mensaje
  51. MPI_Send(&msg, 1, MPI_BYTE, 0, 0, MPI_COMM_WORLD);
  52. }
  53. }
  54.  
  55. if (myrank == 0){
  56.  
  57. end_time = MPI_Wtime();
  58.  
  59. B = (end_time - start_time)/1000;
  60. B = (B/2) * pow(10,6);
  61. printf("Valor de B = %f \n",B);
  62. }
  63.  
  64. MPI_Finalize();
  65. return 0;
  66.  
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement