1

I am building an application using RMA in MPI. I am stuck at how to achieve the following, suppose I have 2 windows win1 and win2, what I want to do is write data into both the windows but I want this to be atomic so that untill both the elements are written into their respective windows no other process accesses the window at same target process.

Is this possible to achieve in MPI? making write on single window atomic is possible with Exclusive Lock but is there any way I can lock multiple windows together?

Yash
  • 21
  • 2
  • Acquire an exclusive lock on both? But note that you can not acquire them at the same time, so you may get a "dining philosophers" problem. Solution: You could make a "coordination window": if you can acquire that, you are free to write in the other two windows. Just curious: What do you need this for? – Victor Eijkhout Feb 14 '23 at 18:43
  • @VictorEijkhout one hiccup is other processes also might be trying to get a shared_lock for reading some of the data from these windows (not necessarily simultaneously, like one process may want to read data from only one window) , this will cause a problem with the coordination window approach right? I am working on parallel graph algorithms, and I have graph properties that stored using RMA, and there are cases where I need to update multiple properties of the same node atomically hence updating multiple windows atomically. – Yash Feb 15 '23 at 03:56
  • 1
    @VictorEijkhout I think then before acquiring a shared lock on any of the window , I can make them acquire a shared_lock on the same coordination window first right? will this work? – Yash Feb 15 '23 at 04:03
  • Your second comment. Yes: you don't lock the individual windows: you try to acquire a lock on the coordination window, and if you succeed, that means the other windows are free to write in. – Victor Eijkhout Feb 15 '23 at 15:54
  • I will still require to get a lock on individual windows too after getting lock on coordination window to ensure coherence i.e RMA calls get completed on other windows when unlock on coordination window is done, becuase lock unlock on coordination window will guarantee completion of RMA calls on the coordination window only( which there aren't any). – Yash Feb 15 '23 at 17:51
  • @VictorEijkhout I am not sure whether coordination window approach will work, when we acquire lock for coordination window it doesn't gurantee anything about RMA calls to other windows right? like the RMA calls to other windows might not necessarily occur in between the lock and unlock of coordination window i.e lock and unlock of coordination window doesnt synchronize the RMA calls on other windows? Is this correct or is there some mistake in my understanding of lock and unlock ? – Yash Feb 15 '23 at 19:45
  • "might not necessarily occur in between" That's how you have to write your code. Only write in the other windows if you have a lock on the coordination window. – Victor Eijkhout Feb 16 '23 at 00:05
  • @VictorEijkhout, MPI_Win_LOCK(target_proc, coord_window, EXCLUSIVE_LOCK); MPI_Put(target_proc, something, individual_window1); MPI_UNLOCK(target_proc, coord_window); is this how you are suggesting? but this wont work because, the MPI_PUT call on individual window 1 doesn't have to execute within the access epoch on coord_window, it will execute in the access epoch of its own window, so the lock and unlock on coord_window have no part in synchrony of get or put operatios on individual windows. Is this right? – Yash Feb 16 '23 at 05:06

1 Answers1

0

MPI window locks are not locks and cannot be used this way. The name is unfortunate.

An exclusive lock/unlock epoch is a critical section around the encapsulated RMA operations. It is possible to implement these with no actual locking in at least some cases.

What you want to achieve requires a proper mutex. You can implement a spin-lock using MPI_COMPARE_AND_SWAP, for example. Other implementations exist, e.g. https://www.mcs.anl.gov/~robl/papers/ross_atomic-mpiio.pdf.

Jeff Hammond
  • 5,374
  • 3
  • 28
  • 45