Skip to content

Commit 0cee059

Browse files
committed
Add MPI_Barrier to ensure all writes finish before any process starts to read
1 parent 35bf19d commit 0cee059

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/drivers/ncmpio/ncmpio_enddef.c

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,9 +1191,14 @@ ncmpio__enddef(void *ncdp,
11911191

11921192
if (ncp->vars.ndefined > 0) { /* no. record and non-record variables */
11931193
if (ncp->begin_var > ncp->old->begin_var) {
1194-
/* header extent has increased, shift the entire data section
1195-
* to a higher offset, by moving record variables first
1194+
/* header size increases, move the entire data section to a
1195+
* higher file offset. To make sure all processes finish their
1196+
* I/O before any process starts to read, it is necessary to
1197+
* call MPI_Barrier.
11961198
*/
1199+
MPI_Barrier(ncp->comm);
1200+
1201+
/* shift record variables first */
11971202
err = move_record_vars(ncp, ncp->old);
11981203
CHECK_ERROR(err)
11991204

@@ -1204,6 +1209,13 @@ ncmpio__enddef(void *ncdp,
12041209
}
12051210
else if (ncp->begin_rec > ncp->old->begin_rec ||
12061211
ncp->recsize > ncp->old->recsize) {
1212+
/* fix-sized variable section size increases, move the entire
1213+
* record variable section to a higher file offset. To make
1214+
* sure all processes finish their I/O before any process
1215+
* starts to read, it is necessary to call MPI_Barrier.
1216+
*/
1217+
MPI_Barrier(ncp->comm);
1218+
12071219
/* number of non-record variables increases, or
12081220
number of records of record variables increases,
12091221
shift and move all record variables down */

0 commit comments

Comments
 (0)