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

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_File_write
  2. MPIOI_File_write

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *   Copyright (C) 1997 University of Chicago. 
   4  *   See COPYRIGHT notice in top-level directory.
   5  */
   6 
   7 #include "mpioimpl.h"
   8 
   9 #ifdef HAVE_WEAK_SYMBOLS
  10 
  11 #if defined(HAVE_PRAGMA_WEAK)
  12 #pragma weak MPI_File_write = PMPI_File_write
  13 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
  14 #pragma _HP_SECONDARY_DEF PMPI_File_write MPI_File_write
  15 #elif defined(HAVE_PRAGMA_CRI_DUP)
  16 #pragma _CRI duplicate MPI_File_write as PMPI_File_write
  17 /* end of weak pragmas */
  18 #elif defined(HAVE_WEAK_ATTRIBUTE)
  19 int MPI_File_write(MPI_File fh, const void *buf, int count, MPI_Datatype datatype,
  20                    MPI_Status *status) __attribute__((weak,alias("PMPI_File_write")));
  21 #endif
  22 
  23 /* Include mapping from MPI->PMPI */
  24 #define MPIO_BUILD_PROFILING
  25 #include "mpioprof.h"
  26 #endif
  27 
  28 /* status object not filled currently */
  29 
  30 /*@
  31     MPI_File_write - Write using individual file pointer
  32 
  33 Input Parameters:
  34 . fh - file handle (handle)
  35 . buf - initial address of buffer (choice)
  36 . count - number of elements in buffer (nonnegative integer)
  37 . datatype - datatype of each buffer element (handle)
  38 
  39 Output Parameters:
  40 . status - status object (Status)
  41 
  42 .N fortran
  43 @*/
  44 int MPI_File_write(MPI_File fh, ROMIO_CONST void *buf, int count,
  45                    MPI_Datatype datatype, MPI_Status *status)
  46 {
  47     int error_code;
  48     static char myname[] = "MPI_FILE_WRITE";
  49 #ifdef MPI_hpux
  50     int fl_xmpi;
  51 
  52     HPMP_IO_START(fl_xmpi, BLKMPIFILEWRITE, TRDTBLOCK, fh, datatype, count);
  53 #endif /* MPI_hpux */
  54 
  55     error_code = MPIOI_File_write(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL, buf,
  56                                   count, datatype, myname, status);
  57 
  58 #ifdef MPI_hpux
  59     HPMP_IO_END(fl_xmpi, fh, datatype, count);
  60 #endif /* MPI_hpux */
  61 
  62     return error_code;
  63 }
  64 
  65 /* prevent multiple definitions of this routine */
  66 #ifdef MPIO_BUILD_PROFILING
  67 int MPIOI_File_write(MPI_File fh,
  68                      MPI_Offset offset,
  69                      int file_ptr_type,
  70                      const void *buf,
  71                      int count,
  72                      MPI_Datatype datatype,
  73                      char *myname,
  74                      MPI_Status *status)
  75 {                     
  76     int error_code, buftype_is_contig, filetype_is_contig;
  77     MPI_Count datatype_size;
  78     ADIO_Offset off, bufsize;
  79     ADIO_File adio_fh;
  80     void *e32buf=NULL;
  81     const void *xbuf=NULL;
  82 
  83     ROMIO_THREAD_CS_ENTER();
  84 
  85     adio_fh = MPIO_File_resolve(fh);
  86 
  87     /* --BEGIN ERROR HANDLING-- */
  88     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
  89     MPIO_CHECK_COUNT(adio_fh, count, myname, error_code);
  90     MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code);
  91 
  92     if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0)
  93     {
  94         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
  95                                           myname, __LINE__, MPI_ERR_ARG,
  96                                           "**iobadoffset", 0);
  97         error_code = MPIO_Err_return_file(adio_fh, error_code);
  98         goto fn_exit;
  99     }
 100     /* --END ERROR HANDLING-- */
 101 
 102     MPI_Type_size_x(datatype, &datatype_size);
 103 
 104     /* --BEGIN ERROR HANDLING-- */
 105     MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code);
 106     /* --END ERROR HANDLING-- */
 107 
 108     if (count*datatype_size == 0)
 109     {
 110 #ifdef HAVE_STATUS_SET_BYTES
 111        MPIR_Status_set_bytes(status, datatype, 0);
 112 #endif
 113         error_code = MPI_SUCCESS;
 114         goto fn_exit;
 115     }
 116 
 117     /* --BEGIN ERROR HANDLING-- */
 118     MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code);
 119     MPIO_CHECK_WRITABLE(adio_fh, myname, error_code);
 120     MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code);
 121     /* --END ERROR HANDLING-- */
 122 
 123     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
 124     ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig);
 125 
 126     ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code);
 127 
 128     xbuf = buf;
 129     if (adio_fh->is_external32) {
 130         error_code = MPIU_external32_buffer_setup(buf, count, datatype, &e32buf);
 131         if (error_code != MPI_SUCCESS) 
 132             goto fn_exit;
 133 
 134         xbuf = e32buf;
 135     }
 136 
 137     if (buftype_is_contig && filetype_is_contig)
 138     {
 139         /* convert bufcount and offset to bytes */
 140         bufsize = datatype_size * count;
 141         if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
 142             off = adio_fh->disp + adio_fh->etype_size * offset;
 143         }
 144         else /* ADIO_INDIVIDUAL */ {
 145             off = adio_fh->fp_ind;
 146         }
 147 
 148         /* if atomic mode requested, lock (exclusive) the region, because
 149            there could be a concurrent noncontiguous request. Locking doesn't
 150            work on PIOFS and PVFS, and on NFS it is done in the
 151            ADIO_WriteContig.
 152          */
 153 
 154         if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS))
 155         {
 156             ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize);
 157         }
 158 
 159         ADIO_WriteContig(adio_fh, xbuf, count, datatype, file_ptr_type,
 160                      off, status, &error_code); 
 161 
 162         if ((adio_fh->atomicity) && ADIO_Feature(adio_fh, ADIO_LOCKS))
 163         {
 164             ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize);
 165         }
 166     }
 167     else
 168     {
 169         /* For strided and atomic mode, locking is done in ADIO_WriteStrided */
 170         ADIO_WriteStrided(adio_fh, xbuf, count, datatype, file_ptr_type,
 171                           offset, status, &error_code);
 172     }
 173 
 174 
 175     /* --BEGIN ERROR HANDLING-- */
 176     if (error_code != MPI_SUCCESS)
 177         error_code = MPIO_Err_return_file(adio_fh, error_code);
 178     /* --END ERROR HANDLING-- */
 179 
 180 fn_exit:
 181     if (e32buf!= NULL) ADIOI_Free(e32buf);
 182     ROMIO_THREAD_CS_EXIT();
 183 
 184     return error_code;
 185 }
 186 #endif

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