1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
2 /*
3 *
4 * Copyright (C) 1997 University of Chicago.
5 * See COPYRIGHT notice in top-level directory.
6 */
7
8 #include "ad_pfs.h"
9
10 void ADIOI_PFS_Flush(ADIO_File fd, int *error_code)
11 {
12 int err, np_total, np_comm;
13 static char myname[] = "ADIOI_PFS_FLUSH";
14
15 /* fsync is not actually needed in PFS, because it uses something
16 called fast-path I/O. However, it doesn't do any harm either. */
17 err = fsync(fd->fd_sys);
18 if (err == -1) {
19 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
20 myname, __LINE__, MPI_ERR_IO,
21 "**io",
22 "**io %s", strerror(errno));
23 }
24 else *error_code = MPI_SUCCESS;
25
26 /* MPI-IO requires that after an fsync all processes must see the same
27 file size. In PFS M_ASYNC mode, this doesn't automatically happen.
28 Therefore, if M_ASYNC mode, temporarily change it to M_UNIX mode
29 and then switch back to M_ASYNC. That updates the file size! */
30
31 MPI_Comm_size(MPI_COMM_WORLD, &np_total);
32 MPI_Comm_size(fd->comm, &np_comm);
33 if ((np_total == np_comm) && (!(fd->atomicity))) {
34 err = _setiomode(fd->fd_sys, M_UNIX);
35 err = _setiomode(fd->fd_sys, M_ASYNC);
36 }
37 /* else it is M_UNIX anyway. don't do anything. */
38 }