2

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.

LucíaLP
  • 21
  • 4
  • 1
    Look at [this answer](https://stackoverflow.com/a/32646142/5239503) and change the counter into a variable that tells whether or not there is already a process in the critical section. If you can't do it, let me know and I'll post an example. – Gilles Aug 28 '17 at 06:28

0 Answers0