Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. ZADATAK
- 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.
- 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.
- int rang = MPI::Komunikator.Get_rank();
- 2. ZADATAK
- #include <iostream>
- #include <mpi.h>
- using namespace std;
- int main (int argc, char* argv[]) {
- int rank, size, structure_choice = (int)argv[1], master_rank = (int)argv[2];
- MPI::Init(argc, argv);
- rank = MPI::COMM_WORLD.Get_rank();
- size = MPI::COMM_WORLD.Get_size();
- if(structure_choice == 0) {
- if(rank == 0) {
- cout << "Svi procesi jednaki" << endl;
- }
- cout << "P["<< rank << "]([jednaki]): Pozdrav svijete!" <<endl;
- } else if (structure_choice == 1) {
- if(rank == master_rank) {
- cout << "Master-worker struktura " << "P["<< rank << "]([master]): Pozdrav svijete!" <<endl;
- } else {
- cout << "P["<< rank << "]([worker]): Pozdrav svijete!" <<endl;
- }
- }
- MPI::Finalize();
- return 0;
- }
Add Comment
Please, Sign In to add comment