filip710

rrs_lv1

Sep 10th, 2020
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. 1. ZADATAK
  2. b) Procesi A i C u komunikatoru MPI::Komunikator imaju rangove 0 i 1, ali ne možemo sa sigurnošću tvrditi koji od njih će dobiti neki od ta dva ranga.
  3.  
  4. Komunikator možemo razdijeliti funkcijom Split(int color, int key), gdje je color argument kojim se određuje kojem će se komunikatoru procesi dodijeliti. Key argument određuje rang unutar novih komunikatora, a proces koji proslijedi najmanju vrijednost biti će rang 0, sljedeći najmanji će biti rang 1 itd. Ako je su vrijednosti jednake, proces koji je imao najmanji rang u originalnom komunikatoru će biti prvi.
  5.  
  6. int rang = MPI::Komunikator.Get_rank();
  7.  
  8.  
  9.  
  10. 2. ZADATAK
  11.  
  12. #include <iostream>
  13. #include <mpi.h>
  14.  
  15. using namespace std;
  16.  
  17. int main (int argc, char* argv[]) {
  18. int rank, size, structure_choice = (int)argv[1], master_rank = (int)argv[2];
  19. MPI::Init(argc, argv);
  20. rank = MPI::COMM_WORLD.Get_rank();
  21. size = MPI::COMM_WORLD.Get_size();
  22.  
  23. if(structure_choice == 0) {
  24. if(rank == 0) {
  25. cout << "Svi procesi jednaki" << endl;
  26. }
  27. cout << "P["<< rank << "]([jednaki]): Pozdrav svijete!" <<endl;
  28. } else if (structure_choice == 1) {
  29. if(rank == master_rank) {
  30. cout << "Master-worker struktura " << "P["<< rank << "]([master]): Pozdrav svijete!" <<endl;
  31. } else {
  32. cout << "P["<< rank << "]([worker]): Pozdrav svijete!" <<endl;
  33. }
  34. }
  35. MPI::Finalize();
  36. return 0;
  37. }
Add Comment
Please, Sign In to add comment