Advertisement
ZvezdaNasilnica

Untitled

Dec 6th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. #include <math.h>
  2. #include "mpi.h"
  3. #include <iostream>
  4. using namespace std;
  5.  
  6. int main(int argc, char *argv[]) {
  7. int n, rank, size, i;
  8. double a[10];
  9.  
  10.  
  11. MPI::Init(argc, argv);
  12. size = MPI::COMM_WORLD.Get_size();
  13. rank = MPI::COMM_WORLD.Get_rank();
  14.  
  15. MPI::Status status;
  16. MPI::Request zahtjev;
  17.  
  18.  
  19. if (rank == 0)
  20. {
  21. for (i=0; i<10; i++)
  22. {
  23. a[i]=sqrt(i);
  24. }
  25.  
  26. MPI::COMM_WORLD.Send(a, 10, MPI::DOUBLE, 1, 17);
  27. MPI::COMM_WORLD.Recv(a,10, MPI::DOUBLE, 2, 17,status);
  28.  
  29. cout << rank << ":poruka " << status.Get_tag()<< endl;
  30. cout << rank << ":je stigla od ranga " << status.Get_source() << endl;
  31. }
  32. else if(rank == 1)
  33. {
  34. MPI::COMM_WORLD.Recv(a,10, MPI::DOUBLE, 0, 17, status);
  35. MPI::COMM_WORLD.Send(a, 10, MPI::DOUBLE, 2, 17);
  36.  
  37. cout << rank << ":poruka " << status.Get_tag()<< endl;
  38. cout << rank << ":je stigla od ranga " << status.Get_source() << endl;
  39. }
  40. else
  41. {
  42.  
  43. MPI::COMM_WORLD.Send(a, 10, MPI::DOUBLE, 0, 17);
  44. MPI::COMM_WORLD.Recv(a, 10, MPI::DOUBLE, 1, 17, status);
  45.  
  46. cout << rank << ":poruka " << status.Get_tag()<< endl;
  47. cout << rank << ":je stigla od ranga " << status.Get_source() << endl;
  48. }
  49.  
  50. MPI::Finalize();
  51. return 0;
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement