I am learning MPI and I am making a program in C to run with four processes. Each process has access to an index (n), then it adds one to that index (update) and each process must know the last calculated value of n.
If a process is accessing the index, the rest of processes must wait until the index is released.
In other words, each process must:
1- access the index 2- update the index 3- release the index
The 1 and 2 points are in the critical section. How can I manage the mutual exclusion with MPI? I have used MPI_Bcast to send the last calculated value and MPI_Wait but it doesn't work.
Thanks in advance.