2

I would like to know which is the best way to ensure an exclusive access to a shared resource (such as memory window) among n processes in MPI. I've tried MPI_Win_lock & MPI_Win_fence but they don't seem to work as expected, i.e: I can see that multiple processes enter a critical region (code between MPI_Win_lock & MPI_Win_unlock that contains MPI_Get and/or MPI_Put) at the same time.

I would appreciate your suggestions. Thanks.

Hristo Iliev
  • 72,659
  • 12
  • 135
  • 186
Reda94
  • 331
  • 4
  • 12

1 Answers1

1

In MPI 2 you cannot truly do atomic operations. This is introduced in MPI 3 using MPI_Fetch_and_op. This is why your critical data is modified.

Furthermore, take care with `MPI_Win_lock'. As described here:

The name of this routine is misleading. In particular, this routine need not block, except when the target process is the calling process.

The actual blocking process is MPI_Win_unlock, meaning that only after returning from this procedure you can be sure that the values from put and get are correct. Perhaps this is better described here:

MPI passive target operations are organized into access epochs that are bracketed by MPI Win lock and MPI Win unlock calls. Clever MPI implementations [10] will combine all the data movement operations (puts, gets, and accumulates) into one network transaction that occurs at the unlock.

This same document can also provide a solution to your problem, which is that critical data is not written atomically. It does this through the use of a mutex, which is a mechanism that ensures only one process can access data at the time.

I recommend you read this document: The solution they propose is not difficult to implement.

Toon
  • 187
  • 11