Question: 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

Answer: 
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.
Variable `a` is not initialized - it is possible that is why it displays that number. In MPI, variable `a` is duplicated between the processes - so there are two values for `a`, one of which is uninitialized. You want to write:

```
int a = 4;
if (myrank == RootProc)
...

```

Or, alternatively, do an `MPI_send` in the Root (id 0), and an `MPI_recv` in the slave (id 1) so the value in the root is also set in the slave.

Note: that code triggers a small alarm in my head, so I need to check something and I'll edit this with more info. Until then though, the uninitialized value is most certainly a problem for you.
Ok I've checked the facts - your code was not properly indented and I missed the missing `{}`. The barrier looks fine now, although the snippet you posted does not do too much, and is not a very good example of a barrier because the slave enters it directly, whereas the root will set the value of the variable to `4` and then enter it. To test that it actually works, you probably want some sort of a sleep mechanism in one of the processes - that will yield (hope it's the correct term) the other process as well, preventing it from printing the `cout` until the sleep is over.