Fence synchronization is the simplest RMA synchronization pattern and most closely resembles the MPI_Barrier call (though advanced users can alter this behavior somewhat by using the assert parameter). Both the start and end of an RMA epoch are defined by all processes calling the collective MPI_Win_fence call. RMA communication calls cannot begin until the target process has called MPI_Win_fence. When MPI_Win_fence is called to terminate an epoch, the call will block until all RMA operations originating at that process complete.

int MPI_Win_fence(int assert, MPI_Win win)
assert
a way for the programmer to provide context to the call
win
the window which should be synchronized

Fence synchronization provides a very simple approach to RMA epochs. It reflects a paradigm where global communication is interleaved with global computation. Each global communication section is bracketed with MPI_Win_fence calls, allowing all processes to sync up, talk, and return to computation. In fence synchronization, ALL communication calls should be contained within MPI_Win_fence calls, as shown below.

//Start up MPI....
MPI_Win win;

if (rank == 0) {
	/* Everyone will retrieve from a buffer on root */
	int soi = sizeof(int);
	MPI_Win_create(buf,soi*20,soi,MPI_INFO_NULL,comm,&win); }
else {
	/* Others only retrieve, so these windows can be size 0 */
	MPI_Win_create(NULL,0,sizeof(int),MPI_INFO_NULL,comm,&win); 
}

/* No local operations prior to this epoch, so give an assertion */
MPI_Win_fence(MPI_MODE_NOPRECEDE,win);

if (rank != 0) {
	/* Inside the fence, make RMA calls to GET from rank 0 */
	MPI_Get(buf,20,MPI_INT,0,0,20,MPI_INT,win);
}

/* Complete the epoch - this will block until MPI_Get is complete */
MPI_Win_fence(0,win);

/* All done with the window - tell MPI there are no more epochs */
MPI_Win_fence(MPI_MODE_NOSUCCEED,win);

/* Free up our window */
MPI_Win_free(&win)

//shut down...

The fence method described earlier is a specific version of what is called active target synchronization because the target must explicitly call the synchronization routine, along with the origin. It is very simple to use but very limited in its flexibility. General active target synchronization is provided by the post, start, complete, and wait functions; these are described next.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement