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

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

DEFINITIONS

This source file includes following definitions.
  1. ADIOI_Get_position

   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 #include "adioi.h"
  11 
  12 /* returns the current position of the individual file pointer
  13    in etype units relative to the current view. */
  14 
  15 void ADIOI_Get_position(ADIO_File fd, ADIO_Offset *offset)
  16 {
  17     ADIOI_Flatlist_node *flat_file;
  18     int i, flag;
  19     MPI_Count filetype_size, etype_size;
  20     int filetype_is_contig;
  21     MPI_Aint filetype_extent, lb;
  22     ADIO_Offset disp, byte_offset, sum=0, size_in_file, n_filetypes, frd_size;
  23     
  24     ADIOI_Datatype_iscontig(fd->filetype, &filetype_is_contig);
  25     etype_size = fd->etype_size;
  26 
  27     if (filetype_is_contig) *offset = (fd->fp_ind - fd->disp)/etype_size;
  28     else {
  29 /* filetype already flattened in ADIO_Open */
  30         flat_file = ADIOI_Flatlist;
  31         while (flat_file->type != fd->filetype) flat_file = flat_file->next;
  32 
  33         MPI_Type_size_x(fd->filetype, &filetype_size);
  34         MPI_Type_get_extent(fd->filetype, &lb, &filetype_extent);
  35 
  36         disp = fd->disp;
  37         byte_offset = fd->fp_ind;
  38         n_filetypes = -1;
  39         flag = 0;
  40         while (!flag) {
  41             sum = 0;
  42             n_filetypes++;
  43             for (i=0; i<flat_file->count; i++) {
  44                 sum += flat_file->blocklens[i];
  45                 if (disp + flat_file->indices[i] + 
  46                     n_filetypes* ADIOI_AINT_CAST_TO_OFFSET filetype_extent + flat_file->blocklens[i] 
  47                     >= byte_offset) {
  48                     frd_size = disp + flat_file->indices[i] + 
  49                         n_filetypes * ADIOI_AINT_CAST_TO_OFFSET filetype_extent
  50                         + flat_file->blocklens[i] - byte_offset;
  51                     sum -= frd_size;
  52                     flag = 1;
  53                     break;
  54                 }
  55             }
  56         }
  57         size_in_file = n_filetypes * (ADIO_Offset)filetype_size + sum;
  58         *offset = size_in_file/etype_size;
  59     }
  60 }

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