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

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

DEFINITIONS

This source file includes following definitions.
  1. MPI_File_iwrite
  2. MPIOI_File_iwrite

   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_iwrite = PMPI_File_iwrite
  14 #elif defined(HAVE_PRAGMA_HP_SEC_DEF)
  15 #pragma _HP_SECONDARY_DEF PMPI_File_iwrite MPI_File_iwrite
  16 #elif defined(HAVE_PRAGMA_CRI_DUP)
  17 #pragma _CRI duplicate MPI_File_iwrite as PMPI_File_iwrite
  18 /* end of weak pragmas */
  19 #elif defined(HAVE_WEAK_ATTRIBUTE)
  20 int MPI_File_iwrite(MPI_File fh, const void *buf, int count, MPI_Datatype datatype,
  21                     MPIO_Request *request) __attribute__((weak,alias("PMPI_File_iwrite")));
  22 #endif
  23 
  24 /* Include mapping from MPI->PMPI */
  25 #define MPIO_BUILD_PROFILING
  26 #include "mpioprof.h"
  27 #endif
  28 
  29 /*@
  30     MPI_File_iwrite - Nonblocking write using individual file pointer
  31 
  32 Input Parameters:
  33 . fh - file handle (handle)
  34 . buf - initial address of buffer (choice)
  35 . count - number of elements in buffer (nonnegative integer)
  36 . datatype - datatype of each buffer element (handle)
  37 
  38 Output Parameters:
  39 . request - request object (handle)
  40 
  41 .N fortran
  42 @*/
  43 #ifdef HAVE_MPI_GREQUEST
  44 #include "mpiu_greq.h"
  45 #endif
  46 
  47 int MPI_File_iwrite(MPI_File fh, ROMIO_CONST void *buf, int count,
  48                     MPI_Datatype datatype, MPI_Request *request)
  49 {
  50     int error_code=MPI_SUCCESS;
  51     static char myname[] = "MPI_FILE_IWRITE";
  52 #ifdef MPI_hpux
  53     int fl_xmpi;
  54 
  55     HPMP_IO_START(fl_xmpi, BLKMPIFILEIWRITE, TRDTSYSTEM, fh, datatype,
  56                   count);
  57 #endif /* MPI_hpux */
  58 
  59 
  60     error_code = MPIOI_File_iwrite(fh, (MPI_Offset) 0, ADIO_INDIVIDUAL,
  61                                    buf, count, datatype, myname, request);
  62 
  63     /* --BEGIN ERROR HANDLING-- */
  64     if (error_code != MPI_SUCCESS)
  65         error_code = MPIO_Err_return_file(fh, error_code);
  66     /* --END ERROR HANDLING-- */
  67 
  68 #ifdef MPI_hpux
  69     HPMP_IO_END(fl_xmpi, fh, datatype, count);
  70 #endif /* MPI_hpux */
  71 
  72     return error_code;
  73 }
  74 
  75 /* prevent multiple definitions of this routine */
  76 #ifdef MPIO_BUILD_PROFILING
  77 int MPIOI_File_iwrite(MPI_File fh,
  78                       MPI_Offset offset,
  79                       int file_ptr_type,
  80                       const void *buf,
  81                       int count,
  82                       MPI_Datatype datatype,
  83                       char *myname,
  84                       MPI_Request *request)
  85 {
  86     int error_code, buftype_is_contig, filetype_is_contig;
  87     MPI_Count datatype_size;
  88     ADIO_Status status;
  89     ADIO_Offset off, bufsize;
  90     ADIO_File adio_fh;
  91     MPI_Offset nbytes=0;
  92 
  93     ROMIO_THREAD_CS_ENTER();
  94     adio_fh = MPIO_File_resolve(fh);
  95 
  96     /* --BEGIN ERROR HANDLING-- */
  97     MPIO_CHECK_FILE_HANDLE(adio_fh, myname, error_code);
  98     MPIO_CHECK_COUNT(adio_fh, count, myname, error_code);
  99     MPIO_CHECK_DATATYPE(adio_fh, datatype, myname, error_code);
 100 
 101     if (file_ptr_type == ADIO_EXPLICIT_OFFSET && offset < 0) {
 102         error_code = MPIO_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
 103                                           myname, __LINE__, MPI_ERR_ARG,
 104                                           "**iobadoffset", 0);
 105         error_code = MPIO_Err_return_file(adio_fh, error_code);
 106         goto fn_exit;
 107     }
 108     /* --END ERROR HANDLING-- */
 109 
 110     MPI_Type_size_x(datatype, &datatype_size);
 111 
 112     /* --BEGIN ERROR HANDLING-- */
 113     MPIO_CHECK_INTEGRAL_ETYPE(adio_fh, count, datatype_size, myname, error_code);
 114     MPIO_CHECK_WRITABLE(adio_fh, myname, error_code);
 115     MPIO_CHECK_NOT_SEQUENTIAL_MODE(adio_fh, myname, error_code);
 116     MPIO_CHECK_COUNT_SIZE(adio_fh, count, datatype_size, myname, error_code);
 117     /* --END ERROR HANDLING-- */
 118 
 119     ADIOI_Datatype_iscontig(datatype, &buftype_is_contig);
 120     ADIOI_Datatype_iscontig(adio_fh->filetype, &filetype_is_contig);
 121     
 122     ADIOI_TEST_DEFERRED(adio_fh, myname, &error_code);
 123 
 124     if (buftype_is_contig && filetype_is_contig) {
 125         /* convert sizes to bytes */
 126         bufsize = datatype_size * count;
 127         if (file_ptr_type == ADIO_EXPLICIT_OFFSET) {
 128             off = adio_fh->disp + adio_fh->etype_size * offset;
 129         }
 130         else {
 131             off = adio_fh->fp_ind;
 132         }
 133 
 134         if (!(adio_fh->atomicity)) {
 135             ADIO_IwriteContig(adio_fh, buf, count, datatype, file_ptr_type,
 136                               off, request, &error_code);
 137         }
 138         else {
 139             /* to maintain strict atomicity semantics with other concurrent
 140               operations, lock (exclusive) and call blocking routine */
 141             if (ADIO_Feature(adio_fh, ADIO_LOCKS) )
 142             {
 143                 ADIOI_WRITE_LOCK(adio_fh, off, SEEK_SET, bufsize);
 144             }
 145 
 146             ADIO_WriteContig(adio_fh, buf, count, datatype, file_ptr_type, off,
 147                              &status, &error_code);  
 148 
 149             if (ADIO_Feature(adio_fh, ADIO_LOCKS) )
 150             {
 151                 ADIOI_UNLOCK(adio_fh, off, SEEK_SET, bufsize);
 152             }
 153             if (error_code == MPI_SUCCESS) {
 154                 nbytes = count * datatype_size;
 155             }
 156             
 157             MPIO_Completed_request_create(&adio_fh, nbytes, &error_code, request);
 158         }
 159     }
 160     else {
 161         ADIO_IwriteStrided(adio_fh, buf, count, datatype, file_ptr_type,
 162                            offset, request, &error_code);
 163     }
 164 fn_exit:
 165     ROMIO_THREAD_CS_EXIT();
 166     return error_code;
 167 }
 168 #endif

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