root/ompi/mca/fbtl/posix/fbtl_posix_pwritev.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_fbtl_posix_pwritev

   1 /*
   2  * Copyright (c) 2004-2005 The Trustees of Indiana University and Indiana
   3  *                         University Research and Technology
   4  *                         Corporation.  All rights reserved.
   5  * Copyright (c) 2004-2011 The University of Tennessee and The University
   6  *                         of Tennessee Research Foundation.  All rights
   7  *                         reserved.
   8  * Copyright (c) 2004-2005 High Performance Computing Center Stuttgart,
   9  *                         University of Stuttgart.  All rights reserved.
  10  * Copyright (c) 2004-2005 The Regents of the University of California.
  11  *                         All rights reserved.
  12  * Copyright (c) 2008-2017 University of Houston. All rights reserved.
  13  * Copyright (c) 2015-2018 Research Organization for Information Science
  14  *                         and Technology (RIST). All rights reserved.
  15  * $COPYRIGHT$
  16  *
  17  * Additional copyrights may follow
  18  *
  19  * $HEADER$
  20  */
  21 
  22 
  23 #include "ompi_config.h"
  24 #include "fbtl_posix.h"
  25 
  26 #include "mpi.h"
  27 #include <unistd.h>
  28 #include <sys/uio.h>
  29 #include <limits.h>
  30 #include "ompi/constants.h"
  31 #include "ompi/mca/fbtl/fbtl.h"
  32 
  33 ssize_t  mca_fbtl_posix_pwritev(ompio_file_t *fh )
  34 {
  35     /*int *fp = NULL;*/
  36     int i, block = 1, ret;
  37     struct iovec *iov = NULL;
  38     int iov_count = 0;
  39     OMPI_MPI_OFFSET_TYPE iov_offset = 0;
  40     ssize_t ret_code=0, bytes_written=0;
  41     struct flock lock;
  42     off_t total_length, end_offset=0;
  43 
  44     if (NULL == fh->f_io_array) {
  45         return OMPI_ERROR;
  46     }
  47 
  48     iov = (struct iovec *) malloc
  49         (OMPIO_IOVEC_INITIAL_SIZE * sizeof (struct iovec));
  50     if (NULL == iov) {
  51         opal_output(1, "OUT OF MEMORY\n");
  52         return OMPI_ERR_OUT_OF_RESOURCE;
  53     }
  54 
  55     for (i=0 ; i<fh->f_num_of_io_entries ; i++) {
  56         if (0 == iov_count) {
  57             iov[iov_count].iov_base = fh->f_io_array[i].memory_address;
  58             iov[iov_count].iov_len = fh->f_io_array[i].length;
  59             iov_offset = (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset;
  60             end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
  61             iov_count ++;
  62         }
  63 
  64         if (OMPIO_IOVEC_INITIAL_SIZE*block <= iov_count) {
  65             block ++;
  66             iov = (struct iovec *)realloc
  67                 (iov, OMPIO_IOVEC_INITIAL_SIZE * block *
  68                  sizeof(struct iovec));
  69             if (NULL == iov) {
  70                 opal_output(1, "OUT OF MEMORY\n");
  71                 return OMPI_ERR_OUT_OF_RESOURCE;
  72             }
  73         }
  74 
  75         if (fh->f_num_of_io_entries != i+1) {
  76             if ( (((OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i].offset +
  77                    (ptrdiff_t)fh->f_io_array[i].length) ==
  78                   (OMPI_MPI_OFFSET_TYPE)(intptr_t)fh->f_io_array[i+1].offset) &&
  79                  (iov_count < IOV_MAX )) {
  80                 iov[iov_count].iov_base = fh->f_io_array[i+1].memory_address;
  81                 iov[iov_count].iov_len  = fh->f_io_array[i+1].length;
  82                 end_offset = (off_t)fh->f_io_array[i].offset + (off_t)fh->f_io_array[i].length;
  83                 iov_count ++;
  84                 continue;
  85             }
  86         }
  87         /*
  88           printf ("RANK: %d Entries: %d count: %d\n",
  89           fh->f_rank,
  90           fh->f_num_of_io_entries,
  91           iov_count);
  92           for (j=0 ; j<iov_count ; j++) {
  93           printf ("%p %lld\n",
  94           iov[j].iov_base,
  95           iov[j].iov_len);
  96           }
  97 
  98         */
  99 
 100         total_length = (end_offset - (off_t)iov_offset);
 101         ret = mca_fbtl_posix_lock ( &lock, fh, F_WRLCK, iov_offset, total_length, OMPIO_LOCK_SELECTIVE ); 
 102         if ( 0 < ret ) {
 103             opal_output(1, "mca_fbtl_posix_pwritev: error in mca_fbtl_posix_lock() error ret=%d %s", ret, strerror(errno));
 104             free (iov); 
 105             /* just in case some part of the lock worked */
 106             mca_fbtl_posix_unlock ( &lock, fh );
 107             return OMPI_ERROR;
 108         }
 109 #if defined (HAVE_PWRITEV) 
 110         ret_code = pwritev (fh->fd, iov, iov_count, iov_offset);
 111 #else
 112         if (-1 == lseek (fh->fd, iov_offset, SEEK_SET)) {
 113             opal_output(1, "mca_fbtl_posix_pwritev: error in lseek:%s", strerror(errno));
 114             free(iov);
 115             mca_fbtl_posix_unlock ( &lock, fh );
 116             return OMPI_ERROR;
 117         }
 118         ret_code = writev (fh->fd, iov, iov_count);
 119 #endif
 120         mca_fbtl_posix_unlock ( &lock, fh );
 121         if ( 0 < ret_code ) {
 122             bytes_written += ret_code;
 123         }
 124         else if (-1 == ret_code ) {
 125             opal_output(1, "mca_fbtl_posix_pwritev: error in writev:%s", strerror(errno));
 126             free (iov);
 127             return OMPI_ERROR;
 128         }
 129         iov_count = 0;
 130     }
 131 
 132     free (iov);
 133 
 134     return bytes_written;
 135 }

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