Blame src/mpi/romio/mpi-io/close.c

Packit 0848f5
/* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
Packit 0848f5
/* 
Packit 0848f5
 *
Packit 0848f5
 *   Copyright (C) 1997 University of Chicago. 
Packit 0848f5
 *   See COPYRIGHT notice in top-level directory.
Packit 0848f5
 */
Packit 0848f5
Packit 0848f5
#include "mpioimpl.h"
Packit 0848f5
Packit 0848f5
#ifdef HAVE_WEAK_SYMBOLS
Packit 0848f5
Packit 0848f5
#if defined(HAVE_PRAGMA_WEAK)
Packit 0848f5
#pragma weak MPI_File_close = PMPI_File_close
Packit 0848f5
#elif defined(HAVE_PRAGMA_HP_SEC_DEF)
Packit 0848f5
#pragma _HP_SECONDARY_DEF PMPI_File_close MPI_File_close
Packit 0848f5
#elif defined(HAVE_PRAGMA_CRI_DUP)
Packit 0848f5
#pragma _CRI duplicate MPI_File_close as PMPI_File_close
Packit 0848f5
/* end of weak pragmas */
Packit 0848f5
#elif defined(HAVE_WEAK_ATTRIBUTE)
Packit 0848f5
int MPI_File_close(MPI_File *fh) __attribute__((weak,alias("PMPI_File_close")));
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
/* Include mapping from MPI->PMPI */
Packit 0848f5
#define MPIO_BUILD_PROFILING
Packit 0848f5
#include "mpioprof.h"
Packit 0848f5
#endif
Packit 0848f5
Packit 0848f5
/*@
Packit 0848f5
    MPI_File_close - Closes a file
Packit 0848f5
Packit 0848f5
Input Parameters:
Packit 0848f5
. fh - file handle (handle)
Packit 0848f5
Packit 0848f5
.N fortran
Packit 0848f5
@*/
Packit 0848f5
int MPI_File_close(MPI_File *fh)
Packit 0848f5
{
Packit 0848f5
    int error_code;
Packit 0848f5
    ADIO_File adio_fh;
Packit 0848f5
    static char myname[] = "MPI_FILE_CLOSE";
Packit 0848f5
#ifdef MPI_hpux
Packit 0848f5
    int fl_xmpi;
Packit 0848f5
Packit 0848f5
    HPMP_IO_WSTART(fl_xmpi, BLKMPIFILECLOSE, TRDTBLOCK, *adio_fh);
Packit 0848f5
#endif /* MPI_hpux */
Packit 0848f5
Packit 0848f5
    ROMIO_THREAD_CS_ENTER();
Packit 0848f5
Packit 0848f5
    adio_fh = MPIO_File_resolve(*fh);
Packit 0848f5
Packit 0848f5
    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
    MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
Packit 0848f5
    if (ADIO_Feature(adio_fh, ADIO_SHARED_FP))
Packit 0848f5
    {
Packit 0848f5
	ADIOI_Free((adio_fh)->shared_fp_fname);
Packit 0848f5
	/* POSIX semantics say a deleted file remains available until all
Packit 0848f5
	 * processes close the file.  But since when was NFS posix-compliant?
Packit 0848f5
	 */
Packit 0848f5
	/* this used to be gated by the lack of the UNLINK_AFTER_CLOSE feature,
Packit 0848f5
	 * but a race condition in GPFS necessated this.  See ticket #2214 */
Packit 0848f5
	MPI_Barrier((adio_fh)->comm);
Packit 0848f5
	if ((adio_fh)->shared_fp_fd != ADIO_FILE_NULL) {
Packit 0848f5
	    MPI_File *fh_shared = &(adio_fh->shared_fp_fd);
Packit 0848f5
	    ADIO_Close((adio_fh)->shared_fp_fd, &error_code);
Packit 0848f5
            MPIO_File_free(fh_shared);
Packit 0848f5
	    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
	    if (error_code != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
	    /* --END ERROR HANDLING-- */
Packit 0848f5
	}
Packit 0848f5
    }
Packit 0848f5
Packit 0848f5
    /* Because ROMIO expects the MPI library to provide error handler management
Packit 0848f5
     * routines but it doesn't ever participate in MPI_File_close, we have to
Packit 0848f5
     * somehow inform the MPI library that we no longer hold a reference to any
Packit 0848f5
     * user defined error handler.  We do this by setting the errhandler at this
Packit 0848f5
     * point to MPI_ERRORS_RETURN. */
Packit 0848f5
    error_code = PMPI_File_set_errhandler(*fh, MPI_ERRORS_RETURN);
Packit 0848f5
    if (error_code != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
Packit 0848f5
    ADIO_Close(adio_fh, &error_code);
Packit 0848f5
    MPIO_File_free(fh);
Packit 0848f5
    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
    if (error_code != MPI_SUCCESS) goto fn_fail;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
Packit 0848f5
#ifdef MPI_hpux
Packit 0848f5
    HPMP_IO_WEND(fl_xmpi);
Packit 0848f5
#endif /* MPI_hpux */
Packit 0848f5
Packit 0848f5
fn_exit:
Packit 0848f5
    ROMIO_THREAD_CS_EXIT();
Packit 0848f5
    return error_code;
Packit 0848f5
fn_fail:
Packit 0848f5
    /* --BEGIN ERROR HANDLING-- */
Packit 0848f5
    error_code = MPIO_Err_return_file(adio_fh, error_code);
Packit 0848f5
    goto fn_exit;
Packit 0848f5
    /* --END ERROR HANDLING-- */
Packit 0848f5
}