root/ompi/mca/sharedfp/sm/sharedfp_sm_seek.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_sharedfp_sm_seek

   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-2017 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) 2013-2018 University of Houston. All rights reserved.
  13  * Copyright (c) 2015      Cisco Systems, Inc.  All rights reserved.
  14  * Copyright (c) 2018      Research Organization for Information Science
  15  *                         and Technology (RIST). All rights reserved.
  16  * $COPYRIGHT$
  17  *
  18  * Additional copyrights may follow
  19  *
  20  * $HEADER$
  21  */
  22 
  23 
  24 #include "ompi_config.h"
  25 #include "sharedfp_sm.h"
  26 
  27 #include "mpi.h"
  28 #include "ompi/constants.h"
  29 #include "ompi/mca/sharedfp/sharedfp.h"
  30 #include "ompi/mca/sharedfp/base/base.h"
  31 
  32 /*use a semaphore to lock the shared memory location*/
  33 #include <semaphore.h>
  34 
  35 int
  36 mca_sharedfp_sm_seek (ompio_file_t *fh,
  37                       OMPI_MPI_OFFSET_TYPE off, int whence)
  38 {
  39     int status=0;
  40     OMPI_MPI_OFFSET_TYPE offset, end_position=0;
  41     int ret = OMPI_SUCCESS;
  42     struct mca_sharedfp_base_data_t *sh = NULL;
  43     struct mca_sharedfp_sm_data * sm_data = NULL;
  44     struct mca_sharedfp_sm_offset * sm_offset_ptr = NULL;
  45 
  46     if( NULL == fh->f_sharedfp_data ) {
  47         opal_output(ompi_sharedfp_base_framework.framework_output,
  48                     "sharedfp_sm_seek: module not initialized \n");
  49         return OMPI_ERROR;
  50     }
  51 
  52     sh = fh->f_sharedfp_data;
  53     offset = off * fh->f_etype_size;
  54 
  55     if( 0 == fh->f_rank ){
  56         if ( MPI_SEEK_SET == whence){
  57             /*no nothing*/
  58             if ( offset < 0){
  59                 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_SET, offset must be > 0, got offset=%lld.\n",offset);
  60                 ret = -1;
  61             }
  62             if ( mca_sharedfp_sm_verbose ) {
  63                 opal_output(ompi_sharedfp_base_framework.framework_output,
  64                             "sharedfp_sm_seek: MPI_SEEK_SET new_offset=%lld\n",offset);
  65             }
  66         }
  67         else if( MPI_SEEK_CUR == whence){
  68             OMPI_MPI_OFFSET_TYPE current_position;
  69             ret = mca_sharedfp_sm_get_position ( fh, &current_position);
  70             if ( mca_sharedfp_sm_verbose ) {
  71                 opal_output(ompi_sharedfp_base_framework.framework_output,
  72                             "sharedfp_sm_seek: MPI_SEEK_CUR: curr=%lld, offset=%lld, call status=%d\n",
  73                             current_position,offset,status);
  74             }
  75             offset = current_position + offset;
  76             if ( mca_sharedfp_sm_verbose ) {
  77                 opal_output(ompi_sharedfp_base_framework.framework_output,
  78                             "sharedfp_sm_seek: MPI_SEEK_CUR: new_offset=%lld\n",offset);
  79             }
  80             if(offset < 0){
  81                 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_CURE, offset must be > 0, got offset=%lld.\n",offset);
  82                 ret = -1;
  83             }
  84         }
  85         else if( MPI_SEEK_END == whence){
  86             end_position=0;
  87             mca_common_ompio_file_get_size(fh,&end_position);
  88 
  89             offset = end_position + offset;
  90             if ( mca_sharedfp_sm_verbose ) {
  91                 opal_output(ompi_sharedfp_base_framework.framework_output,
  92                             "sharedfp_sm_seek: MPI_SEEK_END: file_get_size=%lld\n",end_position);
  93             }
  94             if(offset < 0){
  95                 opal_output(0,"sharedfp_sm_seek - MPI_SEEK_CUR, offset must be > 0, got offset=%lld.\n",offset);
  96                 ret = -1;
  97             }
  98         }
  99         else {
 100             opal_output(0,"sharedfp_sm_seek - whence=%i is not supported\n",whence);
 101             ret = -1;
 102         }
 103 
 104         /*-----------------------------------------------------*/
 105         /* Set Shared file pointer                             */
 106         /*-----------------------------------------------------*/
 107         sm_data = sh->selected_module_data;
 108         sm_offset_ptr = sm_data->sm_offset_ptr;
 109 
 110         /*-------------------*/
 111         /*lock the file  */
 112         /*--------------------*/
 113         if ( mca_sharedfp_sm_verbose ) {
 114             opal_output(ompi_sharedfp_base_framework.framework_output,
 115                         "sharedfp_sm_seek: Aquiring lock, rank=%d...",fh->f_rank); fflush(stdout);
 116         }
 117 
 118         /* Aquire an exclusive lock */
 119         sm_offset_ptr = sm_data->sm_offset_ptr;
 120 
 121         sem_wait(sm_data->mutex);
 122 
 123         if ( mca_sharedfp_sm_verbose ) {
 124             opal_output(ompi_sharedfp_base_framework.framework_output,
 125                         "sharedfp_sm_seek: Success! Acquired sm lock.for rank=%d\n",fh->f_rank);
 126         }
 127         sm_offset_ptr->offset=offset;
 128         if ( mca_sharedfp_sm_verbose ) {
 129             opal_output(ompi_sharedfp_base_framework.framework_output,
 130                         "sharedfp_sm_seek: Releasing sm lock...rank=%d",fh->f_rank); fflush(stdout);
 131         }
 132         sem_post(sm_data->mutex);
 133     }
 134 
 135     /* since we are only letting process 0, update the current pointer
 136      * all of the other processes need to wait before proceeding.
 137      */
 138     fh->f_comm->c_coll->coll_barrier ( fh->f_comm, fh->f_comm->c_coll->coll_barrier_module );
 139 
 140     return ret;
 141 }

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