1 /* ---------------------------------------------------------------- */
2 /* (C)Copyright IBM Corp. 2007, 2008 */
3 /* ---------------------------------------------------------------- */
4 /**
5 * \file ad_gpfs_flush.c
6 * \brief Scalable flush for GPFS
7 */
8
9 /* -*- Mode: C; c-basic-offset:4 ; -*- */
10 /*
11 *
12 * Copyright (C) 1997 University of Chicago.
13 * See COPYRIGHT notice in top-level directory.
14 */
15
16 #include "ad_gpfs.h"
17
18 void ADIOI_GPFS_Flush(ADIO_File fd, int *error_code)
19 {
20 int err=0;
21 static char myname[] = "ADIOI_GPFS_FLUSH";
22
23 int rank;
24
25 MPI_Comm_rank(fd->comm, &rank);
26
27 /* the old logic about who is an fsync aggregator and who is not fell down
28 * when deferred open was enabled. Instead, make this look more like
29 * ad_pvfs2_flush. If one day the I/O aggregators have something they need
30 * to flush, we can consult the 'fd->hints->ranklist[]' array. For now, a
31 * flush from one process should suffice */
32
33 /* ensure all other proceses are done writing. On many platforms MPI_Reduce
34 * is fastest because it has the lightest constraints. On Blue Gene, BARRIER
35 * is optimized */
36 MPI_Barrier(fd->comm);
37
38 if (rank == fd->hints->ranklist[0]) {
39 err = fsync(fd->fd_sys);
40 DBG_FPRINTF(stderr,"aggregation:fsync %s, err=%#X, errno=%#X\n",fd->filename, err, errno);
41 /* We want errno, not the return code if it failed */
42 if (err == -1) err = errno;
43 else err = 0;
44 }
45 MPI_Bcast(&err, 1, MPI_UNSIGNED, fd->hints->ranklist[0], fd->comm);
46 DBGV_FPRINTF(stderr,"aggregation result:fsync %s, errno %#X,\n",fd->filename, err);
47
48 if (err) /* if it's non-zero, it must be an errno */
49 {
50 errno = err;
51 err = -1;
52 }
53
54 /* --BEGIN ERROR HANDLING-- */
55 if (err == -1)
56 {
57 *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
58 myname, __LINE__, MPI_ERR_IO,
59 "**io",
60 "**io %s", strerror(errno));
61 DBGT_FPRINTF(stderr,"fsync %s, err=%#X, errno=%#X\n",fd->filename, err, errno);
62 return;
63 }
64 /* --END ERROR HANDLING-- */
65
66 *error_code = MPI_SUCCESS;
67 }
68