root/ompi/mca/io/romio321/romio/adio/common/ad_seek.c

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_GEN_SeekIndividual

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *   Copyright (C) 1997 University of Chicago. 
   4  *   See COPYRIGHT notice in top-level directory.
   5  */
   6 
   7 #include "adio.h"
   8 #include "adio_extern.h"
   9 
  10 #ifdef HAVE_UNISTD_H
  11 #include <unistd.h>
  12 #endif
  13 
  14 ADIO_Offset ADIOI_GEN_SeekIndividual(ADIO_File fd, ADIO_Offset offset, 
  15                                      int whence, int *error_code)
  16 {
  17 /* implemented for whence=SEEK_SET only. SEEK_CUR and SEEK_END must
  18    be converted to the equivalent with SEEK_SET before calling this 
  19    routine. */
  20 /* offset is in units of etype relative to the filetype */
  21 
  22     ADIO_Offset off;
  23     ADIOI_Flatlist_node *flat_file;
  24 
  25     int i;
  26     ADIO_Offset n_etypes_in_filetype, n_filetypes, etype_in_filetype;
  27     ADIO_Offset abs_off_in_filetype=0;
  28     ADIO_Offset size_in_filetype, sum;
  29     MPI_Count filetype_size, etype_size;
  30     int filetype_is_contig;
  31     MPI_Aint filetype_extent, lb;
  32 
  33     ADIOI_UNREFERENCED_ARG(whence);
  34 
  35     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
  36     etype_size = fd->etype_size;
  37 
  38     if (filetype_is_contig) off = fd->disp + etype_size * offset;
  39     else {
  40         flat_file = ADIOI_Flatlist;
  41         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
  42 
  43         MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
  44         MPI_Type_size_x(fd->filetype, &filetype_size);
  45         if ( ! filetype_size ) {
  46             /* Since offset relative to the filetype size, we can't
  47                do compute the offset when that result is zero.
  48                Return zero for the offset for now */
  49             *error_code = MPI_SUCCESS; 
  50             return 0;
  51         }
  52 
  53         n_etypes_in_filetype = filetype_size/etype_size;
  54         n_filetypes = offset / n_etypes_in_filetype;
  55         etype_in_filetype = offset % n_etypes_in_filetype;
  56         size_in_filetype = etype_in_filetype * etype_size;
  57  
  58         sum = 0;
  59         for (i=0; i<flat_file->count; i++) {
  60             sum += flat_file->blocklens[i];
  61             if (sum > size_in_filetype) {
  62                 abs_off_in_filetype = flat_file->indices[i] +
  63                     size_in_filetype - (sum - flat_file->blocklens[i]);
  64                 break;
  65             }
  66         }
  67 
  68         /* abs. offset in bytes in the file */
  69         off = fd->disp + n_filetypes * filetype_extent +
  70                 abs_off_in_filetype;
  71     }
  72 
  73 /*
  74  * we used to call lseek here and update both fp_ind and fp_sys_posn, but now
  75  * we don't seek and only update fp_ind (ROMIO's idea of where we are in the
  76  * file).  We leave the system file descriptor and fp_sys_posn alone. 
  77  * The fs-specifc ReadContig and WriteContig will seek to the correct place in
  78  * the file before reading/writing if the 'offset' parameter doesn't match
  79  * fp_sys_posn
  80  */
  81     fd->fp_ind = off;
  82 
  83     *error_code = MPI_SUCCESS;
  84 
  85     return off;
  86 }

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