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

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

DEFINITIONS

This source file includes following definitions.
  1. mca_sharedfp_sm_request_position

   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-2005 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-2015 University of Houston. All rights reserved.
  13  * Copyright (c) 2015 Cisco Systems, Inc.  All rights reserved.
  14  * $COPYRIGHT$
  15  *
  16  * Additional copyrights may follow
  17  *
  18  * $HEADER$
  19  */
  20 
  21 
  22 #include "ompi_config.h"
  23 #include "sharedfp_sm.h"
  24 
  25 #include "mpi.h"
  26 #include "ompi/constants.h"
  27 #include "ompi/mca/sharedfp/sharedfp.h"
  28 #include "ompi/mca/sharedfp/base/base.h"
  29 
  30 /*use a semaphore to lock the shared memory*/
  31 #include <semaphore.h>
  32 
  33 int mca_sharedfp_sm_request_position(ompio_file_t *fh, 
  34                                      int bytes_requested,
  35                                      OMPI_MPI_OFFSET_TYPE *offset)
  36 {
  37     int ret = OMPI_SUCCESS;
  38     OMPI_MPI_OFFSET_TYPE position = 0;
  39     OMPI_MPI_OFFSET_TYPE old_offset;
  40     struct mca_sharedfp_sm_data * sm_data = NULL;
  41     struct mca_sharedfp_sm_offset * sm_offset_ptr = NULL;
  42     struct mca_sharedfp_base_data_t *sh = NULL;
  43 
  44     sh = fh->f_sharedfp_data;
  45     sm_data = sh->selected_module_data;
  46 
  47     *offset = 0;
  48     if ( mca_sharedfp_sm_verbose ) {
  49         opal_output(ompi_sharedfp_base_framework.framework_output,
  50                     "Aquiring lock, rank=%d...",fh->f_rank);
  51     }
  52 
  53     sm_offset_ptr = sm_data->sm_offset_ptr;
  54 
  55     /* Aquire an exclusive lock */
  56 
  57     sem_wait(sm_data->mutex);
  58 
  59     if ( mca_sharedfp_sm_verbose ) {
  60         opal_output(ompi_sharedfp_base_framework.framework_output,
  61                     "Succeeded! Acquired sm lock.for rank=%d\n",fh->f_rank);
  62     }
  63 
  64     old_offset=sm_offset_ptr->offset;
  65     if ( mca_sharedfp_sm_verbose ) {
  66         opal_output(ompi_sharedfp_base_framework.framework_output,
  67                     "Read last_offset=%lld!\n",old_offset);
  68     }
  69 
  70     position = old_offset + bytes_requested;
  71     if ( mca_sharedfp_sm_verbose ) {
  72         opal_output(ompi_sharedfp_base_framework.framework_output,
  73                     "old_offset=%lld, bytes_requested=%d, new offset=%lld!\n",old_offset,bytes_requested,position);
  74     }
  75     sm_offset_ptr->offset=position;
  76 
  77 
  78     if ( mca_sharedfp_sm_verbose ) {
  79         opal_output(ompi_sharedfp_base_framework.framework_output,
  80                     "Releasing sm lock...rank=%d",fh->f_rank);
  81     }
  82 
  83     sem_post(sm_data->mutex);
  84     if ( mca_sharedfp_sm_verbose ) {
  85         opal_output(ompi_sharedfp_base_framework.framework_output,
  86                     "Released lock! released lock.for rank=%d\n",fh->f_rank);
  87     }
  88 
  89     *offset = old_offset;
  90 
  91     return ret;
  92 }

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