Skip main navigation

The three shared memory read and write rules

In this step, synchronizations are explained with built-in or explicit pairs of local memory fences and three read and write rules.
© HLRS

In this step, you will see that such synchronizations together with built in or explicit pair of local memory fences, there are three read and write rules provided.

Let’s define the following symbol for a synchronization:

Passive target communication

Such synchronizations can be programmed using five different MPI RMA synchronizations.

In principle, if you want to program a synchronization from process 0 to process 1 there are 5 possibilities. The first is to use MPI_Win_post and MPI_Win_start, the second is MPI_Win_complete and MPI_Win_wait, the third option would be MPI_Win_fence (which is a synchronization in both directions), the fourth is to use a pair of MPI_Win_sync together with any other synchronization, and finally the fifth is to use MPI_Win_unlock and on the other side MPI_Win_lock, where you must guarantee that the lock comes after the unlock and not in the wrong order, as shown in the following figure:

Passive target communication

If you do any of these 5 synchronizations, three rules are guaranteed:

Passive target communication

The first rule is the write-read rule:
If you write a value val_1 into the variable A, then do one of the synchronizations and then load the variable A in the other process, you are guaranteed to load val_1. This is exactly what you need for our small example with the shared variable X.

Passive target communication

The second guaranteed rule is the read-write rule. This means that you load variable B in process 0, then you do the synchronization and finally you overwrite B in process 1.

This overwriting of B by val_2 will not influence the loading of B before the synchronization, so you cannot accidentally load val_2 from B in process 0.

Passive target communication

The third rule is the write-write rule. If you write the variable C on both sides and then load the C again in process 1, then you are guaranteed to get val_4 and not val_3.

In the next step, we will show an example of how you may really need these rules in your application. All these rules are important for correct shared memory programming. This example will show the write-read and the read-write rule together with any-process-synchronizations and pairs of MPI_Win_sync.

© HLRS
This article is from the free online

One-Sided Communication and the MPI Shared Memory Interface

Created by
FutureLearn - Learning For Life

Our purpose is to transform access to education.

We offer a diverse selection of courses from leading universities and cultural institutions from around the world. These are delivered one step at a time, and are accessible on mobile, tablet and desktop, so you can fit learning around your life.

We believe learning should be an enjoyable, social experience, so our courses offer the opportunity to discuss what you’re learning with others as you go, helping you make fresh discoveries and form new ideas.
You can unlock new opportunities with unlimited access to hundreds of online short courses for a year by subscribing to our Unlimited package. Build your knowledge with top universities and organisations.

Learn more about how FutureLearn is transforming access to education