I want to use MPI (MPICH2) on windows. I write this command:
MPI_Barrier(MPI_COMM_WORLD);
And I expect it blocks all Processors until all group members have called it. But it is not happen. I add a schematic of my code:
int a;
if(myrank == RootProc)
a = 4;
MPI_Barrier(MPI_COMM_WORLD);
cout << "My Rank = " << myrank << "\ta = " << a << endl;
(With 2 processor:) Root processor (0
) acts correctly, but processor with rank 1 doesn't know the a
variable, so it display -858993460
instead of 4
.
Can any one help me?
Regards
You're only assigning a
in process 0. MPI doesn't share memory, so if you want the a
in process 1 to get the value of 4, you need to call MPI_Send
from process 0 and MPI_Recv
from process 1.