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

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_Get_byte_offset

   1 /* -*- Mode: C; c-basic-offset:4 ; indent-tabs-mode:nil ; -*- */
   2 /* 
   3  *
   4  *   Copyright (C) 1997 University of Chicago. 
   5  *   See COPYRIGHT notice in top-level directory.
   6  */
   7 
   8 #include "adio.h"
   9 #include "adio_extern.h"
  10 
  11 /* Returns the absolute byte position in the file corresponding to 
  12    "offset" etypes relative to the current view. */
  13 
  14 void ADIOI_Get_byte_offset(ADIO_File fd, ADIO_Offset offset, ADIO_Offset *disp)
  15 {
  16     ADIOI_Flatlist_node *flat_file;
  17     int i;
  18     ADIO_Offset n_filetypes, etype_in_filetype, sum, abs_off_in_filetype=0, size_in_filetype;
  19     MPI_Count n_etypes_in_filetype, filetype_size, etype_size;
  20     int filetype_is_contig;
  21     MPI_Aint filetype_extent, lb;
  22 
  23     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
  24     etype_size = fd->etype_size;
  25 
  26     if (filetype_is_contig) *disp = fd->disp + etype_size * offset;
  27     else {
  28 /* filetype already flattened in ADIO_Open */
  29         flat_file = ADIOI_Flatlist;
  30         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
  31 
  32         MPI_Type_size_x(fd->filetype, &filetype_size);
  33         n_etypes_in_filetype = filetype_size/etype_size;
  34         n_filetypes = offset / n_etypes_in_filetype;
  35         etype_in_filetype = offset % n_etypes_in_filetype;
  36         size_in_filetype = etype_in_filetype * etype_size;
  37  
  38         sum = 0;
  39         for (i=0; i<flat_file->count; i++) {
  40             sum += flat_file->blocklens[i];
  41             if (sum > size_in_filetype) {
  42                 abs_off_in_filetype = flat_file->indices[i] +
  43                     size_in_filetype - (sum - flat_file->blocklens[i]);
  44                 break;
  45             }
  46         }
  47 
  48         /* abs. offset in bytes in the file */
  49         MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
  50         *disp = fd->disp + n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent + abs_off_in_filetype;
  51     }
  52 }

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