root/ompi/mca/io/romio321/romio/adio/common/ad_close.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. ADIO_Close

   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 "adio.h"
   9 #include "adio_extern.h"
  10 #ifdef HAVE_UNISTD_H
  11 #include <unistd.h>
  12 #endif
  13 
  14 void ADIO_Close(ADIO_File fd, int *error_code)
  15 {
  16     int i, j, k, combiner, myrank, err, is_contig;
  17     static char myname[] = "ADIO_CLOSE";
  18 
  19     if (fd->async_count) {
  20         *error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  21                                            myname, __LINE__, MPI_ERR_IO, "**io",
  22                                            "**io %s", strerror(errno));
  23         return;
  24     }
  25 
  26     /* because of deferred open, this warants a bit of explaining.  First, if
  27      * we've done aggregation,
  28      * then close the file.  Then, if any process left has done independent
  29      * i/o, close the file.  Otherwise, we'll skip the fs-specific close and
  30      * just say everything is a-ok.
  31      *
  32      * XXX: is it ok for those processes with a "real" communicator and those
  33      * with "MPI_COMM_SELF" to both call ADIOI_xxx_Close at the same time ?
  34      * everyone who ever opened the file will close it. Is order important? Is
  35      * timing important?
  36      */
  37     if (fd->hints->deferred_open && fd->is_agg) {
  38             (*(fd->fns->ADIOI_xxx_Close))(fd, error_code);
  39     } else {
  40             if(fd->is_open)  {
  41                     (*(fd->fns->ADIOI_xxx_Close))(fd, error_code);
  42             } else {
  43                     *error_code = MPI_SUCCESS;
  44             }
  45             
  46     }
  47 
  48     if (fd->access_mode & ADIO_DELETE_ON_CLOSE) {
  49         /* if we are doing aggregation and deferred open, then it's possible
  50          * that rank 0 does not have access to the file. make sure only an
  51          * aggregator deletes the file.*/
  52         MPI_Comm_rank(fd->comm, &myrank);
  53         if (myrank == fd->hints->ranklist[0]) {
  54                 ADIO_Delete(fd->filename, &err);
  55         }
  56         MPI_Barrier(fd->comm);
  57     }
  58 
  59     if (fd->fortran_handle != -1) {
  60         ADIOI_Ftable[fd->fortran_handle] = MPI_FILE_NULL;
  61     }
  62 
  63     if (fd->hints) ADIOI_Free(fd->hints->ranklist);
  64     if (fd->hints && fd->hints->cb_config_list) ADIOI_Free(fd->hints->cb_config_list);
  65 
  66     /* This BlueGene platform-specific free must be done in the common code
  67      * because the malloc's for these hint data structures are done at the
  68      * scope of ADIO_Open within the SetInfo call (ADIOI_GPFS_SetInfo which
  69      * calls ADIOI_BG_gen_agg_ranklist).  They cannot be done in the
  70      * ADIOI_GPFS_Close because of the file creation case where the
  71      * ADIOI_GPFS_Close and re-open via ADIOI_GPFS_Open are done which results
  72      * in a double-free - ADIOI_GPFS_Open does not redo the SetInfo...  */
  73 #ifdef BGQPLATFORM
  74     if (fd->hints && fd->hints->fs_hints.bg.bridgelist) ADIOI_Free(fd->hints->fs_hints.bg.bridgelist);
  75     if (fd->hints && fd->hints->fs_hints.bg.bridgelistnum) ADIOI_Free(fd->hints->fs_hints.bg.bridgelistnum);
  76 #endif
  77 
  78     /* Persistent File Realms */
  79     if (fd->hints->cb_pfr == ADIOI_HINT_ENABLE) {
  80         /* AAR, FSIZE, and User provided uniform File realms */
  81         if (1) {
  82             ADIOI_Delete_flattened (fd->file_realm_types[0]);
  83             MPI_Type_free (&fd->file_realm_types[0]);
  84         }
  85         else {
  86             for (i=0; i<fd->hints->cb_nodes; i++) {
  87                 ADIOI_Datatype_iscontig(fd->file_realm_types[i], &is_contig);
  88                 if (!is_contig)
  89                     ADIOI_Delete_flattened(fd->file_realm_types[i]);
  90                 MPI_Type_free (&fd->file_realm_types[i]);
  91             }
  92         }
  93         ADIOI_Free(fd->file_realm_st_offs);
  94         ADIOI_Free(fd->file_realm_types);
  95     }
  96     ADIOI_Free(fd->hints);
  97 
  98 
  99 
 100     MPI_Comm_free(&(fd->comm));
 101     ADIOI_Free(fd->filename); 
 102 
 103     MPI_Type_get_envelope(fd->etype, &i, &j, &k, &combiner);
 104     if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->etype));
 105 
 106     ADIOI_Datatype_iscontig(fd->filetype, &is_contig);
 107     if (!is_contig) ADIOI_Delete_flattened(fd->filetype);
 108 
 109     MPI_Type_get_envelope(fd->filetype, &i, &j, &k, &combiner);
 110     if (combiner != MPI_COMBINER_NAMED) MPI_Type_free(&(fd->filetype));
 111 
 112     MPI_Info_free(&(fd->info));
 113 
 114     ADIOI_Free(fd->io_buf);
 115     ADIOI_OneSidedCleanup(fd);
 116 
 117     /* memory for fd is freed in MPI_File_close */
 118 }

/* [<][>][^][v][top][bottom][index][help] */