Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.79 KB | None | 0 0
  1. - rangovi su uvijek slijedni brojevi i poËinju od 0, a zbog tog öto proces moûe imati razliËiti rang unutar komunikatora ne znamo koji od njih Êe dobiti neki od ta dva ranga
  2.  
  3. Zadatak 2:
  4.  
  5. /*
  6.  ============================================================================
  7.  Name       : petrovic_lv1.c
  8.  Author      : student
  9.  Version     :
  10.  Copyright   : Your copyright notice
  11.  Description : Compute Pi in MPI C++
  12.  ============================================================================
  13.  */
  14. #include <math.h>
  15. #include "mpi.h"
  16. #include <iostream>
  17.  
  18.  
  19. using namespace std;
  20. int main(int argc, char *argv[])
  21. {
  22.          int rank,size;
  23.             MPI::Init(argc, argv);
  24.             size = MPI::COMM_WORLD.Get_size();
  25.          rank = MPI::COMM_WORLD.Get_rank();
  26.          int struktura;
  27.          int rang=0;
  28.  
  29.  
  30.          if(rank == 0)
  31.          {
  32.             cout << "Odaberite  strukturu: " << endl;
  33.             cout << "Struktura 1 - svi procesi su jednaki " << endl;
  34.             cout << "Struktura2 - Master-worker " << endl;
  35.             cin >> struktura;
  36.         }
  37.         if(rank==0 && struktura==2)
  38.         {
  39.             cout << "Odaberite rang procesa za master: " << endl;
  40.             for(int i=0;i<size;i++)
  41.                 {
  42.                     cout << i << endl;
  43.                 }
  44.         cin >> rang;
  45.         }
  46.         if(rank==rang)
  47.         {
  48.             cout<<"Odabrana struktura je: "<<endl;
  49.  
  50.             if(struktura==1)
  51.             {
  52.                 cout << "1 - svi procesi su jednaki " << endl;
  53.             }
  54.             else if (struktura==2)
  55.             {
  56.                 cout << "2 - Master-worker " << endl;
  57.             }
  58.         }
  59.         cout << "P[" << rank <<"]([" <<"]): "<< "Pozdrav svijete!" << endl;
  60.         MPI::Finalize();
  61.         return 0; }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement