Guest User

Untitled

a guest
Jul 18th, 2018
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <mpi.h>
  3. #include <stdlib.h>
  4. #include <string.h>
  5.  
  6. #define N 100
  7. #define M 100000
  8.  
  9. main(int argc, char **argv)
  10. {
  11. int my_rank;
  12. int p;
  13. int source;
  14. int dest;
  15. int tag=50;
  16. char message[100];
  17. MPI_Status status;
  18.  
  19. MPI_Init(&argc, &argv);
  20. MPI_Comm_rank(MPI_COMM_WORLD, &my_rank);
  21. MPI_Comm_size(MPI_COMM_WORLD, &p);
  22.  
  23.  
  24. double t1, t2;
  25.  
  26.  
  27. float tab[N];
  28. float tab2[M];
  29. int i;
  30. int j;
  31.  
  32. for(i=0; i<N; i++)
  33. {
  34. tab[i]=i;
  35. }
  36.  
  37. for(j=0; j<M; j++)
  38. {
  39. tab2[j]=j;
  40. }
  41.  
  42.  
  43. for (i=0; i<4; i++)
  44. {
  45.  
  46.  
  47.  
  48.  
  49. if (my_rank == 0)
  50. {
  51. //source = 1;
  52. //dest = 1;
  53.  
  54. t1=MPI_Wtime();
  55.  
  56. MPI_Gather(tab, N, MPI_FLOAT, tab2, M, MPI_FLOAT, 0, MPI_COMM_WORLD);
  57.  
  58.  
  59.  
  60. //MPI_Send(tab, N, MPI_FLOAT, dest, tag, MPI_COMM_WORLD);
  61. //MPI_Recv(tab, N, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
  62.  
  63. t2=MPI_Wtime();
  64.  
  65. printf("Czas = %f\n", t2-t1);
  66.  
  67.  
  68. }
  69.  
  70.  
  71. else
  72. {
  73. //source = 0;
  74. //dest = 0;
  75.  
  76. //sprintf(message, "Hello from process %d.", my_rank);
  77.  
  78. MPI_Gather(tab, N, MPI_FLOAT, tab2, M, MPI_FLOAT, 0, MPI_COMM_WORLD);
  79.  
  80. //MPI_Recv(tab, N, MPI_FLOAT, source, tag, MPI_COMM_WORLD, &status);
  81. //MPI_Send(tab, N, MPI_FLOAT, dest, tag, MPI_COMM_WORLD);
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88. }
  89.  
  90.  
  91.  
  92. }
  93. MPI_Finalize();
  94. }
Add Comment
Please, Sign In to add comment