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

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

DEFINITIONS

This source file includes following definitions.
  1. mca_sharedfp_sm_read
  2. mca_sharedfp_sm_read_ordered

   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) 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 "sharedfp_sm.h"
  25 
  26 #include "mpi.h"
  27 #include "ompi/constants.h"
  28 #include "ompi/mca/sharedfp/sharedfp.h"
  29 #include "ompi/mca/sharedfp/base/base.h"
  30 
  31 int mca_sharedfp_sm_read ( ompio_file_t *fh,
  32                            void *buf, int count, MPI_Datatype datatype, MPI_Status *status)
  33 {
  34     int ret = OMPI_SUCCESS;
  35     OMPI_MPI_OFFSET_TYPE offset = 0;
  36     long bytesRequested = 0;
  37     size_t numofBytes;
  38 
  39     if( NULL == fh->f_sharedfp_data){
  40         opal_output(ompi_sharedfp_base_framework.framework_output,
  41                     "sharedfp_sm_read - module not initialized \n");
  42         return OMPI_ERROR;
  43     }
  44 
  45     /* Calculate the number of bytes to write */
  46     opal_datatype_type_size ( &datatype->super, &numofBytes);
  47     bytesRequested = count * numofBytes;
  48 
  49     if ( mca_sharedfp_sm_verbose ) {
  50         opal_output(ompi_sharedfp_base_framework.framework_output,
  51                     "sharedfp_sm_read: Bytes Requested is %ld\n",bytesRequested);
  52     }
  53 
  54     /*Request the offset to write bytesRequested bytes*/
  55     ret = mca_sharedfp_sm_request_position(fh,bytesRequested,&offset);
  56     offset /= fh->f_etype_size;
  57 
  58     if (  -1 != ret ) {
  59         if ( mca_sharedfp_sm_verbose ) {
  60             opal_output(ompi_sharedfp_base_framework.framework_output,
  61                         "sharedfp_sm_read: Offset received is %lld\n",offset);
  62         }
  63 
  64         /* Read the file */
  65         ret = mca_common_ompio_file_read_at(fh,offset,buf,count,datatype,status);
  66     }
  67 
  68     return ret;
  69 }
  70 
  71 int mca_sharedfp_sm_read_ordered (ompio_file_t *fh,
  72                                   void *buf,
  73                                   int count,
  74                                   struct ompi_datatype_t *datatype,
  75                                   ompi_status_public_t *status)
  76 {
  77     int ret = OMPI_SUCCESS;
  78     OMPI_MPI_OFFSET_TYPE offset = 0;
  79     long sendBuff = 0;
  80     long *buff=NULL;
  81     long offsetBuff;
  82     OMPI_MPI_OFFSET_TYPE offsetReceived = 0;
  83     long bytesRequested = 0;
  84     int recvcnt = 1, sendcnt = 1;
  85     size_t numofBytes;
  86     int i;
  87 
  88     if ( NULL == fh->f_sharedfp_data){
  89         opal_output(ompi_sharedfp_base_framework.framework_output,
  90                     "sharedfp_sm_read_ordered: module not initialized \n");
  91         return OMPI_ERROR;
  92     }
  93 
  94     /* Calculate the number of bytes to read*/
  95     opal_datatype_type_size ( &datatype->super, &numofBytes);
  96     sendBuff = count * numofBytes;
  97 
  98     if ( 0  == fh->f_rank ) {
  99         buff = (long*)malloc(sizeof(long) * fh->f_size);
 100         if (  NULL == buff )
 101             return OMPI_ERR_OUT_OF_RESOURCE;
 102     }
 103 
 104     ret = fh->f_comm->c_coll->coll_gather ( &sendBuff, 
 105                                             sendcnt, 
 106                                             OMPI_OFFSET_DATATYPE,
 107                                             buff, 
 108                                             recvcnt, 
 109                                             OMPI_OFFSET_DATATYPE, 
 110                                             0,
 111                                             fh->f_comm, 
 112                                             fh->f_comm->c_coll->coll_gather_module );
 113     if( OMPI_SUCCESS != ret){
 114         goto exit;
 115     }
 116 
 117     /* All the counts are present now in the recvBuff.
 118     ** The size of recvBuff is sizeof_newComm
 119     */
 120     if (  0 == fh->f_rank ) {
 121         for (i = 0; i < fh->f_size ; i ++) {
 122             bytesRequested += buff[i];
 123             if ( mca_sharedfp_sm_verbose ) {
 124                 opal_output(ompi_sharedfp_base_framework.framework_output,
 125                             "mca_sharedfp_sm_read_ordered: Bytes requested are %ld\n",bytesRequested);
 126             }
 127         }
 128 
 129         /* Request the offset to read bytesRequested bytes
 130         ** only the root process needs to do the request,
 131         ** since the root process will then tell the other
 132         ** processes at what offset they should read their
 133         ** share of the data.
 134         */
 135         ret = mca_sharedfp_sm_request_position(fh,bytesRequested,&offsetReceived);
 136         if( OMPI_SUCCESS != ret){
 137             goto exit;
 138         }
 139         if ( mca_sharedfp_sm_verbose ) {
 140             opal_output(ompi_sharedfp_base_framework.framework_output,
 141                         "mca_sharedfp_sm_read_ordered: Offset received is %lld\n",offsetReceived);
 142         }
 143 
 144         buff[0] += offsetReceived;
 145         for (i = 1 ; i < fh->f_size; i++)  {
 146             buff[i] += buff[i-1];
 147         }
 148     }
 149 
 150     /* Scatter the results to the other processes*/
 151     ret = fh->f_comm->c_coll->coll_scatter ( buff, 
 152                                              sendcnt, 
 153                                              OMPI_OFFSET_DATATYPE,
 154                                              &offsetBuff, 
 155                                              recvcnt, 
 156                                              OMPI_OFFSET_DATATYPE, 
 157                                              0,
 158                                              fh->f_comm, 
 159                                              fh->f_comm->c_coll->coll_scatter_module );
 160     if( OMPI_SUCCESS != ret){
 161         goto exit;
 162     }
 163 
 164     /*Each process now has its own individual offset in recvBUFF*/
 165     offset = offsetBuff - sendBuff;
 166     offset /= fh->f_etype_size;
 167 
 168     if ( mca_sharedfp_sm_verbose ) {
 169         opal_output(ompi_sharedfp_base_framework.framework_output,
 170                     "mca_sharedfp_sm_read_ordered: Offset returned is %lld\n",offset);
 171     }
 172 
 173     /* read to the file */
 174     ret = mca_common_ompio_file_read_at_all(fh,offset,buf,count,datatype,status);
 175 
 176 exit:
 177     if ( NULL != buff ) {
 178         free ( buff );
 179     }
 180 
 181     return ret;
 182 }

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