root/ompi/mca/io/ompio/io_ompio_file_read.c

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

DEFINITIONS

This source file includes following definitions.
  1. mca_io_ompio_file_read
  2. mca_io_ompio_file_read_at
  3. mca_io_ompio_file_iread
  4. mca_io_ompio_file_iread_at
  5. mca_io_ompio_file_read_all
  6. mca_io_ompio_file_iread_all
  7. mca_io_ompio_file_read_at_all
  8. mca_io_ompio_file_iread_at_all
  9. mca_io_ompio_file_read_shared
  10. mca_io_ompio_file_iread_shared
  11. mca_io_ompio_file_read_ordered
  12. mca_io_ompio_file_read_ordered_begin
  13. mca_io_ompio_file_read_ordered_end
  14. mca_io_ompio_file_read_all_begin
  15. mca_io_ompio_file_read_all_end
  16. mca_io_ompio_file_read_at_all_begin
  17. mca_io_ompio_file_read_at_all_end

   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-2016 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-2019 University of Houston. All rights reserved.
  13  * Copyright (c) 2017-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 #include "ompi_config.h"
  23 
  24 #include "ompi/communicator/communicator.h"
  25 #include "ompi/info/info.h"
  26 #include "ompi/file/file.h"
  27 #include "ompi/mca/fs/fs.h"
  28 #include "ompi/mca/fs/base/base.h"
  29 #include "ompi/mca/fcoll/fcoll.h"
  30 #include "ompi/mca/fcoll/base/base.h"
  31 #include "ompi/mca/fbtl/fbtl.h"
  32 #include "ompi/mca/fbtl/base/base.h"
  33 
  34 #include "io_ompio.h"
  35 #include "ompi/mca/common/ompio/common_ompio_request.h"
  36 #include "math.h"
  37 #include <unistd.h>
  38 
  39 /* Read and write routines are split into two interfaces.
  40 **   The
  41 **   mca_io_ompio_file_read/write[_at]
  42 **
  43 ** routines are the ones registered with the ompio modules.
  44 ** The
  45 **
  46 ** ompio_io_ompio_file_read/write[_at]
  47 **
  48 ** routesin are used e.g. from the shared file pointer modules.
  49 ** The main difference is, that the first one takes an ompi_file_t
  50 ** as a file pointer argument, while the second uses the ompio internal
  51 ** ompio_file_t structure.
  52 */
  53 
  54 int mca_io_ompio_file_read (ompi_file_t *fp,
  55                             void *buf,
  56                             int count,
  57                             struct ompi_datatype_t *datatype,
  58                             ompi_status_public_t *status)
  59 {
  60     int ret = OMPI_SUCCESS;
  61     mca_common_ompio_data_t *data;
  62 
  63     data = (mca_common_ompio_data_t *) fp->f_io_selected_data;
  64     OPAL_THREAD_LOCK(&fp->f_lock);
  65     ret = mca_common_ompio_file_read(&data->ompio_fh,buf,count,datatype,status);
  66     OPAL_THREAD_UNLOCK(&fp->f_lock);
  67 
  68     return ret;
  69 }
  70 
  71 int mca_io_ompio_file_read_at (ompi_file_t *fh,
  72                                OMPI_MPI_OFFSET_TYPE offset,
  73                                void *buf,
  74                                int count,
  75                                struct ompi_datatype_t *datatype,
  76                                ompi_status_public_t * status)
  77 {
  78     int ret = OMPI_SUCCESS;
  79     mca_common_ompio_data_t *data;
  80 
  81     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
  82     OPAL_THREAD_LOCK(&fh->f_lock);
  83     ret = mca_common_ompio_file_read_at(&data->ompio_fh, offset,buf,count,datatype,status);
  84     OPAL_THREAD_UNLOCK(&fh->f_lock);
  85 
  86     return ret;
  87 }
  88 
  89 int mca_io_ompio_file_iread (ompi_file_t *fh,
  90                              void *buf,
  91                              int count,
  92                              struct ompi_datatype_t *datatype,
  93                              ompi_request_t **request)
  94 {
  95     int ret = OMPI_SUCCESS;
  96     mca_common_ompio_data_t *data;
  97 
  98     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
  99     OPAL_THREAD_LOCK(&fh->f_lock);
 100     ret = mca_common_ompio_file_iread(&data->ompio_fh,buf,count,datatype,request);
 101     OPAL_THREAD_UNLOCK(&fh->f_lock);
 102 
 103     return ret;
 104 }
 105 
 106 
 107 int mca_io_ompio_file_iread_at (ompi_file_t *fh,
 108                                 OMPI_MPI_OFFSET_TYPE offset,
 109                                 void *buf,
 110                                 int count,
 111                                 struct ompi_datatype_t *datatype,
 112                                 ompi_request_t **request)
 113 {
 114     int ret = OMPI_SUCCESS;
 115     mca_common_ompio_data_t *data;
 116 
 117     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 118     OPAL_THREAD_LOCK(&fh->f_lock);
 119     ret = mca_common_ompio_file_iread_at(&data->ompio_fh,offset,buf,count,datatype,request);
 120     OPAL_THREAD_UNLOCK(&fh->f_lock);
 121 
 122     return ret;
 123 }
 124 
 125 
 126 /* Infrastructure for collective operations  */
 127 /******************************************************/
 128 int mca_io_ompio_file_read_all (ompi_file_t *fh,
 129                                 void *buf,
 130                                 int count,
 131                                 struct ompi_datatype_t *datatype,
 132                                 ompi_status_public_t * status)
 133 {
 134     int ret = OMPI_SUCCESS;
 135     mca_common_ompio_data_t *data;
 136 
 137     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 138 
 139     OPAL_THREAD_LOCK(&fh->f_lock);
 140     ret = mca_common_ompio_file_read_all (&data->ompio_fh,
 141                                           buf,
 142                                           count,
 143                                           datatype,
 144                                           status);
 145     OPAL_THREAD_UNLOCK(&fh->f_lock);
 146     if ( MPI_STATUS_IGNORE != status ) {
 147         size_t size;
 148 
 149         opal_datatype_type_size (&datatype->super, &size);
 150         status->_ucount = count * size;
 151     }
 152 
 153     return ret;
 154 }
 155 
 156 int mca_io_ompio_file_iread_all (ompi_file_t *fh,
 157                                 void *buf,
 158                                 int count,
 159                                 struct ompi_datatype_t *datatype,
 160                                 ompi_request_t **request)
 161 {
 162     int ret = OMPI_SUCCESS;
 163     mca_common_ompio_data_t *data=NULL;
 164     ompio_file_t *fp=NULL;
 165 
 166     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 167     fp = &data->ompio_fh;
 168 
 169     OPAL_THREAD_LOCK(&fh->f_lock);
 170     ret = mca_common_ompio_file_iread_all (&data->ompio_fh,
 171                                            buf,
 172                                            count,
 173                                            datatype,
 174                                            request);
 175     OPAL_THREAD_UNLOCK(&fh->f_lock);
 176 
 177     return ret;
 178 }
 179 
 180 
 181 int mca_io_ompio_file_read_at_all (ompi_file_t *fh,
 182                                    OMPI_MPI_OFFSET_TYPE offset,
 183                                    void *buf,
 184                                    int count,
 185                                    struct ompi_datatype_t *datatype,
 186                                    ompi_status_public_t * status)
 187 {
 188     int ret = OMPI_SUCCESS;
 189     mca_common_ompio_data_t *data;
 190 
 191     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 192     OPAL_THREAD_LOCK(&fh->f_lock);
 193     ret = mca_common_ompio_file_read_at_all(&data->ompio_fh,offset,buf,count,datatype,status);
 194     OPAL_THREAD_UNLOCK(&fh->f_lock);
 195 
 196     return ret;
 197 }
 198 
 199 int mca_io_ompio_file_iread_at_all (ompi_file_t *fh,
 200                                     OMPI_MPI_OFFSET_TYPE offset,
 201                                     void *buf,
 202                                     int count,
 203                                     struct ompi_datatype_t *datatype,
 204                                     ompi_request_t **request)
 205 {
 206     int ret = OMPI_SUCCESS;
 207     mca_common_ompio_data_t *data;
 208     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 209 
 210     OPAL_THREAD_LOCK(&fh->f_lock);
 211     ret = mca_common_ompio_file_iread_at_all ( &data->ompio_fh, offset, buf, count, datatype, request );
 212     OPAL_THREAD_UNLOCK(&fh->f_lock);
 213     return ret;
 214 }
 215 
 216 
 217 /* Infrastructure for shared file pointer operations
 218 ** (individual and ordered)*/
 219 /******************************************************/
 220 int mca_io_ompio_file_read_shared (ompi_file_t *fp,
 221                                    void *buf,
 222                                    int count,
 223                                    struct ompi_datatype_t *datatype,
 224                                    ompi_status_public_t * status)
 225 {
 226     int ret = OMPI_SUCCESS;
 227     mca_common_ompio_data_t *data;
 228     ompio_file_t *fh;
 229     mca_sharedfp_base_module_t * shared_fp_base_module;
 230 
 231     data = (mca_common_ompio_data_t *) fp->f_io_selected_data;
 232     fh = &data->ompio_fh;
 233 
 234     /*get the shared fp module associated with this file*/
 235     shared_fp_base_module = (mca_sharedfp_base_module_t *)(fh->f_sharedfp);
 236     if ( NULL == shared_fp_base_module ){
 237         opal_output(0, "No shared file pointer component found for the given communicator. Can not execute\n");
 238         return OMPI_ERROR;
 239     }
 240     OPAL_THREAD_LOCK(&fp->f_lock);
 241     ret = shared_fp_base_module->sharedfp_read(fh,buf,count,datatype,status);
 242     OPAL_THREAD_UNLOCK(&fp->f_lock);
 243 
 244     return ret;
 245 }
 246 
 247 int mca_io_ompio_file_iread_shared (ompi_file_t *fh,
 248                                     void *buf,
 249                                     int count,
 250                                     struct ompi_datatype_t *datatype,
 251                                     ompi_request_t **request)
 252 {
 253     int ret = OMPI_SUCCESS;
 254     mca_common_ompio_data_t *data;
 255     ompio_file_t *ompio_fh;
 256     mca_sharedfp_base_module_t * shared_fp_base_module;
 257 
 258     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 259     ompio_fh = &data->ompio_fh;
 260 
 261     /*get the shared fp module associated with this file*/
 262     shared_fp_base_module = (mca_sharedfp_base_module_t *)(ompio_fh->f_sharedfp);
 263     if ( NULL == shared_fp_base_module ){
 264         opal_output(0, "No shared file pointer component found for the given communicator. Can not execute\n");
 265         return OMPI_ERROR;
 266     }
 267     OPAL_THREAD_LOCK(&fh->f_lock);
 268     ret = shared_fp_base_module->sharedfp_iread(ompio_fh,buf,count,datatype,request);
 269     OPAL_THREAD_UNLOCK(&fh->f_lock);
 270 
 271     return ret;
 272 }
 273 
 274 int mca_io_ompio_file_read_ordered (ompi_file_t *fh,
 275                                     void *buf,
 276                                     int count,
 277                                     struct ompi_datatype_t *datatype,
 278                                     ompi_status_public_t * status)
 279 {
 280     int ret = OMPI_SUCCESS;
 281     mca_common_ompio_data_t *data;
 282     ompio_file_t *ompio_fh;
 283     mca_sharedfp_base_module_t * shared_fp_base_module;
 284 
 285     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 286     ompio_fh = &data->ompio_fh;
 287 
 288     /*get the shared fp module associated with this file*/
 289     shared_fp_base_module = (mca_sharedfp_base_module_t *)(ompio_fh->f_sharedfp);
 290     if ( NULL == shared_fp_base_module ){
 291         opal_output(0, "No shared file pointer component found for the given communicator. Can not execute\n");
 292         return OMPI_ERROR;
 293     }
 294     OPAL_THREAD_LOCK(&fh->f_lock);
 295     ret = shared_fp_base_module->sharedfp_read_ordered(ompio_fh,buf,count,datatype,status);
 296     OPAL_THREAD_UNLOCK(&fh->f_lock);
 297     return ret;
 298 }
 299 
 300 int mca_io_ompio_file_read_ordered_begin (ompi_file_t *fh,
 301                                           void *buf,
 302                                           int count,
 303                                           struct ompi_datatype_t *datatype)
 304 {
 305     int ret = OMPI_SUCCESS;
 306     mca_common_ompio_data_t *data;
 307     ompio_file_t *ompio_fh;
 308     mca_sharedfp_base_module_t * shared_fp_base_module;
 309 
 310     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 311     ompio_fh = &data->ompio_fh;
 312 
 313     /*get the shared fp module associated with this file*/
 314     shared_fp_base_module = ompio_fh->f_sharedfp;
 315     if ( NULL == shared_fp_base_module ){
 316         opal_output(0, "No shared file pointer component found for the given communicator. Can not execute\n");
 317         return OMPI_ERROR;
 318     }
 319     OPAL_THREAD_LOCK(&fh->f_lock);
 320     ret = shared_fp_base_module->sharedfp_read_ordered_begin(ompio_fh,buf,count,datatype);
 321     OPAL_THREAD_UNLOCK(&fh->f_lock);
 322 
 323     return ret;
 324 }
 325 
 326 int mca_io_ompio_file_read_ordered_end (ompi_file_t *fh,
 327                                         void *buf,
 328                                         ompi_status_public_t * status)
 329 {
 330     int ret = OMPI_SUCCESS;
 331     mca_common_ompio_data_t *data;
 332     ompio_file_t *ompio_fh;
 333     mca_sharedfp_base_module_t * shared_fp_base_module;
 334 
 335     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 336     ompio_fh = &data->ompio_fh;
 337 
 338     /*get the shared fp module associated with this file*/
 339     shared_fp_base_module = ompio_fh->f_sharedfp;
 340     if ( NULL == shared_fp_base_module ){
 341         opal_output(0, "No shared file pointer component found for the given communicator. Can not execute\n");
 342         return OMPI_ERROR;
 343     }
 344     OPAL_THREAD_LOCK(&fh->f_lock);
 345     ret = shared_fp_base_module->sharedfp_read_ordered_end(ompio_fh,buf,status);
 346     OPAL_THREAD_UNLOCK(&fh->f_lock);
 347 
 348     return ret;
 349 }
 350 
 351 
 352 /* Split collectives . Not really used but infrastructure is in place */
 353 /**********************************************************************/
 354 int mca_io_ompio_file_read_all_begin (ompi_file_t *fh,
 355                                       void *buf,
 356                                       int count,
 357                                       struct ompi_datatype_t *datatype)
 358 {
 359     int ret = OMPI_SUCCESS;
 360     ompio_file_t *fp;
 361     mca_common_ompio_data_t *data;
 362 
 363     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 364     fp = &data->ompio_fh;
 365     if ( true == fp->f_split_coll_in_use ) {
 366         printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
 367         return MPI_ERR_OTHER;
 368     }
 369     /* No need for locking fh->f_lock, that is done in file_iread_all */
 370     ret = mca_io_ompio_file_iread_all ( fh, buf, count, datatype, &fp->f_split_coll_req );
 371     fp->f_split_coll_in_use = true;
 372 
 373     return ret;
 374 }
 375 
 376 int mca_io_ompio_file_read_all_end (ompi_file_t *fh,
 377                                     void *buf,
 378                                     ompi_status_public_t * status)
 379 {
 380     int ret = OMPI_SUCCESS;
 381     ompio_file_t *fp;
 382     mca_common_ompio_data_t *data;
 383 
 384     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 385     fp = &data->ompio_fh;
 386     ret = ompi_request_wait ( &fp->f_split_coll_req, status );
 387 
 388     /* remove the flag again */
 389     fp->f_split_coll_in_use = false;
 390     return ret;
 391 }
 392 
 393 int mca_io_ompio_file_read_at_all_begin (ompi_file_t *fh,
 394                                          OMPI_MPI_OFFSET_TYPE offset,
 395                                          void *buf,
 396                                          int count,
 397                                          struct ompi_datatype_t *datatype)
 398 {
 399     int ret = OMPI_SUCCESS;
 400     mca_common_ompio_data_t *data;
 401     ompio_file_t *fp=NULL;
 402     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 403     fp = &data->ompio_fh;
 404 
 405     if ( true == fp->f_split_coll_in_use ) {
 406         printf("Only one split collective I/O operation allowed per file handle at any given point in time!\n");
 407         return MPI_ERR_REQUEST;
 408     }
 409     OPAL_THREAD_LOCK(&fh->f_lock);
 410     ret = mca_common_ompio_file_iread_at_all ( fp, offset, buf, count, datatype, &fp->f_split_coll_req );
 411     OPAL_THREAD_UNLOCK(&fh->f_lock);
 412     fp->f_split_coll_in_use = true;
 413     return ret;
 414 }
 415 
 416 int mca_io_ompio_file_read_at_all_end (ompi_file_t *fh,
 417                                        void *buf,
 418                                        ompi_status_public_t * status)
 419 {
 420     int ret = OMPI_SUCCESS;
 421     mca_common_ompio_data_t *data;
 422     ompio_file_t *fp=NULL;
 423 
 424     data = (mca_common_ompio_data_t *) fh->f_io_selected_data;
 425     fp = &data->ompio_fh;
 426     ret = ompi_request_wait ( &fp->f_split_coll_req, status );
 427 
 428     /* remove the flag again */
 429     fp->f_split_coll_in_use = false;
 430     return ret;
 431 }

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