The following examples all access a preexisting file ``myfile.'' Word 10 in myfile initially contains the integer 2. Each example writes and reads word 10.
First consider the following code fragment:
int a = 4, b, TRUE=1; MPI_File_open( MPI_COMM_WORLD, "myfile", MPI_MODE_RDWR, MPI_INFO_NULL, &fh ) ; MPI_File_set_view( fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL ) ; /* MPI_File_set_atomicity( fh, TRUE ) ; Use this to set atomic mode. */ MPI_File_iwrite_at(fh, 10, &a, 1, MPI_INT, &reqs[0]) ; MPI_File_iread_at(fh, 10, &b, 1, MPI_INT, &reqs[1]) ; MPI_Waitall(2, reqs, statuses) ;For asynchronous data access operations, MPI-/ specifies that the access occurs at any time between the call to the asynchronous data access routine and the return from the corresponding request complete routine. Thus, executing either the read before the write, or the write before the read is consistent with program order. If atomic mode is set, then MPI-/ guarantees sequential consistency, and the program will read either 2 or 4 into b. If atomic mode is not set, then sequential consistency is not guaranteed and the program may read something other than 2 or 4 due to the conflicting data access.
Similarly, the following code fragment does not order file accesses:
int a = 4, b; MPI_File_open( MPI_COMM_WORLD, "myfile", MPI_MODE_RDWR, MPI_INFO_NULL, &fh ) ; MPI_File_set_view( fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL ) ; /* MPI_File_set_atomicity( fh, TRUE ) ; Use this to set atomic mode. */ MPI_File_iwrite_at(fh, 10, &a, 1, MPI_INT, &reqs[0]) ; MPI_File_iread_at(fh, 10, &b, 1, MPI_INT, &reqs[1]) ; MPI_Wait(&reqs[0], &status) ; MPI_Wait(&reqs[1], &status) ;If atomic mode is set, either 2 or 4 will be read into b. Again, MPI-/ does not guarantee sequential consistency in nonatomic mode.
On the other hand, the following code fragment:
int a = 4, b; MPI_File_open( MPI_COMM_WORLD, "myfile", MPI_MODE_RDWR, MPI_INFO_NULL, &fh ) ; MPI_File_set_view( fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL ) ; MPI_File_iwrite_at(fh, 10, &a, 1, MPI_INT, &reqs[0]) ; MPI_Wait(&reqs[0], &status) ; MPI_File_iread_at(fh, 10, &b, 1, MPI_INT, &reqs[1]) ; MPI_Wait(&reqs[1], &status) ;defines the same ordering as:
int a = 4, b; MPI_File_open( MPI_COMM_WORLD, "myfile", MPI_MODE_RDWR, MPI_INFO_NULL, &fh ) ; MPI_File_set_view( fh, 0, MPI_INT, MPI_INT, "native", MPI_INFO_NULL ) ; MPI_File_write_at(fh, 10, &a, 1, MPI_INT, &status ) ; MPI_File_read_at(fh, 10, &b, 1, MPI_INT, &status ) ;Since
Similar considerations apply to conflicting accesses of the form:
MPI_File_write_all_begin(fh,...) ; MPI_File_iread(fh,...) ; MPI_Wait(fh,...) ; MPI_File_write_all_end(fh,...) ;
Recall that constraints governing consistency and semantics are not relevant to the following:
MPI_File_write_all_begin(fh,...) ; MPI_File_read_all_begin(fh,...) ; MPI_File_read_all_end(fh,...) ; MPI_File_write_all_end(fh,...) ;since split collective operations on the same file handle may not overlap (see Section 9.4.5, page
MPI-Standard for MARMOT