Witam, chciałem sie dowiedziec dlaczego program nie wyswietla mi na wyjsciu dwoch informacji ( oznaczylem w komentarzu o ktore linijki mi chodzi) . Program ma za zadanie w procesie 0 pobrac wartosc z standardowego wejscia a pozniej inkrementowac i wyslac do procesu n+1,i tak do ostatniego procesu, z czego jak bd w ostatnim to ma wyslac pakiet do procesu 0. Uruchamiam program dla 4 procesow ( 0, 1, 2, 3)
Jak widac jestem poczatkującym i probuję zrozumieć o co chodzi z programowaniem wspolbieznym i rozproszonym. Rozumiem ze ten kod nie dziala synchronicznie ale mimo wszystko wydaje mi się, ze te linijki które oznaczyłem w komentarzu powinny sie wykonać ?
cout << "Czemu tego mi nie wyswietla" << number <<endl;
#include <iostream>
#include <mpi.h>
using namespace std;
int main(int argc, char**argv)
{
MPI_Init(&argc, &argv);
int number = 0;
int mpi_rank;
MPI_Comm_rank(MPI_COMM_WORLD,&mpi_rank);
int mpi_size;
MPI_Comm_size(MPI_COMM_WORLD,&mpi_size);
if(mpi_rank == 0)
{
cout << "Podaj liczbe " << endl;
cin >> number;
cout << "Proces 0 wysyla " << number << endl;
MPI_Send(&number,1,MPI_INT,1,0,MPI_COMM_WORLD);
cout << "Czemu tego mi nie wyswietla" << number <<endl; // Ta linijka
MPI_Recv(&number,1,MPI_INT,3,3,MPI_COMM_WORLD,MPI_STATUSES_IGNORE);
cout << "Proces 0 otrzymal " << number << " od procesu 3" <<endl;
}
cout << "Czemu tego mi nie wyswietla" << number <<endl;
if(mpi_rank == 1)
{
cout << "Proces 1 przed odebraniem pakietu " << number << endl;
MPI_Recv(&number,1,MPI_INT,0,0,MPI_COMM_WORLD,MPI_STATUSES_IGNORE);
number+=1;
cout << "Proces 1 wysyla " << number << " do procesu 2 " << endl; // Ta linijka
MPI_Send(&number,1,MPI_INT,2,1,MPI_COMM_WORLD);
cout << "Proces 1 wysyla " << number << " do procesu 2 " << endl;
}
if(mpi_rank == 2)
{
cout << "Proces 2 przed odebraniem pakietu " << number << endl;
MPI_Recv(&number,1,MPI_INT,1,1,MPI_COMM_WORLD,MPI_STATUSES_IGNORE);
number+=1;
MPI_Send(&number,1,MPI_INT,3,2,MPI_COMM_WORLD);
cout << "Proces 2 wysyla " << number << " do procesu 3 " << endl;
}
if(mpi_rank == 3)
{
cout << "Proces 3 przed odebraniem pakietu " << number << endl;
MPI_Recv(&number,1,MPI_INT,2,2,MPI_COMM_WORLD,MPI_STATUSES_IGNORE);
number+=1;
MPI_Send(&number,1,MPI_INT,0,3,MPI_COMM_WORLD);
cout << "Proces 4 wysyla " << number << " do procesu 0 " << endl;
}
MPI_Finalize();
return 0;
}