Advertisement
VladSmirN

Untitled

Apr 5th, 2023
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. #include <iostream>
  2. #include "mpi.h"
  3.  
  4. using namespace std;
  5.  
  6. int main(int argc, char** argv)
  7. {
  8.  
  9. MPI_Init(&argc, &argv);
  10.  
  11. int size, rank;
  12.  
  13. MPI_Status status;
  14.  
  15. MPI_Comm_size(MPI_COMM_WORLD, &size);
  16. MPI_Comm_rank(MPI_COMM_WORLD, &rank);
  17.  
  18. printf("i'm %d \n", rank);
  19.  
  20. int* sendarray = new int[2];
  21. int* rbuf = new int[size * 2];
  22. int* displs = new int[size];
  23. int* rcounts = new int[size];
  24. int i;
  25. for (i = 0; i < size - 1; ++i) {
  26. displs[i] = i + i;
  27. rcounts[i] = 1;
  28. }
  29. i = size - 1;
  30. displs[i] = i + i;
  31. rcounts[i] = 2;
  32. sendarray[0] = rank + 1;
  33. sendarray[1] = rank + 2;
  34. if (rank != size - 1) printf("otpravl: %d", sendarray[0]);
  35. else printf("otpravl: %d %d", sendarray[0], sendarray[1]);
  36. double start_Send = MPI_Wtime();
  37. MPI_Gatherv(sendarray, rcounts[rank], MPI_INT, rbuf, rcounts, displs,
  38. MPI_INT, 0, MPI_COMM_WORLD);
  39. double end_Send = MPI_Wtime();
  40.  
  41. if (rank == 0) {
  42. printf(" rezult:");
  43. for (int i = 0; i < size * 2; ++i) {
  44. if (rbuf[i] > 0)
  45. printf("%d", rbuf[i]);
  46. else printf("0");
  47. }
  48. printf(" vremya work %g", (end_Send - start_Send));
  49. }
  50.  
  51. MPI_Finalize();
  52. return 0;
  53. }
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement