root/ompi/mca/io/romio321/romio/mpi-io/open.c

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_File_open

   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 "mpioimpl.h"
   9 
  10 #ifdef HAVE_WEAK_SYMBOLS
  11 
  12 #if defined(HAVE_PRAGMA_WEAK)
  13 #pragma weak MPI_File_open = PMPI_File_open
  14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
  15 #pragma _HP_SECONDARY_DEF PMPI_File_open MPI_File_open
  16 #elif defined(HAVE_PRAGMA_CRI_DUP)
  17 #pragma _CRI duplicate MPI_File_open as PMPI_File_open
  18 /* end of weak pragmas */
  19 #elif defined(HAVE_WEAK_ATTRIBUTE)
  20 int MPI_File_open(MPI_Comm comm, const char *filename, int amode, MPI_Info info, MPI_File *fh) __attribute__((weak,alias("PMPI_File_open")));
  21 #endif
  22 
  23 /* Include mapping from MPI->PMPI */
  24 #define MPIO_BUILD_PROFILING
  25 #include "mpioprof.h"
  26 #endif
  27 
  28 /* for user-definde reduce operator */
  29 #include "adio_extern.h"
  30 
  31 
  32 extern int ADIO_Init_keyval;
  33 
  34 /*@
  35     MPI_File_open - Opens a file
  36 
  37 Input Parameters:
  38 . comm - communicator (handle)
  39 . filename - name of file to open (string)
  40 . amode - file access mode (integer)
  41 . info - info object (handle)
  42 
  43 Output Parameters:
  44 . fh - file handle (handle)
  45 
  46 .N fortran
  47 @*/
  48 int MPI_File_open(MPI_Comm comm, ROMIO_CONST char *filename, int amode,
  49                   MPI_Info info, MPI_File *fh)
  50 {
  51     int error_code = MPI_SUCCESS, file_system, flag, tmp_amode=0, rank;
  52     char *tmp;
  53     MPI_Comm dupcomm = MPI_COMM_NULL;
  54     ADIOI_Fns *fsops;
  55     static char myname[] = "MPI_FILE_OPEN";
  56 #ifdef MPI_hpux
  57     int fl_xmpi;
  58 
  59     HPMP_IO_OPEN_START(fl_xmpi, comm);
  60 #endif /* MPI_hpux */
  61 
  62     ROMIO_THREAD_CS_ENTER();
  63 
  64     /* --BEGIN ERROR HANDLING-- */
  65     MPIO_CHECK_COMM(comm, myname, error_code);
  66     MPIO_CHECK_INFO_ALL(info, error_code, comm);
  67     /* --END ERROR HANDLING-- */
  68 
  69     error_code = MPI_Comm_test_inter(comm, &flag);
  70     /* --BEGIN ERROR HANDLING-- */
  71     if (error_code || flag)
  72     {
  73         error_code = MPIO_Err_create_code(error_code, MPIR_ERR_RECOVERABLE,
  74                                           myname, __LINE__, MPI_ERR_COMM, 
  75                                           "**commnotintra", 0);
  76         goto fn_fail;
  77     }
  78 
  79     if ( ((amode&MPI_MODE_RDONLY)?1:0) + ((amode&MPI_MODE_RDWR)?1:0) +
  80          ((amode&MPI_MODE_WRONLY)?1:0) != 1 )
  81     {
  82         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  83                                           myname, __LINE__, MPI_ERR_AMODE, 
  84                                           "**fileamodeone", 0);
  85         goto fn_fail;
  86     }
  87 
  88     if ((amode & MPI_MODE_RDONLY) && 
  89             ((amode & MPI_MODE_CREATE) || (amode & MPI_MODE_EXCL)))
  90     {
  91         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  92                                           myname, __LINE__, MPI_ERR_AMODE, 
  93                                           "**fileamoderead", 0);
  94         goto fn_fail;
  95     }
  96 
  97     if ((amode & MPI_MODE_RDWR) && (amode & MPI_MODE_SEQUENTIAL))
  98     {
  99         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
 100                                           myname, __LINE__, MPI_ERR_AMODE, 
 101                                           "**fileamodeseq", 0);
 102         goto fn_fail;
 103     }
 104 
 105     MPI_Comm_dup(comm, &dupcomm);
 106 
 107 /* check if ADIO has been initialized. If not, initialize it */
 108     MPIR_MPIOInit(&error_code);
 109     if (error_code != MPI_SUCCESS) goto fn_fail;
 110 
 111 /* check if amode is the same on all processes: at first glance, one might try
 112  * to use a built-in operator like MPI_BAND, but we need every mpi process to
 113  * agree the amode was not the same.  Consider process A with
 114  * MPI_MODE_CREATE|MPI_MODE_RDWR, and B with MPI_MODE_RDWR:  MPI_BAND yields
 115  * MPI_MODE_RDWR.  A determines amodes are different, but B proceeds having not
 116  * detected an error */
 117     MPI_Allreduce(&amode, &tmp_amode, 1, MPI_INT, ADIO_same_amode, dupcomm);
 118 
 119     if (tmp_amode == ADIO_AMODE_NOMATCH) {
 120         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
 121                         myname, __LINE__, MPI_ERR_NOT_SAME,
 122                         "**fileamodediff", 0);
 123         goto fn_fail;
 124     }
 125     /* --END ERROR HANDLING-- */
 126 
 127     file_system = -1;
 128 
 129     /* resolve file system type from file name; this is a collective call */
 130     ADIO_ResolveFileType(dupcomm, filename, &file_system, &fsops, &error_code);
 131     /* --BEGIN ERROR HANDLING-- */
 132     if (error_code != MPI_SUCCESS)
 133     {
 134         /* ADIO_ResolveFileType() will print as informative a message as it
 135          * possibly can or call MPIO_Err_setmsg.  We just need to propagate 
 136          * the error up.
 137          */
 138         goto fn_fail;
 139     }
 140 
 141     /* --END ERROR HANDLING-- */
 142 
 143     /* strip off prefix if there is one, but only skip prefixes
 144      * if they are greater than length one to allow for windows
 145      * drive specifications (e.g. c:\...) */
 146 
 147     tmp = strchr(filename, ':');
 148     if (tmp > filename + 1) {
 149         filename = tmp + 1;
 150     }
 151 
 152 /* use default values for disp, etype, filetype */    
 153 
 154     *fh = ADIO_Open(comm, dupcomm, filename, file_system, fsops, amode, 0,
 155                     MPI_BYTE, MPI_BYTE, info, ADIO_PERM_NULL, &error_code);
 156 
 157     /* --BEGIN ERROR HANDLING-- */
 158     if (error_code != MPI_SUCCESS) {
 159         goto fn_fail;
 160     }
 161     /* --END ERROR HANDLING-- */
 162 
 163     /* if MPI_MODE_SEQUENTIAL requested, file systems cannot do explicit offset
 164      * or independent file pointer accesses, leaving not much else aside from
 165      * shared file pointer accesses. */
 166     if ( !ADIO_Feature((*fh), ADIO_SHARED_FP) && (amode & MPI_MODE_SEQUENTIAL)) 
 167     {
 168         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE, 
 169                                           myname, __LINE__, 
 170                                           MPI_ERR_UNSUPPORTED_OPERATION,
 171                                           "**iosequnsupported", 0);
 172         ADIO_Close(*fh, &error_code);
 173         goto fn_fail;
 174     }
 175 
 176     /* determine name of file that will hold the shared file pointer */
 177     /* can't support shared file pointers on a file system that doesn't
 178        support file locking. */
 179     if ((error_code == MPI_SUCCESS) && 
 180                     ADIO_Feature((*fh), ADIO_SHARED_FP)) {
 181         MPI_Comm_rank(dupcomm, &rank);
 182         ADIOI_Shfp_fname(*fh, rank, &error_code);
 183         if (error_code != MPI_SUCCESS)
 184             goto fn_fail;
 185 
 186         /* if MPI_MODE_APPEND, set the shared file pointer to end of file.
 187            indiv. file pointer already set to end of file in ADIO_Open. 
 188            Here file view is just bytes. */
 189         if ((*fh)->access_mode & MPI_MODE_APPEND) {
 190             if (rank == (*fh)->hints->ranklist[0])  /* only one person need set the sharedfp */
 191                     ADIO_Set_shared_fp(*fh, (*fh)->fp_ind, &error_code);
 192             MPI_Barrier(dupcomm);
 193         }
 194     }
 195 
 196 #ifdef MPI_hpux
 197     HPMP_IO_OPEN_END(fl_xmpi, *fh, comm);
 198 #endif /* MPI_hpux */
 199 
 200 fn_exit:
 201     ROMIO_THREAD_CS_EXIT();
 202     return error_code;
 203 fn_fail:
 204     /* --BEGIN ERROR HANDLING-- */
 205     if (dupcomm != MPI_COMM_NULL) MPI_Comm_free(&dupcomm);
 206     error_code = MPIO_Err_return_file(MPI_FILE_NULL, error_code);
 207     goto fn_exit;
 208     /* --END ERROR HANDLING-- */
 209 }

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